我保存了一个boolean标志sharedpreferences,我需要在应用程序的一开始就进入该标志。如果我卸载并再次安装该应用程序然后收到该标志,会发生什么情况?对我来说,它不会抛出异常,而是在卸载之前向我发送值。我想知道这怎么可能..
为了避免FutureBuilder一次又一次地被调用(请参阅此),我有调用我的 future 的习惯,initState并且它一直工作得很好,直到我不得不使用嵌套的 future。
connectionState基本上我希望第二个 future 仅在第一个 future成为 后才被调用done。有什么帮助吗?
这是我的代码进一步解释-
FutureBuilder(
future: _future1,
builder: (BuildContext context, AsyncSnapshot snapshot) {
return snapshot.connectionState != ConnectionState.done
? CircularProgressIndicator()
: snapshot.data != 200
? SomeWidget()
: FutureBuilder(
future: _future2,
builder: (BuildContext context, AsyncSnapshot snapshot) {
return snapshot?.connectionState == ConnectionState.done
? Text('')
: CircularProgressIndicator();
});
},
);
Run Code Online (Sandbox Code Playgroud)
_future2所以基本上,如果收到的数据不是 200 ,我根本不想被调用_future1。换句话说,我想_future2根据 的结果决定是否应该被调用_future1。

如何使指示进度的小部件看起来像所附图像?
我正在使用call_number插件从我的应用程序拨打电话。我正在跟踪AppLifecycleState采取行动。这是状态变化的顺序 -
AppLifecycleState.inactive
AppLifecycleState.resumed
AppLifecycleState.inactive
AppLifecycleState.paused
AppLifecycleState.inactive
AppLifecycleState.resumed
Run Code Online (Sandbox Code Playgroud)
最后4-我理解流程,但我无法理解为什么状态会resumed第一次改变。根据文档 - “应用程序是可见的并响应用户输入。” 当它处于恢复状态但当我按下按钮时,直接拨打电话。我想知道它是否是由插件在后台完成的,但我什至没有看到我的应用程序出现。
我使用 canvas.drawLine 来显示一条线,但我希望用户能够看到它从一个点绘制到另一个点,并且如果可能的话,还可以控制动画的持续时间。(类似于进度条,但这是我的自定义小部件)
如果没有网络,我想显示一个错误屏幕。我没有使用连接包,因为我不想连续检查。我只想在调用后端 api 并显示屏幕时处理异常。我无法捕获异常。
我发现了这个问题和这个关于套接字异常的问题,但似乎没有一个对我有帮助。
这就是我调用后端 api 的方式 -
callBackendApi() async {
try {
http.Response response = await Future.value(/*api call here*/)
.timeout(Duration(seconds: 90), onTimeout: () {
print('TIME OUT HAPPENED');
});
} catch (exception) {
Fluttertoast.showToast(msg: 'Check internet connection.');
print('Error occurred' + exception.toString());
}
}
Run Code Online (Sandbox Code Playgroud) flutter ×6
dart ×4
asynchronous ×2
components ×1
future ×1
lifecycle ×1
line ×1
paint ×1
progress-bar ×1
state ×1
widget ×1