Refactor signup page to use BLoC pattern and implement authentication repository
- Updated signup.dart to replace Provider with BLoC for state management. - Created AuthRepository to handle authentication logic and Firestore user management. - Added TripRepository and UserRepository for trip and user data management. - Implemented methods for user sign-in, sign-up, and data retrieval in repositories. - Enhanced trip management with create, update, delete, and participant management functionalities. - Updated AuthService to include new methods for sign-in and sign-up. - Removed unnecessary print statements from TripService for cleaner code. - Added dependencies for flutter_bloc and equatable in pubspec.yaml. Not tested yet
This commit is contained in:
46
lib/blocs/theme/theme_bloc.dart
Normal file
46
lib/blocs/theme/theme_bloc.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'theme_event.dart';
|
||||
import 'theme_state.dart';
|
||||
|
||||
class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
|
||||
ThemeBloc() : super(const ThemeState()) {
|
||||
on<ThemeChanged>(_onThemeChanged);
|
||||
on<ThemeLoadRequested>(_onThemeLoadRequested);
|
||||
}
|
||||
|
||||
Future<void> _onThemeChanged(
|
||||
ThemeChanged event,
|
||||
Emitter<ThemeState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(themeMode: event.themeMode));
|
||||
|
||||
// Sauvegarder la préférence
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('themeMode', event.themeMode.toString());
|
||||
}
|
||||
|
||||
Future<void> _onThemeLoadRequested(
|
||||
ThemeLoadRequested event,
|
||||
Emitter<ThemeState> emit,
|
||||
) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final themeModeString = prefs.getString('themeMode');
|
||||
|
||||
if (themeModeString != null) {
|
||||
ThemeMode themeMode;
|
||||
switch (themeModeString) {
|
||||
case 'ThemeMode.light':
|
||||
themeMode = ThemeMode.light;
|
||||
break;
|
||||
case 'ThemeMode.dark':
|
||||
themeMode = ThemeMode.dark;
|
||||
break;
|
||||
default:
|
||||
themeMode = ThemeMode.system;
|
||||
}
|
||||
emit(state.copyWith(themeMode: themeMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
20
lib/blocs/theme/theme_event.dart
Normal file
20
lib/blocs/theme/theme_event.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract class ThemeEvent extends Equatable {
|
||||
const ThemeEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ThemeChanged extends ThemeEvent {
|
||||
final ThemeMode themeMode;
|
||||
|
||||
const ThemeChanged({required this.themeMode});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [themeMode];
|
||||
}
|
||||
|
||||
class ThemeLoadRequested extends ThemeEvent {}
|
||||
21
lib/blocs/theme/theme_state.dart
Normal file
21
lib/blocs/theme/theme_state.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ThemeState extends Equatable {
|
||||
final ThemeMode themeMode;
|
||||
|
||||
const ThemeState({this.themeMode = ThemeMode.system});
|
||||
|
||||
bool get isDarkMode {
|
||||
return themeMode == ThemeMode.dark;
|
||||
}
|
||||
|
||||
ThemeState copyWith({ThemeMode? themeMode}) {
|
||||
return ThemeState(
|
||||
themeMode: themeMode ?? this.themeMode,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [themeMode];
|
||||
}
|
||||
Reference in New Issue
Block a user