Ad
MaterialButton OnPressed Listener Not Work (Flutter)
I created a layout like this, the problem is that the onPressed listener doesn't work but I can't understand why:
Material(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(22.0)),
color: const Color.fromRGBO(33, 63, 132, 1),
clipBehavior: Clip.antiAlias,
child: MaterialButton(
height: 140.0,
minWidth: 380.0,
elevation: 20.0,
color: const Color.fromRGBO(33, 63, 132, 1),
textColor: Colors.white,
child: Text("Chiudi sessione / Cambia utente",
style: TextStyle(
fontSize: ScreenUtil().setSp(20),
)),
onPressed: () {
var future = endUserSession(badgeCode, false, context);
future.then((value) {
setUserBadgeForDualMode("");
setDoorStatusIntoPrefs("");
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const OpenDoorDualMode()));
});
}
),
)
What am I doing wrong?
Ad
Answer
The problem seems to be with your function call, you are not awaiting for a future value, Use it that way
var future = await endUserSession(badgeCode, false, context);
Or Try Removing it and call your function like this
await endUserSession(badgeCode, false, context).then((value) async {
await setUserBadgeForDualMode("");
await setDoorStatusIntoPrefs("");
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const OpenDoorDualMode()));
});
Use "await" wherever you are expecting a future value.
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad