I found a solution with Navigator.pop(context, data) in showModalBottomSheet
this is solution
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0, AppBar().preferredSize.height, 0, 0),
child: CountryPicker(
countryCodes: countryCodes,
),
);
},
).then((value) {
setState(() {
countryCodeIndex = value;
});
});
but i can't use method then in showBottomSheet
this is error that i got
The method 'then' isn't defined for the type 'PersistentBottomSheetController'.
Try correcting the name to the name of an existing method, or defining a method named 'then
How i can receive data from showBottomSheet
CodePudding user response:
Using showModalBottomSheet
you can just use then()
or await
When you have to use showBottomSheet()
it returns a PersistentBottomSheetController
that has a property closed
of type Future<T> that can also be used with then()
or await
. Check API documentation on that: https://api.flutter.dev/flutter/material/PersistentBottomSheetController-class.html
Edit: I did some further research: Seems like showBottomSheet is not working as expected. There's an issue (https://github.com/flutter/flutter/issues/66837) where it's stated that Navigator.pop(context)
with data is not working...
So if possible I would recommend to use ``