How run code after showDialog is dismissed in Flutter?

前端 未结 7 1436
心在旅途
心在旅途 2021-02-05 01:11

How to update the Homepage just after the showDialog() is dismissed/disposed? Doesn\'t seem like it has an onDispose() function.

Found another

7条回答
  •  感情败类
    2021-02-05 01:32

    There are two approaches.

    1. Use async-await

      bool shouldUpdate = await showDialog(...);
      if (shouldUpdate) {
        setState(() {
          // we should update the UI
        });
      }
      
    2. Use then

      showDialog(...).then((shouldUpdate) {
        if (shouldUpdate) {
          setState(() {
            // we should update the UI
          });
        }
      });
      

提交回复
热议问题