0

I have a problem during develop my app, I understand navigation of page can used "Navigation.of(context)" with pass an argument with ID, however I would like to do same thing with page but could not find any solution. If anyone have idea how to make it please providing me some clue. Thank you so much!! Anything missed out will be updated

Dialog

There have another "Custom Dialog" class which define for the dialog and doing onSaved stuff once user key in information. Each of the link been saved will auto generate an ID so would like to pass the "ID" for update using but stuck on how to pass "ID" argument.

  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,
        );
      },
    );
  }

Navigation

In part of navigation have been tried to do something similar pass argument "ID" but it's not work so is there any way to pass argument from a page to dialog?

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 Dialog

  @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();
  }
Chinbin
  • 235
  • 3
  • 9

1 Answers1

0

Just pass the id as a parameter in calldialogue function

sample code:-

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,
    );
  },
);

}

Navigation code :-

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,
            ),
          ),
        ),
      ),
    );
  }
Piyush Kumar
  • 460
  • 2
  • 7
  • I have been tried for passing id something like this however how do I receive this "ID" in "didChangeDependecies"? If using normal Navigation would use "ModalRoute.of(context)" to pass the id but in here seems might have some differences. I have been update how my "didChangeDependencies" look like – Chinbin Jun 14 '21 at 07:22