@@ -23,15 +23,18 @@ final backendClientProvider = AsyncNotifierProvider<BackendClient, Map<String, S
2323/// Allows to communicate with the backend.
2424class BackendClient extends AsyncNotifier <Map <String , String >> {
2525 /// The default timeout in seconds.
26- static const int _kDefaultTimeout = 10 ;
26+ static const Duration _kDefaultTimeout = Duration (seconds: 10 );
27+
28+ /// The app client ID storage key.
29+ static const String _kAppClientIdKey = 'appClientId' ;
2730
2831 /// The HTTP client instance.
2932 final http.Client _client = http.Client ();
3033
3134 @override
3235 FutureOr <Map <String , String >> build () async {
3336 PackageInfo packageInfo = await PackageInfo .fromPlatform ();
34- String ? appClientId = await SimpleSecureStorage .read ('appClientId' );
37+ String ? appClientId = await SimpleSecureStorage .read (_kAppClientIdKey );
3538 ref.onDispose (_client.close);
3639 return {
3740 'App-Version' : packageInfo.version,
@@ -46,7 +49,7 @@ class BackendClient extends AsyncNotifier<Map<String, String>> {
4649 if (! headers.containsKey ('App-Client-Id' )) {
4750 String appClientId = currentPlatform.generateAppClientId ();
4851 headers['App-Client-Id' ] = appClientId;
49- await SimpleSecureStorage .write ('appClientId' , appClientId);
52+ await SimpleSecureStorage .write (_kAppClientIdKey , appClientId);
5053 if (ref.mounted) {
5154 state = AsyncData (headers);
5255 }
@@ -60,6 +63,7 @@ class BackendClient extends AsyncNotifier<Map<String, String>> {
6063 String ? backendUrl,
6164 Session ? session,
6265 bool autoRefreshAccessToken = true ,
66+ Duration timeout = _kDefaultTimeout,
6367 }) async {
6468 try {
6569 bool isConnected = await ref.read (connectivityStateProvider.future);
@@ -89,7 +93,7 @@ class BackendClient extends AsyncNotifier<Map<String, String>> {
8993 ).build (),
9094 headers: headers,
9195 )
92- .timeout (const Duration (seconds : _kDefaultTimeout) );
96+ .timeout (timeout );
9397 return ResultSuccess (
9498 value: request.toResponse (response),
9599 );
0 commit comments