-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from B3-3iL-DLW/ui/create-login-page
UI/create login page
- Loading branch information
Showing
14 changed files
with
345 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,6 @@ on: | |
push: | ||
branches: | ||
- dev | ||
pull_request: | ||
branches: | ||
- dev | ||
|
||
env: | ||
FLUTTER_VERSION: 3.10.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
part 'login_state.dart'; | ||
|
||
class LoginCubit extends Cubit<LoginState> { | ||
LoginCubit() : super(LoginInitial()) { | ||
checkUserAuthentication(); | ||
} | ||
|
||
Future<bool> areFieldsFilled( | ||
String ine, String name, String birthDate) async { | ||
if (ine.isEmpty || name.isEmpty || birthDate.isEmpty) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
Future<void> saveLoginDetails( | ||
String ine, String name, String birthDate) async { | ||
if (!(await areFieldsFilled(ine, name, birthDate))) { | ||
emit(LoginFieldError()); | ||
return; | ||
} | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
await prefs.setString('ine', ine); | ||
await prefs.setString('name', name); | ||
await prefs.setString('birthDate', birthDate); | ||
emit(RedirectToClassSelection()); | ||
} | ||
|
||
Future<void> checkUserAuthentication() async { | ||
SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
String? ine = prefs.getString('ine'); | ||
String? name = prefs.getString('name'); | ||
String? birthDate = prefs.getString('birthDate'); | ||
String? className = prefs.getString('className'); | ||
|
||
if (ine != null && name != null && birthDate != null && className != null) { | ||
emit(LoginAuthenticated()); | ||
} else { | ||
emit(LoginInitial()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
part of 'login_cubit.dart'; | ||
|
||
@immutable | ||
abstract class LoginState {} | ||
|
||
class LoginInitial extends LoginState {} | ||
|
||
class LoginAuthenticated extends LoginState {} | ||
|
||
class LoginFieldError extends LoginState {} | ||
|
||
class RedirectToClassSelection extends LoginState {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,78 @@ | ||
import 'package:app_student/api/api_service.dart'; | ||
import 'package:app_student/api/class_groups/repositories/class_group_repository.dart'; | ||
import 'package:app_student/config/config.dart'; | ||
import 'package:app_student/login/cubit/login_cubit.dart'; | ||
import 'package:app_student/login/widgets/form/form_login.dart'; | ||
import 'package:app_student/login/widgets/header/header_text.dart'; | ||
import 'package:app_student/week_schedule/views/week_schedule.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
import '../../class_groups/cubit/class_group_cubit.dart'; | ||
import '../../class_groups/views/class_group_view.dart'; | ||
import '../widgets/header/header_logo.dart'; | ||
|
||
class LoginPage extends StatelessWidget { | ||
const LoginPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const Scaffold( | ||
body: Column( | ||
children: [ | ||
HeaderLogo(), | ||
HeaderText('Bonjour :)'), | ||
Expanded(child: FormLogin()), | ||
], | ||
), | ||
return BlocBuilder<LoginCubit, LoginState>( | ||
builder: (context, state) { | ||
if (state is RedirectToClassSelection) { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
final config = Provider.of<Config>(context, listen: false); | ||
Navigator.of(context).pushReplacement( | ||
MaterialPageRoute<ClassListPage>( | ||
builder: (context) => BlocProvider( | ||
create: (_) => ClassGroupCubit( | ||
classRepository: ClassGroupRepository( | ||
apiService: ApiService(apiUrl: config.apiUrl))), | ||
child: const ClassListPage()), | ||
), | ||
); | ||
}); | ||
return Container(); | ||
} else if (state is LoginInitial) { | ||
return const Scaffold( | ||
body: Column( | ||
children: [ | ||
HeaderLogo(), | ||
HeaderText('Bonjour :)'), | ||
Expanded(child: FormLogin()), | ||
], | ||
), | ||
); | ||
} else if (state is LoginAuthenticated) { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
Navigator.of(context).pushReplacement( | ||
MaterialPageRoute(builder: (context) => const WeekSchedulePage()), | ||
); | ||
}); | ||
return Container(); | ||
} else if (state is LoginFieldError) { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Veuillez remplir tous les champs'), | ||
backgroundColor: Colors.red, | ||
), | ||
); | ||
}); | ||
return const Scaffold( | ||
body: Column( | ||
children: [ | ||
HeaderLogo(), | ||
HeaderText('Bonjour :)'), | ||
Expanded(child: FormLogin()), | ||
], | ||
), | ||
); | ||
} else { | ||
return Container(); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.