@@ -18,38 +18,29 @@ Inspired by [chopper](https://pub.dev/packages/chopper).
1818#### Basic usage:
1919
2020``` dart
21- // ignore_for_file: avoid_print
2221import 'package:dio/dio.dart';
2322import 'package:tio/tio.dart';
2423
2524class User {
26- User.fromJson(Map<String, dynamic> json) : id = json['id'] as int;
25+ User.fromJson(JsonMap json) : id = json['id'] as int;
2726
2827 final int id;
2928}
3029
3130class MyError {
3231 const MyError.fromString(this.errorMessage);
3332
34- const MyError.empty() : errorMessage = 'Unknown message';
35-
36- MyError.fromJson(Map<String, dynamic> json)
37- : errorMessage = json['message'] as String;
33+ MyError.fromJson(JsonMap json) : errorMessage = json['message'] as String;
3834
3935 final String errorMessage;
4036}
4137
4238const factoryConfig = TioFactoryConfig<MyError>(
43- [
44- TioJsonFactory<User>(User.fromJson),
45- ],
46- // Factory for error transformation
47- errorGroup: TioFactoryGroup(
48- // when response body is empty (or empty string)
49- empty: TioEmptyFactory(MyError.empty),
50- string: TioStringFactory(MyError.fromString), // string
51- json: TioJsonFactory(MyError.fromJson), // or json
52- ),
39+ jsonFactories: {
40+ User.fromJson,
41+ },
42+ errorJsonFactory: MyError.fromJson,
43+ errorStringFactory: MyError.fromString,
5344);
5445
5546final dio = Dio();
@@ -77,7 +68,20 @@ void main() async {
7768 case TioFailure<User, MyError>(error: final error):
7869 print('error acquired ${error.errorMessage}');
7970 }
71+
72+ // ignore: omit_local_variable_types
73+ final User? user = await getUser(2).map(
74+ success: (success) => success.result,
75+ failure: (failure) => null,
76+ );
77+
78+ // ignore: omit_local_variable_types
79+ final User? user2 = await getUser(3).when(
80+ success: (user) => user,
81+ failure: (error) => null,
82+ );
8083}
84+
8185```
8286
8387## Guide
0 commit comments