1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/provider_counter
Filip Hracek 7bae186046 Finish the migration from scoped_model to provider
After this change, we’re managing Counter’s lifecycle with ChangeNotifierProvider.

This removes the periodic Timer. Not only does that simplify the example and makes it closer to the original, it also prevents a leaking timer (though, in this case, it’s not an issue, since the timer is needed for the whole duration of the app). I experimented with a more robust approach (having or injecting a Timer/StreamController into the Counter, and disposing of it there) but that seemed overly complex for such a simple example. This whole problem will get significantly easier with https://github.com/rrousselGit/provider/issues/46, at which point I could reintroduce this. I will also think about a more complex Provider example, something like the venerable `bloc_complex`, with infinite-scrolling pagination and all that.
2019-05-20 16:54:25 -07:00
..

Provider Counter

The starter Flutter application, but using Provider to manage state.

This app is a direct counterpart to the simple counter application that you get when you create a new Flutter project. That one uses a StatefulWidget to manage application state. The version in this repository uses a simple app state management approach, Provider.

It shows how you might deal with state that is modified from outside the app (for example, state synchronized over network) and which needs to be accessed and changed from different parts of your app.

Getting Started

The only important part of the app is the lib/main.dart file. It has comments that will walk you through it.

For more information on the provider package (where Provider comes from), please see the package documentation.

For more information on state management in Flutter, and a list of other approaches, head over to the State management page at flutter.dev.