Flutter Project
Out-of-the-box features/tools
- Router integration and simple page setup boilerplate
- Login/Register/Profile pages with Firebase Authentication
- Check for app updates to force update (using Firebase Remote Config)
- Logger that make logging easier and sends error logs to Firebase Crashlytics
- Firestore configuration and model/services structuring with helper methods
- FCM notifications with Firebase Messaging and Local Notifications integration that enables foreground and background notifications
- Sync FCM token with Firestore for the logged in users
Running Project
It is recommended to use fvm
to run the project. You can install fvm
by following the instructions here. If you have fvm
installed, you can run the following command,
fvm use
fvm flutter run
Configuration
Enabled Services
- Authentication https://firebase.flutter.dev/docs/auth/start
- Firestore https://firebase.flutter.dev/docs/firestore/usage
- Crashlytics https://firebase.flutter.dev/docs/crashlytics/usage
- Cloud Messaging https://firebase.flutter.dev/docs/messaging/usage
- Remote Config https://firebase.flutter.dev/docs/remote-config/overview
- Analytics https://firebase.flutter.dev/docs/analytics/overview
Project setup
- Create a firebase project. No need to add any apps yet.
- Install
flutterfire
. (Tested with version0.2.4
) - Use
flutterfire configure
to configure the project and add android/iOS apps. (Run this again if you change the application id/add new services) - Run
configure.py
script usingpython configure.py
. You may need to install python. Delete theconfigure.py
file after running the script. If something goes wrong while running the script, reset the project usinggit reset --hard
and try again. - Run
fvm flutter pub get
to install all the dependencies. - Run the app.
- Crash app using top right button and use dashboard to make sure crashlytics integration works.
- Send a self notification to make sure local notifications integration works.
- Send a test notification via the dashboard (The FCM registration token will be logged in to the console) and check if it arrives (Both when app is in foreground/background). Tapping it should show a success message.
- Set and publish
minimumAppVersion
in Remote Config to 2.0.0 (higher than current), now when you open the app, there should be a message saying that you need to update the app.
Note: To rename the intellij project properly, use intellij refactoring.
Firebase Local Setup/Use Emulators
- Run
firebase init
in firebase project directory and enable services and emulators. - You can deploy firebase project via
firebase deploy
. Usefirebase deploy --only firestore
to deploy firestore rules only. - Start emulators by
firebase emulators:start
. - In the app, set
DebugConstants.enableEmulators
totrue
. - Run the app in a android emulator in the same device as firebase emulators.
- Now app should connect to firebase emulator.
Design Choices
State Management
The project uses Riverpod to manage the state of the application. The relevant provider code is in lib/providers
directory. Additionally, Flutter Hooks are used for manage life cycle of the widgets.
Models
The json models are in lib/models
directory. These will be generated using build_runner
. The models should not have any dependencies on other packages or any associated logic.
Code generator can be run by following command,
fvm flutter pub run build_runner build --delete-conflicting-outputs
Services
The services are in lib/services
directory. Each firebase service will extend FirebaseService
class. All query/write/delete methods will be implemented in the associated service class. Each service will also accompany a abstract class (which defines the interface) and a implementation class.
Providers
The providers are in lib/providers
directory.
Routing
This project uses Auto Route to handle routing. The relevant code is in lib/router
directory. Since this routing package is using code generation, you will have to run build_runner
everytime routing code is changed.
Common Widgets
All common widgets live inside lib/widgets
directory.
Flutterfire UI is integrated. This includes several auth and firestore widgets. See Flutterfire UI Widget Catalogue for more details.
Pages
All pages live inside lib/pages
directory. Each page should be inside directories that represent their feature/use-case.
Logging
The project uses Logger to log the events. Logging can be done simply as Log.d("message")
(for debug) or Log.i("message")
(for info) or Log.w("message")
(for warning) or Log.e("message")
(for error). You may also pass an Exception
and a StackTrace
to log the error as Log.e("message", e, stackTrace)
.
Note: If the logs are crowded with unnecessary logs, apply following filter (VS Code): I/flutter
Future Work
- Local Notifications Release Config (https://pub.dev/packages/flutter_local_notifications#release-build-configuration)
- iOS Configurations