简体   繁体   English

颤动:如何关闭 giffy 对话框

[英]flutter: How to close a giffy dialog

How to close a NetworkGiffyDialog ?如何关闭NetworkGiffyDialog

showDialog(
  context: context,
  builder: (_) => NetworkGiffyDialog(
    image: Image.asset('asset/gif/send.gif'),
    title: const Text('Send Money',
        textAlign: TextAlign.center,
        style: TextStyle(
            fontSize: 22.0,
            fontWeight: FontWeight.w600)),
    description:const Text('Are you sure you want to Send this Amount?',
      textAlign: TextAlign.center,
    ),
    entryAnimation: EntryAnimation.BOTTOM,
      onOkButtonPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) => const HomePage()));
          Fluttertoast.showToast(msg: "Sent with Success");
      },
  ),
);

Instead of Navigator.push(...) , just use Navigator.pop(context, result) on the NetworkGiffyDialog.onOkButtonPressed and/or NetworkGiffyDialog.onCancelButtonPressed events.而不是Navigator.push(...) ,只需在NetworkGiffyDialog.onOkButtonPressed和/或NetworkGiffyDialog.onCancelButtonPressed事件上使用Navigator.pop(context, result) Where the result can be a boolean that says if the user did tap on Cancel or OK button. result可以是一个布尔值,表示用户是否点击了CancelOK按钮。 It should close the dialog displayed by the showDialog function它应该关闭showDialog 函数显示的对话框

just like onOkButtonPressed, add onCancelButtonPressed inside NetworkGifyDialog, also add buttonCancelText for text.就像 onOkButtonPressed 一样,在 NetworkGifyDialog 中添加onCancelButtonPressed ,还为文本添加buttonCancelText

buttonCancelText: Text('cancel'),
//dismiss the dialog.
onCancelButtonPressed:()
{
Navigator.pop(context);
}


showDialog(
                      context: context,
                      builder: (_) => NetworkGiffyDialog(
                            key: keys[1],
                            image: Image.network(
                              "https://raw.githubusercontent.com/Shashank02051997/FancyGifDialog-Android/master/GIF's/gif14.gif",
                              fit: BoxFit.cover,
                            ),
                            entryAnimation: EntryAnimation.TOP_LEFT,
                            title: Text(
                              'Granny Eating Chocolate',
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  fontSize: 22.0, fontWeight: FontWeight.w600),
                            ),
                            description: Text(
                              'This is a granny eating chocolate dialog box. This library helps you easily create fancy giffy dialog.',
                              textAlign: TextAlign.center,
                            ),
                            onOkButtonPressed: () {},
//dismiss the dialog.
onCancelButtonPressed:()
{
Navigator.pop(context);
}
                          ));
                }),


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM