Fasilkom COVID-19 Project
A health care equipment marketplace to help COVID-19 situation.
Getting Started
- Install Flutter by following instructions in Flutter.dev documentation
- Add flutter to your $PATH if you have not done so
- Switch channel to
beta
to allow compiling to Web by running
flutter channel beta && flutter upgrade`
- Run this command to enable compiling to Web
flutter config --enable-web
- Run this application in Chrome by running
flutter run -d chrome
Note: if you're using Chromium, you may need to set
CHROME_EXECUTABLE
to point to your Chromium executable.
- Enjoy the benefit of Flutter development! You can do hot reload by pressing r (small r) in the terminal and hot restart by pressing R (capital r), but if you
Using Text Editor or IDE
For Flutter development, you can both use VSCode or IntelliJ Idea. You can also select the devices that you want to target using VSCode or IntelliJ Idea. In VSCode, you can select the devices in the bottom right of the Editor. In IntelliJ, there will be Dropdown menu beside the start button.
Setting up different Firebase App
For using different Firebase App than the one that is used in this project do:
- Android: Change
android/app/google-services.json
with your owngoogle-services.json
file - Web: Change
firebaseConfig
variables inweb/index.html
with your own config from your Firebase console - iOS: TODO
Style Guide
This codebase will use Effective Dart style guide as it's primary source of truth for linting. To achieve strictness of code quality, we use pedantic, the package that is used in Google for ensuring code quality and consistency.
If someday in the future we disagree with the convention, please edit analysis_options.yaml
Generate JSON Model (Serializer/Deserializer) Class using pub runner
Serializing and deserializing is easy in Flutter because of package dart:convert
, but using that package requires us to create boilerplate code that tells what JSON key will map to what attribute. Hence, this is not a scalable solution for building a large app.
To make a new JSON model, we can just import json_annotations
and declare the class with @JsonSerializable()
(see example in models/
directory), but we need code generator to run in our terminal generate the code for us so that we don't have to. To do this, please run:
flutter pub run build_runner build
Script above works for building the code one time, so everytime we make a changes to the models class, we have to run the script again. To avoid doing that, we can run it in watch mode by using:
flutter pub run build_runner watch
And voila! Flutter will generate the model code for us.
For more info about JSON serialization head over to this documentation.
Architecture/State Management Guide
This Flutter app uses a library called provider for managing it's state. Why Provider? Because it is very simple and relatively easier to learn compared to state management patterns like Redux, MobX, etc. The idea of Provider is actually very simple: Lift the state of a Widget up to the Provider, and make it accessible to all Widget that are descendants of the Provider widget. According to the author, provider is a mixture between dependency injection and state management, built with widgets for widgets. If you think that Provider is not clean enough to manage the state, you can combine it by using BLoC Pattern, this pattern is recommended by the Google Flutter team on the Google I/O event. For more tutorial about Provider pattern, please check out this link.