1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_bloc/flutter_bloc.dart' ;
3
- import 'package:ht_auth_api/ht_auth_api.dart' ; // Concrete Auth Client Impl
4
- import 'package:ht_auth_repository/ht_auth_repository.dart' ; // Auth Repository
5
- import 'package:ht_data_api/ht_data_api.dart' ; // Concrete Data Client Impl
6
- import 'package:ht_data_repository/ht_data_repository.dart' ; // Data Repository
7
- import 'package:ht_http_client/ht_http_client.dart' ; // HTTP Client
8
- import 'package:ht_kv_storage_shared_preferences/ht_kv_storage_shared_preferences.dart' ; // KV Storage Impl
9
- import 'package:ht_main/app/app.dart' ; // The App widget
10
- import 'package:ht_main/bloc_observer.dart' ; // App Bloc Observer
11
- import 'package:ht_shared/ht_shared.dart' ; // Shared models, FromJson, ToJson, etc.
3
+ import 'package:ht_auth_api/ht_auth_api.dart' ;
4
+ import 'package:ht_auth_repository/ht_auth_repository.dart' ;
5
+ import 'package:ht_data_api/ht_data_api.dart' ;
6
+ import 'package:ht_data_repository/ht_data_repository.dart' ;
7
+ import 'package:ht_http_client/ht_http_client.dart' ;
8
+ import 'package:ht_kv_storage_shared_preferences/ht_kv_storage_shared_preferences.dart' ;
9
+ import 'package:ht_main/app/app.dart' ;
10
+ import 'package:ht_main/bloc_observer.dart' ;
11
+ import 'package:ht_shared/ht_shared.dart' ;
12
12
13
13
void main () async {
14
14
WidgetsFlutterBinding .ensureInitialized ();
@@ -23,23 +23,13 @@ void main() async {
23
23
late final HtAuthRepository authenticationRepository;
24
24
25
25
// 3. Define Token Provider
26
- // TODO(refactor): This is a temporary workaround. The HtAuthRepository
27
- // should be refactored to provide a public method/getter to retrieve
28
- // the current authentication token string. This function should then
29
- // call that method.
30
26
Future <String ?> tokenProvider () async {
31
- // For now, return null as we don't have a way to get the token
32
- // from the current HtAuthRepository implementation.
33
- // The HtHttpClient will make unauthenticated requests by default.
34
- // The authentication flow will handle obtaining and storing the token
35
- // via the HtAuthRepository's signIn/verify methods.
36
- // A future refactor is needed to make the token available here.
37
- return null ;
27
+ return authenticationRepository.getAuthToken ();
38
28
}
39
29
40
30
// 4. Instantiate HTTP Client
41
31
final httpClient = HtHttpClient (
42
- baseUrl: 'http://localhost:8080' , // Provided base URL for Dart Frog backend
32
+ baseUrl: 'http://localhost:8080' ,
43
33
tokenProvider: tokenProvider,
44
34
);
45
35
@@ -49,8 +39,7 @@ void main() async {
49
39
// Initialize the authenticationRepository instance
50
40
authenticationRepository = HtAuthRepository (
51
41
authClient: authClient,
52
- // storageService is not a parameter based on errors.
53
- // Token persistence must be handled within HtAuthRepository using HtKVStorageService internally.
42
+ storageService: kvStorage,
54
43
);
55
44
56
45
// 6. Instantiate Data Clients and Repositories for each model type
@@ -59,7 +48,7 @@ void main() async {
59
48
60
49
final headlinesClient = HtDataApi <Headline >(
61
50
httpClient: httpClient,
62
- modelName: 'headline' , // Assuming 'headline' is the model name for the API
51
+ modelName: 'headline' ,
63
52
fromJson: Headline .fromJson,
64
53
toJson: (headline) => headline.toJson (),
65
54
);
@@ -69,7 +58,7 @@ void main() async {
69
58
70
59
final categoriesClient = HtDataApi <Category >(
71
60
httpClient: httpClient,
72
- modelName: 'category' , // Assuming 'category' is the model name for the API
61
+ modelName: 'category' ,
73
62
fromJson: Category .fromJson,
74
63
toJson: (category) => category.toJson (),
75
64
);
@@ -79,7 +68,7 @@ void main() async {
79
68
80
69
final countriesClient = HtDataApi <Country >(
81
70
httpClient: httpClient,
82
- modelName: 'country' , // Assuming 'country' is the model name for the API
71
+ modelName: 'country' ,
83
72
fromJson: Country .fromJson,
84
73
toJson: (country) => country.toJson (),
85
74
);
@@ -89,15 +78,15 @@ void main() async {
89
78
90
79
final sourcesClient = HtDataApi <Source >(
91
80
httpClient: httpClient,
92
- modelName: 'source' , // Assuming 'source' is the model name for the API
81
+ modelName: 'source' ,
93
82
fromJson: Source .fromJson,
94
83
toJson: (source) => source.toJson (),
95
84
);
96
85
final sourcesRepository = HtDataRepository <Source >(dataClient: sourcesClient);
97
86
98
87
final userContentPreferencesClient = HtDataApi <UserContentPreferences >(
99
88
httpClient: httpClient,
100
- modelName: 'user_content_preferences' , // Assuming model name
89
+ modelName: 'user_content_preferences' ,
101
90
fromJson: UserContentPreferences .fromJson,
102
91
toJson: (prefs) => prefs.toJson (),
103
92
);
@@ -108,18 +97,17 @@ void main() async {
108
97
109
98
final userAppSettingsClient = HtDataApi <UserAppSettings >(
110
99
httpClient: httpClient,
111
- modelName: 'user_app_settings' , // Assuming model name
100
+ modelName: 'user_app_settings' ,
112
101
fromJson: UserAppSettings .fromJson,
113
102
toJson: (settings) => settings.toJson (),
114
103
);
115
104
final userAppSettingsRepository = HtDataRepository <UserAppSettings >(
116
105
dataClient: userAppSettingsClient,
117
106
);
118
107
119
- // Assuming AppConfig model exists in ht_shared and has fromJson/toJson
120
108
final appConfigClient = HtDataApi <AppConfig >(
121
109
httpClient: httpClient,
122
- modelName: 'app_config' , // Assuming model name
110
+ modelName: 'app_config' ,
123
111
fromJson: AppConfig .fromJson,
124
112
toJson: (config) => config.toJson (),
125
113
);
0 commit comments