Skip to content

Commit

Permalink
chore: added connectivity plus for offline auths
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMuuo committed Dec 14, 2024
1 parent 9cfc5e7 commit 164dafd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
9 changes: 9 additions & 0 deletions lib/features/auth/cubit/auth_cubit.dart
Original file line number Diff line number Diff line change
@@ -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<AuthState> {
final UserRepository _userRepository = UserRepository();
Expand Down Expand Up @@ -41,6 +44,12 @@ class AuthCubit extends Cubit<AuthState> {
);
}

StreamSubscription<List<ConnectivityResult>> subscription = Connectivity()
.onConnectivityChanged
.listen((List<ConnectivityResult> result) {
// Received changes in available connectivity types!
});

/// Authenticate performs authentication mechanisms with both verisafe
/// and magnet to authenticate a user
Future<Either<String, bool>> authenticate(
Expand Down
51 changes: 26 additions & 25 deletions lib/features/auth/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ class _LoginPageState extends State<LoginPage> {
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) {
Expand Down Expand Up @@ -173,9 +173,11 @@ class _LoginPageState extends State<LoginPage> {
? 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;
}
Expand All @@ -191,9 +193,8 @@ class _LoginPageState extends State<LoginPage> {
);

result.fold((l) {
_showMessageDialog(
"Verification error",
l,
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l)),
);
}, (r) {
HapticFeedback.heavyImpact();
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 164dafd

Please sign in to comment.