flutter-provider

Use case for FutureProvider

☆樱花仙子☆ 提交于 2020-06-13 00:30:51
问题 I was wondering what use case exists for the FutureProvider class? I am particularly interested how to load an asynchronous function like Future<Contact> getAllContacts() async { ... } when the ui is built with a FutureProvider , ChangeNotifierProvider or anything similar. Moreover, each time when notifyListeners() is called, I would like to have that provider to rebuild the ui with asynchronous call. Is that any way possible with provider or am I missing something? 回答1: FutureProvider doesn

How does listeners in Provider work in Flutter?

一笑奈何 提交于 2020-06-01 05:08:36
问题 I am using Provider package to work with data from different locations. For this question, I have created a sample project which consists of a Welcome Screen which shows a Login button, upon click, it redirects to Login Screen where one would have login text field but for now, I have placed a button which on click calls the login function and that login function notifies the listeners. I also have a logout function and boolean value which keeps track of the logged in status. These functions

How to use Futures inside ChangeNotifier?

淺唱寂寞╮ 提交于 2020-05-31 05:46:48
问题 I have an sqlite database from which I read data. I also have a long widget tree. So after a bit of research I found the provider Flutter package. But I can't figure out how to use Futures inside the class extending ChangeNotifier or How to use it anywhere in my widget tree? class MyProvider with ChangeNotifier { dynamic _myValue; dynamic get myValue => _myValue; set myValue(dynamic newValue) { _myValue = newValue; notifyListeners(); } MyProvider(){ loadValue(); } Future<void> loadValue async

How to use Futures inside ChangeNotifier?

旧时模样 提交于 2020-05-31 05:45:46
问题 I have an sqlite database from which I read data. I also have a long widget tree. So after a bit of research I found the provider Flutter package. But I can't figure out how to use Futures inside the class extending ChangeNotifier or How to use it anywhere in my widget tree? class MyProvider with ChangeNotifier { dynamic _myValue; dynamic get myValue => _myValue; set myValue(dynamic newValue) { _myValue = newValue; notifyListeners(); } MyProvider(){ loadValue(); } Future<void> loadValue async

Provider vs. InheritedWidget

落爺英雄遲暮 提交于 2020-05-28 03:40:21
问题 Am I wrong or if we just want to pass a value down the Widget tree, Provider is just an InheritedWidget with a dispose method? 回答1: Yes. Provider is indeed mostly features based on Inheritedwidgets. If you want to make your own, then that's fine. But you'll quickly realize that, without provider, you'll have hundreds of useless repetitive lines. Provider basically takes the logic of InheritedWidgets, but reduce the boilerplate to the strict minimum. 回答2: Provider is not a must, but should.

Provider vs. InheritedWidget

被刻印的时光 ゝ 提交于 2020-05-28 03:38:27
问题 Am I wrong or if we just want to pass a value down the Widget tree, Provider is just an InheritedWidget with a dispose method? 回答1: Yes. Provider is indeed mostly features based on Inheritedwidgets. If you want to make your own, then that's fine. But you'll quickly realize that, without provider, you'll have hundreds of useless repetitive lines. Provider basically takes the logic of InheritedWidgets, but reduce the boilerplate to the strict minimum. 回答2: Provider is not a must, but should.

How to use flutter provider in a statefulWidget?

一个人想着一个人 提交于 2020-05-13 11:51:12
问题 I am using flutter_provider for state management. I want to load some items on page(statefulwidget) load from Api. I am showing a loader on page start and want to show the items once they are fetched. PlayList.dart - class Playlist extends StatefulWidget { @override _PlaylistState createState() => _PlaylistState(); } class _PlaylistState extends State<Playlist> { var videosState; @override void initState() { super.initState(); videosState = Provider.of<VideosProvider>(context); videosState

Is FutureProvider broken or something?

ⅰ亾dé卋堺 提交于 2020-04-18 05:50:48
问题 I try this simple FutureProvider code yet it gave me an error: Error: Could not find the correct Provider<String> above this Consumer<String> Widge I have make sure that FutureProvider wraps my MaterialApp and get the provider using Consumer widget. Here's my code: import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return FutureProvider( create: (

List view throws an error before stream has finished retrieving data

北城余情 提交于 2020-04-18 05:36:54
问题 I've been learning Flutter and following an online tutorial regarding Provider package, at present I'm working with StreamProvider . I have a service which connects to Firestore and returns all documents within a collection ('reports'), these documents are then mapped to my report object. Service: class FirestoreService { Firestore _db = Firestore.instance; var random = Random(); Stream<List<Report>> getReports() { return _db.collection('reports') .orderBy('timeStamp', descending: true)

List view throws an error before stream has finished retrieving data

白昼怎懂夜的黑 提交于 2020-04-18 05:36:41
问题 I've been learning Flutter and following an online tutorial regarding Provider package, at present I'm working with StreamProvider . I have a service which connects to Firestore and returns all documents within a collection ('reports'), these documents are then mapped to my report object. Service: class FirestoreService { Firestore _db = Firestore.instance; var random = Random(); Stream<List<Report>> getReports() { return _db.collection('reports') .orderBy('timeStamp', descending: true)