-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes an issue with listening to the connection
- Loading branch information
Showing
4 changed files
with
42 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
lib/views/main_view/main_view_widgets/connectivity_listener.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import '../../../l10n/app_localizations.dart'; | ||
import '../../../utils/logger.dart'; | ||
import '../../../utils/riverpod_providers.dart'; | ||
|
||
class ConnectivityListener extends ConsumerWidget { | ||
final Widget child; | ||
const ConnectivityListener({required this.child, super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final connectivity = ref.watch(connectivityProvider).asData?.value; | ||
if (connectivity != null && connectivity == ConnectivityResult.none) { | ||
ref.read(tokenProvider.notifier).isLoading.then((value) { | ||
final tokenState = ref.read(tokenProvider); | ||
if (tokenState.hasPushTokens) { | ||
Logger.info("Connectivity changed: $connectivity"); | ||
ref.read(statusMessageProvider.notifier).state = (AppLocalizations.of(context)!.noNetworkConnection, null); | ||
} | ||
}); | ||
} | ||
return child; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters