Skip to content

Commit

Permalink
Add redirect to download when no internet
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityDarkLab committed Feb 2, 2024
1 parent 28801c0 commit 496f095
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/models/user/user_state_model.dart';
Expand Down Expand Up @@ -43,6 +44,8 @@ class App extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
_checkConnectivityAndRedirect(context, ref);

final userState = ref.watch(userViewModelProvider);

bool isLoggedIn = ref.watch(userViewModelProvider).user != null;
Expand All @@ -61,10 +64,10 @@ class App extends ConsumerWidget {
],
supportedLocales: L10n.all,
locale: Locale(UserPreferences.getLanguage()),
theme: appTheme, // Your light theme
darkTheme: darkAppTheme, // Define your dark theme
theme: appTheme,
darkTheme: darkAppTheme,
themeMode:
ref.watch(themeModeProvider), // Use the theme mode from the provider
ref.watch(themeModeProvider),
navigatorKey: navigatorKey,
scaffoldMessengerKey: scaffoldMessengerKey,
home: !isLoggedIn
Expand All @@ -74,6 +77,16 @@ class App extends ConsumerWidget {
);
}

void _checkConnectivityAndRedirect(BuildContext context, WidgetRef ref) {
Connectivity().checkConnectivity().then((connectivityResult) {
if (connectivityResult == ConnectivityResult.none) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pushReplacementNamed('/downloads');
});
}
});
}

void _handleErrors(WidgetRef ref, UserState userState) {
// Check for errors in userState and show a SnackBar if there are any
if (userState.error != null) {
Expand Down

0 comments on commit 496f095

Please sign in to comment.