2021年3月27日星期六

Parameter is null instead of an id with ModalRoute.of()

I am developing a mobile App with Flutter and Firebase.

I am trying to use pushNamed() and hand over a parameter. (an id)

I don't know how i could solve my problem.

Here is my Code:

@override    void didChangeDependencies() {      if (_isInit) {        print(ModalRoute.of(context).settings.arguments);        final productId = ModalRoute.of(context).settings.arguments;        if (productId != null) {          _editedAngebot = Provider.of<Angebote>(context).findByID(productId);          _initValues = {            'titel': _editedAngebot.titel,            'beschreibung': _editedAngebot.beschreibung,            'semester': _editedAngebot.semester.toString(),            'fach': _editedAngebot.fach,            'abteilung': _editedAngebot.abteilung,          };        }      }      _isInit = false;      super.didChangeDependencies();    }  

And the other class, where I set the parameter. My "Angebot" object only has a default constructor.

trailing: isAllowed()              ? IconButton(                  icon: Icon(Icons.edit),                  onPressed: () {                    Navigator.of(context).maybePop();                    Navigator.of(context)                        .pushNamed('/editAngebot', arguments: id);                  })  

Why is my ID null?

https://stackoverflow.com/questions/66834506/parameter-is-null-instead-of-an-id-with-modalroute-of March 28, 2021 at 01:59AM

没有评论:

发表评论