草庐IT

future-proof

全部标签

sqlite - 如何访问 initstate 中的 future 值?

如何获取状态的initState中的future值?我正在尝试创建一个登录屏幕,检查session是否存在于sqflite中并相应地返回。我有一个DBhelper类,用于检查数据库并在Future中返回session。我如何比较这个?我还有一个聊天屏幕,我需要监听websocket并将用户名发送到initstate上的服务器。此用户名也在数据库中,并作为Future值返回。P.S我不想在登录页面上显示正在加载。如果session在数据库中,我想直接进入主界面。 最佳答案 将代码从initState()移到另一个你可以async的方法

dart - flutter 错误 :The argument type 'Future<Image>' can't be assigned to the parameter type 'Widget'

我在使用flutterflame库时遇到了这个错误Theargumenttype'Future'can'tbeassignedtotheparametertype'Widget'.我的代码是:import'package:flutter/material.dart';import'package:flame/flame.dart';classTileMapextendsStatefulWidget{@override_TileMapStatecreateState()=>_TileMapState();}class_TileMapStateextendsState{@overrideW

flutter - 如何将 Future<StreamedResponse> 转换为 Future<Response>?

我正在尝试发送带有正文的DELETE请求,但http.delete不支持向请求添加正文。我在网上找到了这个解决方案,但我想返回Response而不是StreamedResponse。我怎样才能做到这一点?staticFuturedeleteFavorites({Mapbody})async{UserRepositoryuserRepository=UserRepository();Stringtoken=awaituserRepository.storage.read(key:'token');finalclient=http.Client();varresponse;try{resp

asynchronous - Dart 中的 future 队列

我想实现一个聊天系统。我卡在了用户发送多个消息非常快的地步。尽管所有消息都到达服务器,但顺序不限。所以我想到实现一个队列,其中每条消息都应该最先入队等待轮到自己轮到发帖请求等待服务器响应大约5秒如果响应在时间范围内到达并且状态为OK,则消息发送否则消息发送失败。在第5点的任何情况下,消息都应出队,并有机会下一条消息。现在,主要问题是,每个聊天头或我们正在与之交谈的用户可能有多个队列。我将如何实现?我对Dart和Dart真的很陌生。请帮忙。谢谢! 最佳答案 听起来您正在描述一个Stream-一系列有序的异步事件。https://www

dart - 错误 : The argument type '(File) → Future<dynamic>' can't be assigned to the parameter type '(dynamic) → FutureOr<dynamic>'

我正在尝试编译示例:https://github.com/dart-lang/googleapis_examples/blob/master/drive_upload_download_console/bin/main.dart我得到以下Dart编译错误error:Theargumenttype'(File)→Future'can'tbeassignedtotheparametertype'(dynamic)→FutureOr'.(argument_type_not_assignableatlib/google_api_rest/main.dart:49)来自以下代码://Downlo

dart - Flutter - 将 future 列表传递给 SearchDelegate

我一直在关注-boringfluttershow上的Flutter搜索教程.我一直在尝试使用从future列表派生的列表来实现相同的功能,其中数据来自api(在本例中为Aqueduct服务器)。目前我的屏幕列出了API中的所有联系人,我现在想针对该联系人列表进行搜索。我假设最好的做法是将相同的列表(已经显示)传递给搜索委托(delegate)。不幸的是,我不确定如何实现这一目标。我的代码如下(请注意我已经为这个例子精简了一些代码):class_ContactsScreenStateextendsState{staticconst_usersUrl=//urlinfo;staticfin

dart - 如何将 Future<dynamic> 转换/转换为图像?

我有像这样获取图像的功能dynamicimgBinary=_repository.fetchImage(productId);我想将其添加到图像列表中ListlistImages=newList();很喜欢dynamicimgBinary=_repository.fetchImage(productId);listImages.add(imgBinary);这个怎么投? 最佳答案 好的,所以你可以尝试.then方法。因为_repository.fetchImage(productId);是future。所以你可以试试-Listlis

dart - future build 者( future :) is recursing my http requests,

我需要在页面呈现之前从三个不同的url获取数据。所以,这是我的ScopedModel中的方法,包括多个http.post方法:FuturefetchData()async{_isLoading=true;notifyListeners();awaitfetchAvailable();awaitfetchOnProgress();awaitfetchCompleted();_isLoading=false;notifyListeners();fetchData区域中的方法只是带有原始Future类型的经典http.post请求。这是我的FutureBuilder:FutureBuilde

asynchronous - 获取方法 Future<T> 的结果 flutter

我有一个方法FuturegetCurrentUser()async{FirebaseUseruser=await_firebaseAuth.currentUser();returnuser;}我希望能够通过以下方式在其他模块中调用它:if(class.getCurrentUser()!=null){//Dosomething}我似乎无法弄清楚如何获取实际值,而不是存储该值的Future对象。例如,在C++中,我可以执行future.get(),这将阻止并将值返回给我。有flutter的等价物吗?我是这门语言的新手,已经搜索了几个小时,但似乎找不到解决这个确切问题的方法。

firebase - flutter future :A build function returned null

我想从firebase检索数据到futurebuilder。我为此使用了这个函数。FuturegetAllData()async{ReseviorDataModelresModel;DatabaseReferenceref=FirebaseDatabase.instance.reference();DataSnapshotchilded=awaitref.child("Reservoir/${widget.placeName}").once();Mapvalues;values=childed.value;resModel=ReseviorDataModel.customConstrc