Giter VIP home page Giter VIP logo

testflutter's Introduction

provider_shopper

A Flutter sample app that shows a state management approach using the Provider package. This is the app discussed in the Simple app state management section of flutter.dev.

An animated gif of the app in action

Goals for this sample

  • Show simple use of Provider for providing an immutable value to a subtree
  • Illustrate a simple state management approach using the ChangeNotifier class
  • Show use of ProxyProvider for provided objects that depend on other provided objects

The important bits

lib/main.dart

Here the app sets up objects it needs to track state: a catalog and a shopping cart. It builds a MultiProvider to provide both objects at once to widgets further down the tree.

The CartModel instance is provided using a ChangeNotifierProxyProvider, which combines two types of functionality:

  1. It will automatically subscribe to changes in CartModel (if you only want this functionality simply use ChangeNotifierProvider).
  2. It takes the value of a previously provided object (in this case, CatalogModel, provided just above), and uses it to build the value of CartModel (if you only want this functionality, simply use ProxyProvider).

lib/models/*

This directory contains the model classes that are provided in main.dart. These classes represent the app state.

lib/screens/*

This directory contains widgets used to construct the two screens of the app: the catalog and the cart. These widgets have access to the current state of both the catalog and the cart via Provider.of.

Questions/issues

If you have a general question about Provider, the best places to go are:

If you run into an issue with the sample itself, please file an issue in the main Flutter repo.

testflutter's People

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.