Flutter Firebase Complete App | Study App

This is a flutter firebase complete app using firebase, firebase firestore, firebase storage, google sign in, with two themes from scratch. This app covers both android and ios part.

Topics(advanced) covered

1. Firebase app creation with CLI

2. Firebase upload data programmatically

3. Work with firebase collections, documents and fields

4. Firebase storage for uploading image

5. Read data from firebase

6. Firebase data upload batch operation

7. Firebase google sign in

8. Google auth before accessing data

9. Upload user data to firebase

10. Upload app study score data to firebase

11. Store data per user in firebase

 

This is a dynamic app and it contains 12 UI screen.

Complete code for early access 

Firebase Master Class App

Assets for following video tutorial

assets

Facebook group for discussing this app issue

facebook group

AppLogger Class

This class helps you log information which is helpful for debugging. You need a plugig to do it.

logger: ^1.0.0
class AppLogger {
  static final logger = Logger(
    printer: PrettyPrinter(
        methodCount: 2, // number of method calls to be displayed
        errorMethodCount: 8, // number of method calls if stacktrace is provided
        lineLength: 200, // width of the output
        colors: true, // Colorful log messages
        printEmojis: true, // Print an emoji for each log message
        printTime: false // Should each log print contain a timestamp
    ),
  );

  static void i(dynamic message){
    logger.i(message);
  }
  static void d(dynamic message){
    logger.d(message);
  }
  static void w(dynamic message){
    logger.w(message);
  }
  static void e(dynamic message){
    logger.e(message);
  }
  static void wtf(dynamic message){
    logger.wtf(message);
  }

}

Errors and Solutions

1. Firebase database rules

You may set up some rules to work with Firebase Collections

rules_version = '2'; service cloud.firestore {
match /databases/{database}/documents { 
    match /questionPapers/{ppr}/questions/{q}{ 
      allow read, write: if request.auth != null 
      }
      
	match /leaderboard/{document=**} { 
  	allow read, write: if true;
	}
    match /questionPapers/{document=**} { 
      allow read, write: if true;
    }
    match /users/{document=**} { 
      allow read, write: if true;
    }
} 
}

The above rules should help you create collections and work on them.

 

2. Controller Injection Error or FirebaseStorageService not Found

You may see the below error 

FirebaseStorageService" not found. You need to call "Get.put(FirebaseStorageService())" or "Get.lazyPut(()=>FirebaseStorageService())"

That happened because we missed to inject the controller. To get rid of the problem do this, just below line in initial_bindings.dart

Get.put(FirebaseStorageService());

Now it should look like this

class InitialBinding implements Bindings {
  @override
  void dependencies() {
    Get.put(ThemeController());
    //Get.put(PapersDataUploader());
    Get.put(AuthController(), permanent: true);
    Get.put(NotificationService());
    Get.lazyPut(() =>  FireBaseStorageService());
  }
}

3. Navigation to home screen

Make sure you have the home route in your app_routes.dart

class AppRoutes {
  static List<GetPage> routes() => [
        GetPage(name: "/", page: () => const SplashScreen()),
        GetPage(
          name: "/introduction",
          page: () => const AppIntroductionScreen(),
        ),
        GetPage(
            name: "/home",
            page: () => const HomeScreen(),
            binding: BindingsBuilder(() {
              Get.put(QuestionPaperController());
            })),
      ];
}

And from introduction.dart file add the code inside the Column widget

AppCircleButton(
                      onTap: () => Get.offAndToNamed("/home"),
                      child: const Icon(Icons.arrow_forward, size: 35))

4. Bad state: field does not exist within the DocumentSnapshotPlatform

Now this error happens because, we have wrong key and value pair for our database. Remember we get the data from firebase and convert them in object. 

The problem is in the question_paper_model.dart, we have a typo for "Description", it should be "description", and "question_count" should be "questions_count"

5. App Crashes Google Signin

When you click on the google sign in button, the app crashes. We need to add SHA1 key in firebase console.

Use the below command

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

 

Recent posts