Skip to content

Commit

Permalink
fix connectivity status check
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityDarkLab committed Feb 7, 2024
1 parent 517995c commit 0d39c1c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
12 changes: 0 additions & 12 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
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 @@ -42,17 +41,6 @@ class App extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final connectivityStatus = ref.watch(connectivityProvider);
connectivityStatus.whenData((result) {
if(result == ConnectivityResult.none) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (ModalRoute.of(context)?.settings.name != '/downloads') {
Navigator.of(context).pushNamed('/downloads');
return;
}
});
}
});

final userState = ref.watch(userViewModelProvider);

Expand Down
37 changes: 33 additions & 4 deletions lib/views/on_boarding_view/welcome_screen_view.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/providers.dart';
import 'package:gocast_mobile/utils/constants.dart';
import 'package:gocast_mobile/views/login_view/internal_login_view.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:logger/logger.dart';

/// Welcome screen view.
/// This is the first screen that the user sees when the app is opened.
Expand All @@ -16,11 +18,38 @@ class WelcomeScreen extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
// Getting screen size for responsive layout
final connectivityStatus = ref.watch(connectivityProvider);
Logger().i(connectivityStatus.toString());
return connectivityStatus.when(
data: (result) {
// If there's no connectivity, navigate or replace the current view.
if (result == ConnectivityResult.none) {
WidgetsBinding.instance.addPostFrameCallback((_) {

if (ModalRoute.of(context)?.settings.name != '/downloads') {
Navigator.of(context).pushReplacementNamed('/downloads');
}
});
}
return _buildMainLayout(context, ref);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stackTrace) {
return Center(
child: Text(
AppLocalizations.of(context)!.error_occurred,
style: const TextStyle(color: Colors.red),
),
);
},
);
}


Widget _buildMainLayout(BuildContext context, WidgetRef ref) {
final screenSize = MediaQuery.of(context).size;
final bool isPortrait =
MediaQuery.of(context).orientation == Orientation.portrait;

return Scaffold(
body: SafeArea(
child: Padding(
Expand Down Expand Up @@ -145,7 +174,7 @@ class WelcomeScreen extends ConsumerWidget {
),
)
: Text(AppLocalizations.of(context)!.tum_login,
style: const TextStyle(fontSize: 18)),
style: const TextStyle(fontSize: 18),),
onPressed: () => handleSSOLogin(context, ref),
);
}
Expand All @@ -162,7 +191,7 @@ class WelcomeScreen extends ConsumerWidget {
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
),
child: Text(AppLocalizations.of(context)!.continue_without,
style: const TextStyle(fontSize: 18)),
style: const TextStyle(fontSize: 18),),
onPressed: () {
Navigator.pushNamed(context, '/publiccourses');
},
Expand Down

0 comments on commit 0d39c1c

Please sign in to comment.