Code Monkey home page Code Monkey logo

syntaxlexx / learning-flutter-riverpod Goto Github PK

View Code? Open in Web Editor NEW
21.0 1.0 4.0 13.58 MB

Riverpod State Mgmt for Flutter. StateProviders, StateNotifierProviders, FutureProviders, StreamProviders, autodisposed and families, and everything in-between.

Kotlin 0.07% Swift 0.77% Objective-C 0.02% Dart 74.51% CMake 9.71% C++ 11.14% C 0.74% HTML 1.99% JavaScript 0.54% CSS 0.50% Shell 0.01%
flutter riverpod state-management android flutter-architecture flutter-provider provider-state-management riverpod-authentication

learning-flutter-riverpod's Introduction

Flutter Riverpod Learning/Reference zone

A Null-Safety flutter project acting as a learning/code reference zone

Based on

  • Riverpod (v1/v2)
  • Page Transitions
  • Math Expressions
  • Flex Color Scheme

Screenshot 1 Screenshot 3 Screenshot 2

Resources

  1. App Structure by Code With Andrea
  2. Feature-first or layer-first?
  3. Riverpod Docs

Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter development, view the online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

NB: To view Google Ads, switch to the googleads branch as it does not work with the web version.

Launcher Icons

flutter pub run flutter_launcher_icons:main

Updating Splash Image

Using the flutter_native_splash package

flutter pub run flutter_native_splash:create

Architecture/Project Structure

The base sturcture is based on Code With Andrea's app structure. It offers a sweet spot between feature-first and Layer first approach, which -honestly- makes a lot more sense.

However, after building several prototypes (small quick apps), the structure feels augmented towards a Bloc-like architecture, where it begins to feel like there are too many files & folders for even the simplest of tasks.

The latest architecture features a somewhat better and more flexible architecture, offering a sweet spot between feature-first, layer-first, and Code with Andreas's architectures.

NB: Check the real folder structure contained in this project for a better visual understanding.

Changes include:

  • Renamed presentation -> ui: No need to name the presentation layer presentation. It's too lengthy and what we hate as devs is writing too much!
  • Renamed controllers -> providers. We're dealing with providers after all, aren't we?
  • Renamed services -> repositories. However, if you prefer naming yours services, well and good. The key point here is be CONSISTENT in your project. We will use repositories as it's the most popular convention.
  • StateNotifier states(classes) moved from providers files to individual models folder.
  • enums moved to data. For a Clean architecture, it would be better keeping all enums on their own and not in providers. It becomes easier to maintain the project in the long run.
  • Merged application, domain, controllers/providers -> data. Any state has been separated from the ui. Any piece of state/logic has been moved out of the presentation/ui folder.
  • Any form TextEditingController be used inside a StatefulHookConsumerWidget via useTextEditingController. Riverpod Hooks combined with Flutter Hooks are a fantastic way for handling such use-cases. Same goes for animations, pageControllers, e.t.c. found in the flutter hooks package. Form Validation can be done via the validators package, or for more complex validation, the providers can handle that (StateNotifiers) - Or however you deem fit ๐Ÿคทโ€โ™‚๏ธ
  • Inside the ui, any Screen must be suffixed with Screen e.g. OrdersScreen. Any other widget should be viewed as a partial/widget/fragment to the main screen, and, therefore, can be re-used multiple times in the entire project - not just by the feature. Screens, on the other hand, cannot be re-used in other widgets.
  • Flexibility:
    • If a feature only requires a screen and a provider, the folder structure can then be:
      • ui
      • providers
    • If a feature requires a screen, a provider, and a state/model/stateNotifier class, the folder structure can then be:
      • ui
      • data
        • providers
        • models
    • If a feature requires a screen, a provider, a state/model/stateNotifier class, and enums, the folder structure can then be:
      • ui
      • data
        • providers
        • models
        • enums
    • If a feature requires a screen, a provider, a state/model/stateNotifier class, enum, and repository, the folder structure can then be:
      • ui
      • data
        • providers
        • models
        • enums
        • repositories
        • exceptions

For apps that have an admin and user dashboard, this architecture gets in line with the following architecture:

  • main.dart
  • src
    • app_routes.dart
    • common_widgets
    • utils
    • features
      • onboarding
      • splash
      • home
      • auth
      • admin
        • dashboard
        • orders
        • invoices
        • reports
      • user
        • dashboard
        • orders
        • cart
        • invoices

and each fature can then follow the guidelines above. The ui and data can now be tested individually.

NB: Check the real folder structure contained in this project for a better visual understanding.

Links

learning-flutter-riverpod's People

Contributors

syntaxlexx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.