@@ -27,6 +27,38 @@ void main() async {
2727 _setupLoggers ();
2828 await SystemChrome .setPreferredOrientations ([DeviceOrientation .portraitUp]);
2929
30+ // Create http client
31+ late final Func0 <Future <void >> onUnauthorized;
32+ final simpleHttpClient = createSimpleHttpClient (() => onUnauthorized ());
33+
34+ // construct RemoteDataSource
35+ final RemoteDataSource remoteDataSource = ApiService (simpleHttpClient);
36+
37+ // construct LocalDataSource
38+ final rxPrefs = RxSharedPreferences .getInstance ();
39+ final crypto = MethodChannelCryptoImpl ();
40+ final LocalDataSource localDataSource = SharedPrefUtil (rxPrefs, crypto);
41+ onUnauthorized = () => localDataSource.removeUserAndToken ().first;
42+
43+ // construct UserRepository
44+ final UserRepository userRepository = UserRepositoryImpl (
45+ remoteDataSource,
46+ localDataSource,
47+ );
48+
49+ runApp (
50+ Provider <UserRepository >.value (
51+ userRepository,
52+ child: const MyApp (),
53+ ),
54+ );
55+ }
56+
57+ SimpleHttpClient createSimpleHttpClient (
58+ Func0 <Future <void >> onUnauthorized,
59+ ) {
60+ final authInterceptor = AuthInterceptor (onUnauthorized: onUnauthorized);
61+
3062 final loggingInterceptor = SimpleLoggingInterceptor (
3163 SimpleLogger (
3264 loggerFunction: print,
@@ -38,10 +70,6 @@ void main() async {
3870 ),
3971 );
4072
41- late final Func0 <Future <void >> onUnauthorized;
42- final authInterceptor =
43- AuthInterceptor (onUnauthorized: () => onUnauthorized ());
44-
4573 final simpleHttpClient = SimpleHttpClient (
4674 client: Platform .isIOS || Platform .isMacOS
4775 ? CupertinoClient .defaultSessionConfiguration ()
@@ -59,27 +87,7 @@ void main() async {
5987 ],
6088 );
6189
62- // construct RemoteDataSource
63- final RemoteDataSource remoteDataSource = ApiService (simpleHttpClient);
64-
65- // construct LocalDataSource
66- final rxPrefs = RxSharedPreferences .getInstance ();
67- final crypto = MethodChannelCryptoImpl ();
68- final LocalDataSource localDataSource = SharedPrefUtil (rxPrefs, crypto);
69- onUnauthorized = () => localDataSource.removeUserAndToken ().first;
70-
71- // construct UserRepository
72- final UserRepository userRepository = UserRepositoryImpl (
73- remoteDataSource,
74- localDataSource,
75- );
76-
77- runApp (
78- Provider <UserRepository >.value (
79- userRepository,
80- child: const MyApp (),
81- ),
82- );
90+ return simpleHttpClient;
8391}
8492
8593void _setupLoggers () {
0 commit comments