The repo contains the codebase of Magic's Flutter test.

Overview

Magic

Coverage style: very good analysis

A flutter app to track and record user workouts.

Running the App

To run the app, you should fetch all dependencies and run the build_runner

flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs

App Architecture and Folder Structure

The code of the app implements clean architecture to separate the UI, domain and data layers with a feature-first approach for folder structure, implementing the MVVM architectural pattern.

Folder Structure

lib
├── core
│   ├── app
│   ├── data
│   ├── models
│   ├── services
│   │   ├── service_api
│   │   └── stream_service
│   └── utils
├── features
│   ├── add_workout
│   │   ├── view_model --- add_workout_vm
│   │   ├── widgets   
│   │   └── view
│   ├── home
│   │   ├── view_model --- home_view_model
│   │   ├── widgets
│   │   └── view
│   └── splash_view
│       ├── view_model --- splash_view_model
│       └── views
|
└── main.dart
  • main.dart has the root MaterialApp and all necessary configurations and route settings to start the app

  • The core folder contains code shared across features

    • app contains the code generator for Stacked app, implementations and services.
    • data abstract app-level database and workout store to store database
    • storage service is implemented with Sqflite)
    • models for create dart classes/models
    • services folders for implementing:
      • service_api which acts as a layer between the viewmodel and data layer
      • stream service contains class for stream service
    • utils for colors and size management with Flutter screen utils
  • The features folder: contains the core features of the app like:

    • add workout
    • home
    • splash screen

Testing

The test folder mirrors the lib folder in addition to some test utilities. And more tests will be added.

mocktail is used to mock dependencies.

Testing with Stacked

Testing with Stacked is hassle-free and simple. You can test your business logic separately from Flutter, and you can test how they behave in your widgets with widget testing. You can find helpful information about this in the official docs.

1. Unit Testing

Covered all functions necessary for this app. One would have to get mock and used mocked dependencies of services before carrying out tests.

    late MockNavigationService mockNavService;
    late MockServiceApi mockServiceApi;
    late MockStreamSubscription mockStreamService;
    late HomeViewModel sut; ///sut means system under tests
    
    setUp(() {
        mockStreamService = MockStreamSubscription();
        sut = HomeViewModel(mockStreamService);
    });

and then test like:

    test("initials values are correct", () {
       expect(sut.workoutList, []);
    });

or group and test with:

  group("fetchWorkouts", () {
  
    test("fetch workouts using service api", () async {
        serviceApiReturns3Workouts();
        await sut.fetchWorkout();
        verify(() => mockServiceApi.getWorkouts()).called(1);
    
    });
    
    test("sets workoutList to the ones from the service", () async {
        serviceApiReturns3Workouts();
        await sut.fetchWorkout();
        expect(sut.workoutList, workoutsFromService);
    
    });
  
  });

Third party packages

  • Stacked and its services: Used to implement a very clean MVVM architectural pattern, state management and navigation service very cleaner.
  • Google fonts: Used for implementing custom font.
  • Sqflite: Used to create and implementing database.
  • Flutter screen utils: For adapting to different screen and font sizes to look good on different mobile screens.
  • Mocktail: Used to create mocks.

PS: Much thought wasn't given to UI and design.

You might also like...

This repo is a boilerplate to create flutter application easily. It is based on **GetX**.

This repo is a boilerplate to create flutter application easily. It is based on **GetX**.

flutter-app boilerplate This repo is a boilerplate to create flutter application easily. It is based on GetX. More info about GetX here. The app has b

Dec 3, 2022

continue to my flutter journey here's the comeback repo , lets see what i will end up making

flutter_application_1 A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

May 19, 2021

This repo is for anything that can be reusable in flutter like custom widgets 🟥, animations 🌟and more

Ease This packa is for anything that can be reusable in flutter like custom widgets 🟥 , animations 🌟 and more. Features 1-custom text widget to ease

Dec 3, 2022

A Flutter repo with a ready-to-go architecture containing flavors, bloc, device settings, json serialization and connectivity

A Flutter repo with a ready-to-go architecture containing flavors, bloc, device settings, json serialization and connectivity

Flutter Ready to Go A Flutter repo with a ready-to-go architecture containing flavors, bloc, device settings, json serialization and connectivity. Why

Nov 11, 2022

This is a repo for Flutter ItemStack ListView Tutorial

Flutter Item Stack ListView Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is

Dec 19, 2022

Repo for MultiLevel Drawer Flutter Package

Repo for MultiLevel Drawer Flutter Package

MultiLevel Drawer An easy to implement Multi Level Drawer for Flutter Applications. Just use this in place of regular Scaffold Drawer and you are read

Nov 9, 2022

This repo provides a starter kit thats include Getx package.

This repo provides a starter kit thats include Getx package.

Getx_Starter This repo provides a starter kit thats include Getx package. It includes key-value databases, sample pages, and components which they are

Apr 27, 2022

Repo for Teach Yourself mastering dart programming language

mastering-dart Repo for Teach Yourself mastering dart programming language Chapter Membuat Aplikasi Pertama Menggunakan Dart Percabangan Perulangan Fu

Nov 10, 2022

This is my participation Repo for the 100 days of coding challenge

hundred_days_of_coding Day 1: Started creating Project and using advanced tools to make the development easier Day 2: Added DataClasses with the help

Nov 21, 2021
Owner
Ikenna Umeh
Flutter Everyday. Rust on weekends.
Ikenna Umeh
Deepak Sharma 149 Dec 10, 2022
This repo contains a collection of permission related Flutter plugins which can be used to request permissions to access device resources in a cross-platform way.

Flutter Permission Plugins Deprecation Notice This repository has been replaced by the Flutter permission_handler plugin and will not longer be mainta

Baseflow 51 Dec 13, 2021
The repo contains the source code for all the tutorials on the FilledStacks Youtube channel.

Flutter tutorials The repo contains the source code for all the written tutorials by Filledstacks. All Tutorials plus additional snippets and shorter

Dane Mackier 4.5k Dec 31, 2022
A repo for me to test and collate popular algorithms.

Common Algorithms written in Dart This repo is a result of practicing the algorithms presented on www.geeksforgeeks.org, as well as some coding challe

Gerard R 1 May 28, 2022
An E-Commerce application developed on Flutter, which helps to run the app on Android / IOS / Windows's OS / MacOS / Web Browser from a single codebase

BuySmart An E-Commerce application developed on Flutter, which helps to run the app on Android / IOS / Windows's OS / MacOS / Web Browser from a singl

Sumit Kumar 11 Oct 10, 2022
This is a wallet application written in Flutter & Dart. Codebase could be shared effectively on other OS Platforms

Gwallet A Simple wallet application written in Flutter and Dart for Android and iOs. Getting Started For Android, Specifically. You can run iOS, by st

Gerald Maduabuchi 8 Dec 12, 2022
Flutter bloc cubit test knowdge - Flutter bloc cubit test knowdge

Flutter Bloc Simple Api This project is using weather api for featch data and di

Waruna Kaushalya 0 Jan 3, 2022
Integration test - Copy of the official Flutter integration test plugin

integration_test This package enables self-driving testing of Flutter code on de

null 0 Jan 5, 2022
Integration Test Preview allows tests on multiple screen sizes in a single e2e test run.

Integration Test Preview has pre-configured methods that allow for faster test deployment for end to end (e2e) test coverage (using Android and iOS pl

The Mobile Applications Community 3 Aug 23, 2022