首页 > 解决方案 > 在文本小部件中接收数据后如何关闭对话框小部件

问题描述

当我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 "),            



标签: flutterdart

解决方案


你可以用不同的方式来做,比如不显示初始化状态的对话框,你可以使用 FutureBuilder 代替,如下所示

FutureBuilder<String>(
future: _getData,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
   if (snapshot.connectionState!=ConnectionState.done) {
      return CircularProgressIndicator();
    }
    else Text(snapshot.data);
  },
)

或者你也可以使用这个


推荐阅读