Flutter implementation for ExotikArch via a simple todos CRUD application.

Overview

ExotikArch - Flutter setState on steriods

ExotikArch for Flutter. Deliver production apps fast with flutter.

ExotikArch

  • Global State Management
  • Navigation Service
  • Helper Widgets, i.e. loaders and processors.
  • Seamless Exception Handling with zero code repeats
  • Support for Isolates to offload API calls.

*Note

ExotikArch exists in form of this app project at the moment. If this project gathers enough attention then I'll make a package out of it and publish that over to pubdev.

Run it

flutter run

Modules

State Managment

ExotikArch uses the built-in setState function to cater for the global state managment. It is designed to work well with MVC pattern. We make controllers to handle the business logic. To construct a simple controller just extend it with ExoController

import 'package:exotik_todos_app/exotik_arch/exotik_arch.dart';

class TodosController extends ExoController<TodosRetainer> {

  void Function(void Function() fn)? setState;
  TodosRetainer? retainer;

  TodosController(
    this.setState,
    {
      TodosRetainer?initRetainer
    }
  ) : super(
    setState,
    initRetainer: initRetainer ?? TodosRetainer()
  );

  void dispose() async {
    super.dispose();
  }

}

The ExoController takes in a generic type which will serve as a model for controller data. For instance in case of this TodosController, this TodosRetainers reference is defined as,

class TodosRetainer {

  late List<Todo> todosList;

  TodosRetainer(){
    todosList = [];
  }

}

Its a convention to keep retainer references in the same file as the controllers. To call the controller from the UI use this syntax,

  late TodosController todosController;

  @override
  void initState() {

    todosController = TodosController(
      this.setState,
      initRetainer: anaGlobalRetainers.todosRetainer
    );

    super.initState();
  }

Note that there is a initRetainer being passed to TodosContoller constructor. That's how the global state is supported. All the global retainers are put in a AnaGlobalRetinaters reference and passed to a controller on demand. If a initRetainer is passed then controller is initialized with existing state, hence the global state effect.

Navigation Service

Navigate to anywhere from anywhere. Just use,

import 'package:exotik_todos_app/exotik_arch/exotik_arch.dart';

ExoNavService.push(
    MainPage()
);

Helper Widgets

ExotikArch ships with 2 main helper widgets. These are constructed on a very simple idea. All most 90% of apps do only 2 things. They load and display data. Or they submit data to server and wait for response. ExotikArch treats them as data loading and process handling respectively. To load the data there is a helper widget called ExoDataLoader. It takes in a reference of ExoControler. And whenever the controller is in loading state it renders a spinner automatically and then stops once data has been rendered.

We expose the logic in controllers, and UI is updated automatically.

Future<void> getTodos({
    bool reload = true
}) async {

    try {

      if(!reload){
        if(retainer!.todosList.isNotEmpty){
          return;
        }
      }

      List<Todo> _todosList;

      exoDataLoaderHelper.startLoading(); // Start Data Loader

      _todosList = await apiInterface.getTodos();

      exoDataLoaderHelper.stopLoading(); // Stop Data Loader

      if(_todosList != null){
        retainer!.todosList = _todosList;
      }

    } on ExoException catch (e, s){

      exoDataLoaderHelper.showError(e); // Handle Error Messages

      return null;

    }

    return;

}

Same goes for processes. There is ExoProcessHandler, which will display a overlay spinner and stops it once the process has been finished.

Future<bool> login(
    String email,
    String password,
    {
      bool rememberMe: true
    }
) async {

    try{

      AppUser? _appUser;

      exoProcessHandlerHelper.startLoading(); // Start Process Loader

      _appUser = await apiInterface.logIn(
        email,
        password,
      );

      exoProcessHandlerHelper.stopLoading(); // Stop Process Loader

      appUser = _appUser;

      if(appUser != null){
        if(rememberMe){
          appUser?.cache();
        }
        return true;
      } else {
        return false;
      }

    } on ExoException catch (e, s){

      exoProcessHandlerHelper.showError(e); // Handle Error Messages

      return false;

    }

}

And ExoDataLoader, ExoProcessHandler are called just like regular widgets,

@override
  Widget build(BuildContext context) {
    return ExoProcessHandler(
      exoProcessHandlerHelper: todosController.exoProcessHandlerHelper,
      child: Container(),
    );
  }

@override
  Widget build(BuildContext context) {
    return ExoProcessHandler(
      exoProcessHandlerHelper: authController.exoProcessHandlerHelper,
      child: Container()
    );
}

Exception Handling

ExotikArch has a built-in mechanism to handle all the exceptions internally. This works v.i.a contollers and helper widgets. All the exceptions are parsed to one single class ExoException which has a friendlyErrorMessage field in it. This message is automatically displayed when something goes wrong on ExoProcessHandler or ExoDataLoader widgets. Flash messages are constructed and prompted to user.

Work offload - Support for Isolates

Isolates support is very basic at the moment. We use build-in compute() function for that. Which will spawn the isolates, make a network request in it and then despawn it. The implementation for that is found is api_interface.dart file.

      ComputeRequest computeRequest = ComputeRequest(
        requestURL,
        RequestType.POST,
        body: body,
      );

      CDioResponse<Map<String, dynamic>> response = await compute<ComputeRequest, CDioResponse<Map<String, dynamic>>>(
        cRequest,
        computeRequest
      ); // Execute the network request With Isolate

      CDioResponse<Map<String, dynamic>> response = await cRequest(
        computeRequest
      ); // Execute the Network Request WithOut Isolate

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

You might also like...

Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur

Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur

❤️ Sponsor get_it This is a simple Service Locator for Dart and Flutter projects with some additional goodies highly inspired by Splat. It can be used

Jan 1, 2023

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter. Need help? Please do not submit an issue for a "

Jan 8, 2023

Integrating ChatMessaging via WebSocket (socket_io package) in Flutter Application

Chat Messaging via WebSocket Integrating ChatMessaging via WebSocket (socket_io_client package) in Flutter Application. The server is also built in Da

Jul 26, 2022

A template for flutter projects with CRUD

A template for flutter projects with CRUD

Flutter boilerplate Flutter Boilerplate Project Fork this project then start you

Nov 24, 2022

Hive CRUD App For Flutter

Hive CRUD App For Flutter

flutter_hive_crud_app A new Flutter project. Getting Started This project is a s

Oct 19, 2022

A shopper Flutter app that use BloC pattern and CRUD operations with different ways(memory/sqlite/http)

A shopper Flutter app that use BloC pattern and CRUD operations with different ways(memory/sqlite/http)

The project is maintained by a non-profit organisation, along with an amazing collections of Flutter samples. We're trying to make continuous commits

Nov 10, 2022

Flutter App - Add Firebase Crud Operation can Create Delete Update Read real time data

Flutter App - Add Firebase Crud Operation can Create Delete Update Read real time data

Firebase-Crud-Operation In This Flutter App I Will Add Firebase Crud Operation like you can Create Delete Update Read real time data. Sample Images Re

Nov 7, 2022

A Flutter Task App with Parse (Back4app) as the backend demonstrating CRUD operations.

A Flutter Task App with Parse (Back4app) as the backend demonstrating CRUD operations.

Siro's Task App Description A Flutter Task App with Parse (Back4app) as the backend demonstrating CRUD operations. Getx State Management Objective Thi

Aug 27, 2022

Rest Api Crud funtion . Created, Update, Delete , Read

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

Nov 30, 2022
Owner
"Sarvam Dukham" ~Buddha
null
QUICKNOTES is a simple Note taking app, you can easily manages your TODOs

QUICKNOTES is a simple Note taking app, you can easily manages your TODOs. It has a simple UI with Dark & Light Themes.

Abdul Basit 2 May 2, 2022
ToDo App made with flutter which stores your todos based on their categories. The data is stored in external application storage in your device in JSON file.

⭐ My ToDo ⭐ Built with ❤︎ by Akash Debnath This is my second project on Flutter. This app hepls you to keep record of your ToDos. You can create your

Akash Debnath 38 Dec 25, 2022
A Flutter application that demonstrate simple CRUD operations with Firebase cloud database.

Cricket Team A Flutter application that demonstrate simple CRUD operations with Firebase cloud database. Preview Home Empty Swipe Add Player Update Pl

Bhavik Makwana 45 Jun 19, 2021
Full Feature Todos Flutter Mobile app with fireStore integration.

IONICFIREBASEAPP DOWNLOAD TODO APP Marketplace for Mobile app and Backend that developed on leading Enterprise Technologies with as well as with your

Ionicfirebaseapp 138 Nov 4, 2022
Todos os projetos feitos no curso de Lógica de Programação com Dart em um só

Projetinho criado a partir do curso de Lógica de Porgramação com Dart da Udemy, ministrado pelo Jacob Moura (fundador do Flutterando). Feito para roda

Neeko 1 Mar 17, 2022
Implementing simple storage operations, CRUD (Create, Read, Update, Delete), using Firebase Firestore

CRUD Firebase Implementing simple storage operations, CRUD (Create, Read, Update

Luciano Martins 6 Oct 29, 2022
Memory Cache is simple, fast and global in-memory cache with CRUD features.

Memory Cache Memory Cache is simple, fast and global in-memory cache. Features Create, read, update, delete and invalidate cache. Expirable Cache Gett

Gökberk Bardakçı 6 Dec 25, 2022
In this video we will learn how to Create CRUD Rest API for our Flutter application using NODEJS API.

Flutter CRUD Using NodeJS API In this video we will learn how to Create CRUD Rest API for our Flutter application using NODEJS API. ?? Packages Used h

SnippetCoder 14 Dec 30, 2022