Giter Site home page Giter Site logo

devdaisy-lab / bloc_fruits Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 6.28 MB

A state management approach using flutter bloc package

Kotlin 2.11% Swift 2.06% Objective-C 0.19% Dart 95.64%
flutter flutter-apps flutter-examples flutter-package bloc state-management state equatable eshop-cart eshopping

bloc_fruits's Introduction

bloc_fruits

A flutter app sample, Bloc Fruits, shows a state management approach using Flutter bloc and Equatable (overrides == and hashCode) packages. The app has two separate screens: a list of fruits and a cart. The list of fruits represented by the MyList widget and the cart represented by the MyCart widget. The list of fruits screen includes a scrolling view of many fruit items (MyFruitItem) with add button (AddButton). The cart screen includes list of added fruits (CartList) and total price of added fruits (CartTotal).

This is a widget tree of the Bloc Fruits app:

A Flutter app structure:

lib/main.dart

In order to track states of the object, they need to be provided to widget further down the tree. Here the MultiBlocProvider is used in order to provide both blocs (in this case, ListBloc and CartBloc) at once to widgets further down the tree.

The ListBloc and CartBloc instances are provided by using BlocProvider. The BlocProvider creates a new two blocs: ListBloc and CartBloc with added states: LoadList and LoadCart and mades them available to widgets further down the tree.

lib/bloc/*

This directory contains the blocs: ListBloc and CartBloc, events: ListEvent and CartEvent and states: ListState and ListState. The blocs, events, and states, respresent the app state.

lib/model/*

This directory contains the model classes: ListModel, CartModel and an object Fruit skeleton.

lib/screens/*

This directory contains widgets MyList and MyCart. They represents two different screens: a list of fruit items and a cart.

A widget MyList containes list of MyListFruit, builded by BlockBuilder<ListBloc, ListState> on state ListLoaded, every fruit item is listed by it's position index (state.myList.getByPosition(index)).

lib/widgets/*

This directory contains widgets (MyFruitItem, AddButton, CartList, and CartTotal) used to construct the two screens of the app: a list of fruits and a cart.

A widget MyFruitItem represent the item of fruit with AddButton.

A widget AddButton has access to the CartBloc and CartState via BlocBuilder The BlocBuilder handles widgets building in response to new state. In this case on the button press instead the button the check icon appears and CartState updates.

The widgets CartList has access to the CartBloc and CartState via BlocBuilder. The BlocBuilder rebuilds Cart screen after CartState updates on the press button.

The widgets CartTotal has access to the CartBloc and CartState via BlocBuilder. The BlocBuilder rebuilds total price after CartState updates on the press button.

lib/style/*

This directory contains of the app Text Style: fontFamily, fontWeight, fontSize and text color.

IOS Platform

Android Platform

bloc_fruits's People

Contributors

devdaisy-lab avatar

Stargazers

 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.