我知道还有其他方法可以实现此目的,但我想通过initState()使用Future来使用SharedPreferences获取列表。下面说明了我想要实现的目标,但它没有按要求工作,因为Future在完成任务之前立即返回。这应该如何构建?import'package:flutter/material.dart';import'package:shared_preferences/shared_preferences.dart';class_MyHomePageStateextendsState{SharedPreferences_prefs;String_sMessage="Noresp
我知道Future将在事件队列中运行。但是事件队列也在主隔离上运行,如果我将来做一些繁重的任务(例如,计算从1到1000000的总和),它会阻塞我的ui代码。但是Future在网络操作中不会阻塞ui(比如awaithttpClient.getUrl(uri))。为什么使用future的网络请求需要几秒钟而不阻塞UI,而计算操作会阻塞UI?@overridevoidinitState(){super.initState();Future((){varresult;for(vari=0;i如果我在initState()中使用Future执行一些繁重的任务,ui将被阻塞。
我知道Future将在事件队列中运行。但是事件队列也在主隔离上运行,如果我将来做一些繁重的任务(例如,计算从1到1000000的总和),它会阻塞我的ui代码。但是Future在网络操作中不会阻塞ui(比如awaithttpClient.getUrl(uri))。为什么使用future的网络请求需要几秒钟而不阻塞UI,而计算操作会阻塞UI?@overridevoidinitState(){super.initState();Future((){varresult;for(vari=0;i如果我在initState()中使用Future执行一些繁重的任务,ui将被阻塞。
我需要从firestore数据库中获取所有数据。我是这样走的,https://stackoverflow.com/a/55865045/9139407FuturegetPhotography(){Futuredata=awaitdb.collection('photography').document('0yUc5QBGHNNq6WK9CyyF').setData(jsonDecode(jsonEncode(Photography([AllImages(["list"])],"image_url","Shanika","image_url","lovelycouple","Bhanuk
我需要从firestore数据库中获取所有数据。我是这样走的,https://stackoverflow.com/a/55865045/9139407FuturegetPhotography(){Futuredata=awaitdb.collection('photography').document('0yUc5QBGHNNq6WK9CyyF').setData(jsonDecode(jsonEncode(Photography([AllImages(["list"])],"image_url","Shanika","image_url","lovelycouple","Bhanuk
我遇到了一个奇怪的问题,如果我在我的flutter应用程序中从我的提供者那里yield*,函数中的其余代码就不会完成。我使用的是BLoC模式,所以我的_mapEventToState函数如下所示:Stream_mapJoiningCongregationToState(intidentifier,intpassword)async*{_subscription?.cancel();_subscription=(_provider.doThings(id:identifier,password:password)).listen((progress)=>{dispatch(Event(p
我遇到了一个奇怪的问题,如果我在我的flutter应用程序中从我的提供者那里yield*,函数中的其余代码就不会完成。我使用的是BLoC模式,所以我的_mapEventToState函数如下所示:Stream_mapJoiningCongregationToState(intidentifier,intpassword)async*{_subscription?.cancel();_subscription=(_provider.doThings(id:identifier,password:password)).listen((progress)=>{dispatch(Event(p
我有一个sqlite数据库,我从中读取数据。我还有一棵很长的小部件树。因此,经过一些研究,我找到了providerFlutter包。但是我不知道如何在扩展ChangeNotifier的类中使用Futures或者如何在我的小部件树中的任何地方使用它?classMyProviderwithChangeNotifier{dynamic_myValue;dynamicgetmyValue=>_myValue;setmyValue(dynamicnewValue){_myValue=newValue;notifyListeners();}MyProvider(){loadValue();}Fut
我有一个sqlite数据库,我从中读取数据。我还有一棵很长的小部件树。因此,经过一些研究,我找到了providerFlutter包。但是我不知道如何在扩展ChangeNotifier的类中使用Futures或者如何在我的小部件树中的任何地方使用它?classMyProviderwithChangeNotifier{dynamic_myValue;dynamicgetmyValue=>_myValue;setmyValue(dynamicnewValue){_myValue=newValue;notifyListeners();}MyProvider(){loadValue();}Fut
我想从数据库中获取所有项目,但我不知道如何将Future字符串列表转换为字符串列表。varx=DataBaseHelper.instance.queryAllRows();Future>queryAllRows()async{Databasedb=awaitinstance._initDatabase();List>s=awaitdb.query(table,columns:[columnname]);Listlist=newList();for(varxins){x.forEach((k,v)=>list.add(v));}returnlist;}我想获取数据库中的所有值,但不知道如