Skip to content

Commit

Permalink
fix: sign "no internet connection (looks & functionality) (#1805)
Browse files Browse the repository at this point in the history
/claim #1798
closes #1798
  • Loading branch information
beastoin authored Feb 24, 2025
2 parents f47ceeb + 8e5e888 commit 3843670
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
30 changes: 20 additions & 10 deletions app/lib/pages/home/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,25 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
builder: (ctx, connectivityProvider, child) {
bool isConnected = connectivityProvider.isConnected;
previousConnection ??= true;
if (previousConnection != isConnected) {
if (previousConnection != isConnected && connectivityProvider.isInitialized) {
previousConnection = isConnected;
if (!isConnected) {
Future.delayed(Duration.zero, () {
if (mounted) {
Future.delayed(const Duration(seconds: 2), () {
if (mounted && !connectivityProvider.isConnected) {
ScaffoldMessenger.of(ctx).showMaterialBanner(
MaterialBanner(
content: const Text('No internet connection. Please check your connection.'),
backgroundColor: Colors.red,
content: const Text(
'No internet connection. Please check your connection.',
style: TextStyle(color: Colors.white70),
),
backgroundColor: const Color(0xFF424242), // Dark gray instead of red
leading: const Icon(Icons.wifi_off, color: Colors.white70),
actions: [
TextButton(
onPressed: () {
ScaffoldMessenger.of(ctx).hideCurrentMaterialBanner();
},
child: const Text('Dismiss'),
child: const Text('Dismiss', style: TextStyle(color: Colors.white70)),
),
],
),
Expand All @@ -301,20 +305,26 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver, Ticker
ScaffoldMessenger.of(ctx).hideCurrentMaterialBanner();
ScaffoldMessenger.of(ctx).showMaterialBanner(
MaterialBanner(
content: const Text('Internet connection is restored.'),
backgroundColor: Colors.green,
content: const Text(
'Internet connection is restored.',
style: TextStyle(color: Colors.white),
),
backgroundColor: const Color(0xFF2E7D32), // Dark green instead of bright green
leading: const Icon(Icons.wifi, color: Colors.white),
actions: [
TextButton(
onPressed: () {
if (mounted) {
ScaffoldMessenger.of(ctx).hideCurrentMaterialBanner();
}
},
child: const Text('Dismiss'),
child: const Text('Dismiss', style: TextStyle(color: Colors.white)),
),
],
onVisible: () => Future.delayed(const Duration(seconds: 3), () {
ScaffoldMessenger.of(ctx).hideCurrentMaterialBanner();
if (mounted) {
ScaffoldMessenger.of(ctx).hideCurrentMaterialBanner();
}
}),
),
);
Expand Down
12 changes: 9 additions & 3 deletions app/lib/providers/connectivity_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import 'package:internet_connection_checker_plus/internet_connection_checker_plu
class ConnectivityProvider extends ChangeNotifier {
bool _isConnected = true;
bool _previousConnection = true;
bool _isInitialized = false;
final InternetConnection _internetConnection = InternetConnection();

bool get isConnected => _isConnected;

bool get previousConnection => _previousConnection;
bool get isInitialized => _isInitialized;

ConnectivityProvider() {
init();
Expand All @@ -19,9 +20,14 @@ class ConnectivityProvider extends ChangeNotifier {
bool result = await _internetConnection.hasInternetAccess;
_isConnected = result;
_previousConnection = result;
_isInitialized = true;
notifyListeners();

_internetConnection.onStatusChange.listen((InternetStatus result) {
_previousConnection = _isConnected;
isInternetConnected(result);
if (_isInitialized) { // Only handle status changes after initialization
_previousConnection = _isConnected;
isInternetConnected(result);
}
});
}

Expand Down

0 comments on commit 3843670

Please sign in to comment.