FiTrack - Get Fit With Friends - Documentation
This page explains technical background of the app and can be used by other developers for contributing to the project. The project uses the programming language Dart and uses the Flutter cross-platform framework by Google. Best practices like seperation of concerns, splitting the application into multiple layers and using advanced state management with the BLoC pattern are used.
Table of content
- Pre-requisites
- Installation guide
- Used dependencies / dev-dependencies
- Project structure
- Architecture explanation
Pre-requisites
- working dart installation on your machine (check out the official dart installation guide)
- working flutter installation on your machine (check out the official flutter installation guide
- working git installation on your machine (check out the official git installation guide)
- working android sdk / Android Studio installation on your machine if you want to target Android (check out the official android studio installation guide)
- working xcode installation if you want to target iOS (check out this guide)
Installation Guide
- Make sure you got a functional flutter installation by running
flutter doctor
- Clone the master (or any other) branch by running
git clone https://github.com/mobileappdevhm20/team-project-team_7.git
- Install the project dependencies by running
flutter pub get
-
- Debug on your own device or a running simulator by running
flutter run
or - Build a release by running either
flutter build apk
orflutter build ios
- Debug on your own device or a running simulator by running
Dependencies
Dependencies (compilation dependencies)
These dependencies are required for application to compile. They are part of the created .apk/.ipa file.
- flutter_bloc - Used for implementing the BLoC pattern in Flutter environments
- equatable - Enables value equality instead of standard pointer equality in dart
- firebase_core - Enables the connection of multiple Firebase apps
- firebase_auth - Enables Firebase authentication in Flutter apps
- rx_dart - Adds additional capabilities to Dart Streams and StreamControllers
- background_location - Gives access to GPS sensor while the app running is in the background
- auto_route - Route Generation library
- cloud_firestore - Enables the access of Cloud Firestore, a Service to store data in a noSQL database
- share - Enables sharing content via the platform share UI
- quotes - Utility that contains more than 500 famous quotes.
Dev-Dependencies (only needed while developing)
These dependencies will not be included in the final product and just help the developers to develop faster and better.
- mockito - Mock library for testing purposes
- bloc_test - Testing library that makes it easy to test BLoCs, events and states.
- flutter_launcher_icons - Simplifies the task of updating the apps launcher icon
- flutter_launcher_name - Simplifies the task of updating the apps launcher name
- lint - Advanced dart linter for better code style
- auto_route_generator - Generator for the auto_route dependency
- build_runner - Build system for Dart code generation and modular compilation
Project structure
- pubspec.yaml - File that stores the meta-data for the project and I used for managing dependencies
- android/ and ios/ - Don’t touch these folders unless you know what you’re doing
- assets/ - Contains images, fonts and more
- test/ - Contains unit tests for widgets and other objects
- test_driver/ - Contains driver tests (integration tests)
- lib/ - Contains the actual source code
- main.dart - Entry file to the application that setups global blocs, repository and the root widget of the app
- theme.dart - Defines the ThemeData of the application
- blocs/ - Contains BLoCs and their respective event and state files. (3 files in total for each BLoC) (more on the BLoC pattern here)
- components/ - Contains reusable components that are used in multiple parts of the application
- models/ - Contains data models
- repositories/ - Contains repositories that are used to access data providers and combine them
- routes/ - Contains the routing setup for the application
- services/ - Contains custom implementations for special services
- views/ - Split into folders. Each folder contains a view. If special components are used specifically in that view, they are stored in /components subfolder
Architecture
Repository and Blocs
The app makes heavy use of Repositories and BLOCs. To access those there is a MultiRepositoryProvider and MultiBlocProvider in the main.dart. These Repositories and BLOCs can then be accessed in the whole widget tree.
MultiRepositoryProvider(
providers: [
//global repositories
RepositoryProvider(create: (context) => UserRepository()),
RepositoryProvider(
create: (context) => WorkoutRepository(),
),
],
child: MultiBlocProvider(
providers: [
//global blocs
BlocProvider<AuthenticationBloc>(create: (context) {
return AuthenticationBloc(
userRepository: RepositoryProvider.of<UserRepository>(context),
)..add(AppStarted());
}),
BlocProvider<WorkoutBloc>(
create: (context) => WorkoutBloc(),
),
BlocProvider<WorkoutDBBloc>(
create: (context) => WorkoutDBBloc(
workoutRepository:
RepositoryProvider.of<WorkoutRepository>(context))),
],
child: const FiTrackApp(),
),
Login and Signup
For User Authentication Firebase with the firebase_auth plugin is used. The communication to firebase is done with the repository lib/repositories/user_repository.dart.
The app uses BLOCs to communicate with the repository. There is a:
- authentication_bloc: Looks what the authentication state of the user is, in other words if the user is logged in or not. The app should then route to the appropiate views.
- register_bloc: Communicates directly to the user_repository to register the user. Also validates email and password during typing.
- login_bloc: Communicates directly to the user_repository to login the user. Also validates email and password during typing.
There is a seperate screen each for login and signup which communicate with the appropiate BLOCs.
Fitrack Scaffold
Most pages are created with this Scaffold (lib/components/custom_scaffold.dart). It customises the look of the appbar and includes a buttom navigation bar with a floating action button. What parts are shown can be controlled with booleans.
Homescreen
For now this screen only displays a random quote from quotes package. The idea was to show the recent events, news and milestones of you and your friends here.
Tracking
The tracking is done with background_location package. The first time the app is used the user is asked for gps-permission. The ui communicates with the location-service via the workout_bloc.dart.
Tracking Summary
When the user is finished with tracking he is redirected to a tracking summary screen. Here he has the option to save his workout. To do this the UI communicates with the workout_db_bloc.dart. The BLOC then communicates with the workout_repository.dart which uses firebases Cloud-Firestore to save the Workout online and per user.
There is also a share feature and the option to not save.
Past Workouts
This view uses a StreamBuilder to create a listview with all workouts for the current user. For simplicity the view uses the workout_repository.dart directly and not with a bloc.
Authors & Acknowledgement
This project was created in Flutter as a part of a University project. In the course, Mobile Application Development (in German ‘Mobile Anwendungen’) at Munich University of Applied Sciences.