mirror of
https://github.com/hmalik144/days_left_flutter.git
synced 2026-03-17 23:16:12 +00:00
- Introduction on base view model and stateless widget classes
- Implementation of firebase - Implementation of dependency injection Took 11 hours 26 minutes
This commit is contained in:
49
lib/data/FirebaseAuthData.dart
Normal file
49
lib/data/FirebaseAuthData.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
// import 'package:firebase_auth/firebase_auth.dart';
|
||||
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
|
||||
class FirebaseAuthData {
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
|
||||
|
||||
User getUser() {
|
||||
return firebaseAuth.currentUser;
|
||||
}
|
||||
|
||||
String getUid() {
|
||||
return getUser()?.uid;
|
||||
}
|
||||
|
||||
Future<UserCredential> signUpWithEmailAndPassword(
|
||||
String email, String password) {
|
||||
return firebaseAuth.createUserWithEmailAndPassword(
|
||||
email: email, password: password);
|
||||
}
|
||||
|
||||
Future<UserCredential> signIn(String email, String password) {
|
||||
return firebaseAuth.signInWithEmailAndPassword(
|
||||
email: email, password: password);
|
||||
}
|
||||
|
||||
Future<void> resetPassword(String email) {
|
||||
return firebaseAuth.sendPasswordResetEmail(email: email);
|
||||
}
|
||||
|
||||
Future<void> signOut() {
|
||||
return firebaseAuth.signOut();
|
||||
}
|
||||
|
||||
Future<void> updateUsername(String newEmail) {
|
||||
return getUser().updateEmail(newEmail);
|
||||
}
|
||||
|
||||
Future<void> updatePassword(
|
||||
String email, String password, String newPassword) async {
|
||||
UserCredential credentials = await signIn(email, password);
|
||||
return credentials.user.updatePassword(newPassword);
|
||||
}
|
||||
|
||||
Future<void> updateProfile({String displayName, String photoURL}) {
|
||||
return getUser()
|
||||
.updateProfile(displayName: displayName, photoURL: photoURL);
|
||||
}
|
||||
}
|
||||
20
lib/data/ViewState.dart
Normal file
20
lib/data/ViewState.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:sealed_class/sealed_class.dart';
|
||||
|
||||
@Sealed([Idle, HasStarted, HasData, HasError])
|
||||
abstract class ViewState {}
|
||||
|
||||
class Idle implements ViewState {}
|
||||
|
||||
class HasStarted implements ViewState {}
|
||||
|
||||
class HasData implements ViewState {
|
||||
final dynamic data;
|
||||
|
||||
HasData(this.data);
|
||||
}
|
||||
|
||||
class HasError implements ViewState {
|
||||
final String error;
|
||||
|
||||
HasError(this.error);
|
||||
}
|
||||
Reference in New Issue
Block a user