flutter - 在文本小部件中接收数据后如何关闭对话框小部件
问题描述
当我buildShowDialog
收到 initState
一些想要关闭buildShowDialog
. 我怎样才能做到这一点 ?
buildshowDialog 方法
buildShowDialog(BuildContext context) {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Center(
child: CircularProgressIndicator(),
);
});
}
调用它initState
@override
void initState() {
super.initState();
buildShowDialog(context);
}
现在在我的小部件中,当我从提供程序包中获取我的文本小部件中的一些数据时,我想关闭对话框然后
@override
Widget build(BuildContext context) {
\\\
return Scaffold(
body: Stack(
\\\
Consumer < AppData > (
builder: (ctx, prod, child) => dropOffText ?
Text(
prod.dropOffLocation != null ?
prod.dropOffLocation
***CALL NAVIGATOR.POP HERE! *** (close the dialog here)
:
"Pick your destination ",
style: TextStyle(fontSize: 12.0),
overflow: TextOverflow.ellipsis,
) :
Text("Pick your destination "),
解决方案
你可以用不同的方式来做,比如不显示初始化状态的对话框,你可以使用 FutureBuilder 代替,如下所示
FutureBuilder<String>(
future: _getData,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.connectionState!=ConnectionState.done) {
return CircularProgressIndicator();
}
else Text(snapshot.data);
},
)
或者你也可以使用这个包
推荐阅读
- python - 拆分数据框取决于使用 python 的 csv 文件大小
- java - JPA 标准 - 如何准备 SELECT IN 查询
- css - 为什么面包屑文本不能右对齐?
- tabulator - 查找要用作迭代器的单元格索引
- swift - 共享内部类/方法/等。Swift 模块之间
- python - 运行 bash 命令在 Python3 中复制粘贴文件是一个可靠的选择吗?
- database - 表格 - 转到下一页的按钮
- linux - 我可以在 shell 脚本的第一行省略“shebang”的完整路径吗?
- python - 关于 sum 函数的 Python 弃用警告
- python - ValueError:超出最大允许尺寸,AgglomerativeClustering fit_predict