0

我在开发我的应用程序时遇到问题,我知道页面导航可以使用“Navigation.of(context)”并通过 ID 传递参数,但是我想对页面做同样的事情但找不到任何解决方案。如果有人知道如何制作它,请给我一些线索。太感谢了!!错过的都会更新

对话

还有另一个“自定义对话框”类,它为对话框定义并在用户输入信息后执行 onSaved 内容。保存的每个链接都会自动生成一个 ID,因此希望传递“ID”以进行更新,但仍停留在如何传递“ID”参数上。

  Future<dynamic> callDialog(BuildContext context) {
    String label;

    if (appTitle == "Instagram") {
      label = "Please Enter Your Username";
    } else if (appTitle == "Whatsapp") {
      label = "Please Enter Your Phone Number";
    } else if (appTitle == "LinkedIn") {
      label = "Please Enter Your URL";
    } else if (appTitle == "Mail") {
      label = "Please Enter Your E-mail";
    }

    return showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return CustomDialogBox(
          title: appTitle,
          descriptions: "$label",
          button1: "Cancel",
          button2: "Save",
          img: appImage,
        );
      },
    );
  }

导航

在导航的一部分中已经尝试做类似的传递参数“ID”,但它不起作用所以有什么方法可以将参数从页面传递到对话框?

Widget build(BuildContext context) {
        return Card(
          child: Hero(
            tag: appTitle,
            child: InkWell(
              onTap: () {
                callDialog(context,);
              },
              child: GridTile(
                footer: GridTileBar(
                  backgroundColor: Colors.black54,
                  title: Text(
                    appTitle,
                    textAlign: TextAlign.center,
                  ),
                ),
                child: Image.asset(
                  appImage,
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),
        );
      }

didChangeDependencies对话框

  @override
  void didChangeDependencies() {
    if (_isInit) {
      final appId = ModalRoute.of(context).settings.arguments as String;
      if (appId != null) {
        //check product exist
        _editedApp = Provider.of<UserProfileLogic>(context, listen: false)
            .findByAppId(appId);
        _initValues = {
          "title": _editedApp.title,
          "urlLink": _editedApp.appLink,
          "imageUrl": _editedApp.appImage,
        };
      }
    }
    _isInit = false;
    super.didChangeDependencies();
  }
4

1 回答 1

0

只需将 id 作为calldialogue函数中的参数传递

示例代码: -

Future<dynamic> callDialog(BuildContext context,String id) {
String label;

if (appTitle == "Instagram") {
  label = "Please Enter Your Username";
} else if (appTitle == "Whatsapp") {
  label = "Please Enter Your Phone Number";
} else if (appTitle == "LinkedIn") {
  label = "Please Enter Your URL";
} else if (appTitle == "Mail") {
  label = "Please Enter Your E-mail";
}

return showDialog(
  context: context,
  barrierDismissible: false,
  builder: (BuildContext context) {
    return CustomDialogBox(
      title: appTitle,
      descriptions: "$label",
      button1: "Cancel",
      button2: "Save",
      img: appImage,
    );
  },
);

}

导航代码:-

Widget build(BuildContext context) {
    return Card(
      child: Hero(
        tag: appTitle,
        child: InkWell(
          onTap: () {
            callDialog(context,id); //pass your id here
          },
          child: GridTile(
            footer: GridTileBar(
              backgroundColor: Colors.black54,
              title: Text(
                appTitle,
                textAlign: TextAlign.center,
              ),
            ),
            child: Image.asset(
              appImage,
              fit: BoxFit.cover,
            ),
          ),
        ),
      ),
    );
  }
于 2021-06-14T05:22:37.367 回答