From 164dafd245473761ba1dfc4a6c085db649eabcfb Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 13 Dec 2024 15:20:00 +0300 Subject: [PATCH] chore: added connectivity plus for offline auths --- lib/features/auth/cubit/auth_cubit.dart | 9 +++++ lib/features/auth/views/login_page.dart | 51 +++++++++++++------------ pubspec.yaml | 1 + 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/lib/features/auth/cubit/auth_cubit.dart b/lib/features/auth/cubit/auth_cubit.dart index 6d4657c..feaf058 100644 --- a/lib/features/auth/cubit/auth_cubit.dart +++ b/lib/features/auth/cubit/auth_cubit.dart @@ -1,9 +1,12 @@ +import 'dart:async'; + import 'package:academia/database/database.dart'; import 'package:academia/features/auth/repository/user_repository.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:academia/features/auth/cubit/auth_states.dart'; +import 'package:connectivity_plus/connectivity_plus.dart'; class AuthCubit extends Cubit { final UserRepository _userRepository = UserRepository(); @@ -41,6 +44,12 @@ class AuthCubit extends Cubit { ); } + StreamSubscription> subscription = Connectivity() + .onConnectivityChanged + .listen((List result) { + // Received changes in available connectivity types! + }); + /// Authenticate performs authentication mechanisms with both verisafe /// and magnet to authenticate a user Future> authenticate( diff --git a/lib/features/auth/views/login_page.dart b/lib/features/auth/views/login_page.dart index cf91def..517fc50 100644 --- a/lib/features/auth/views/login_page.dart +++ b/lib/features/auth/views/login_page.dart @@ -35,25 +35,25 @@ class _LoginPageState extends State { bool validateForm() { return _formState.currentState!.validate(); } - - /// Shows a dialog with [title] and [content] - void _showMessageDialog(String title, String content) { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: Text(title), - content: Text(content), - actions: [ - TextButton( - onPressed: () { - context.pop(); - }, - child: const Text("Ok"), - ), - ], - ), - ); - } + // + // /// Shows a dialog with [title] and [content] + // void _showMessageDialog(String title, String content) { + // showDialog( + // context: context, + // builder: (context) => AlertDialog( + // title: Text(title), + // content: Text(content), + // actions: [ + // TextButton( + // onPressed: () { + // context.pop(); + // }, + // child: const Text("Ok"), + // ), + // ], + // ), + // ); + // } @override Widget build(BuildContext context) { @@ -173,9 +173,11 @@ class _LoginPageState extends State { ? null : () async { if (!validateForm()) { - _showMessageDialog( - "Validation error", - "Please ensure that the form was well filled", + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text( + "Please ensure that the form was well filled"), + ), ); return; } @@ -191,9 +193,8 @@ class _LoginPageState extends State { ); result.fold((l) { - _showMessageDialog( - "Verification error", - l, + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(l)), ); }, (r) { HapticFeedback.heavyImpact(); diff --git a/pubspec.yaml b/pubspec.yaml index 0581c04..606a5ba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -63,6 +63,7 @@ dependencies: skeletonizer: ^1.4.2 get_it: ^8.0.2 pretty_dio_logger: ^1.4.0 + connectivity_plus: ^6.1.1 dev_dependencies: flutter_test: