Get x
void main() { runApp(GetMaterialApp( initialRoute: '/home', getPages: [ GetPage(name: '/home', page: () => HomeView(), binding: HomeBinding()), ], )); }
class Controller extends GetxController { var count = 0; void increment() { count++; update(); } }
firebase core
void main() async{ WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp().then((value){ Get.put(AuthController()); }); runApp(const MyApp()); }
Future<void> initializeDefault() async { FirebaseApp app = await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); print('Initialized default app $app'); }
Get.snackbar("Error Occurred", e.toString());
Firebase Auth
email and password verification
UserCredential credential = await FirebaseAuth.instance .createUserWithEmailAndPassword(email: email, password: password);
It creates a new user account in Firebase Authentication by using the provided email and password, and returns a UserCredential object that contains information about the newly created user.
Firebase Storage
Future<String> _uploadProPic(File image) async { Reference ref = FirebaseStorage.instance .ref() //create reference .child('profilePics') //foldername .child(FirebaseAuth.instance.currentUser!.uid); //uid for file UploadTask uploadTask = ref.putFile(image); //upload image TaskSnapshot snapshot = await uploadTask; //snapshot of current task like size or url String imageDwnUrl = await snapshot.ref.getDownloadURL(); //downloadable link return imageDwnUrl; }
_uploadProPic
that takes a File
object as input. The function uploads the file to Firebase storage by creating a reference to a specific location in storage using the FirebaseStorage.instance
method, and then calling the putFile()
method on that reference. After the upload is complete, the function retrieves the download URL of the uploaded file from the TaskSnapshot
object and returns it as a String
.User Model
//App(User/obj) convert to Firebase(Map/JSON format) Map<String , dynamic> toJson() => { "name" : name, "profilePic" : profilePhoto, "email" : email, "uid" : uid }; //Firebase(Map/JSON format) convert to App(User) static myUser fromSnap( DocumentSnapshot snap){ var snapshot = snap.data() as Map<String , dynamic>; return myUser( email: snapshot['email'], profilePhoto: snapshot["profilePic"], uid: snapshot["uid"], name: snapshot["name"] ); }
the concept of a "snapshot" in this context refers to representing the data of a specific document in the firestore database at a certain point in time.
User State Persistence
//User State Persistence late Rx<User?> _user; User get user => _user.value!; // _user - Nadi // _user.bindStream - Nadi Me Color Deko //ever - Aap Ho @override void onReady() { //TODO: implement onReady super.onReady(); _user = Rx<User?>(FirebaseAuth.instance.currentUser); _user.bindStream(FirebaseAuth.instance.authStateChanges()); ever(_user, _setInitialView); //always listener //Rx - Observable Keyword - Continously Checking Variable Is Changing Or Not. } _setInitialView(User? user){ if(user == null){ Get.offAll(()=> LoginScreen()); }else{ Get.offAll(() => HomeScreen()); } }
Bottom Nav Bar and state change
using stateful widget and set state with different page index on Tap
Build Context
Flutter lifecycle ( initstate, Despose() )
Navigator - route
Navigator.push
Splash Screen
Timer, Navigator.pushreplacement
Provider state change
if we don’t want to refresh full page just to change a little thing in page
Generated Routes
you can just make Switch-case routes by giving simple names to pages
Page View Builder
Dynamic scrolling