flutter go back
Navigator.pop(context);
flutter go back
Navigator.pop(context);
flutter not navigating to a new screen
Wrap the new screen with a Scaffold widget
//navigation page
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DestinationScreen()),
);
}
// new screen page
class _DestinationScreenState extends State<DestinationScreen> {
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
call back in flutter
77
The declaration of VoidCallback is
typedef void VoidCallback();
That is the type of functions that can be called with zero arguments and which does not return a useful value. That does not seem to be what you want. It's not entirely clear what you do want since the program isn't syntactically valid, but would this work for you:
class MyClass {
static doSomething(int i) { /* ... */ }
MyOtherClass myOtherClass = new MyOtherClass(doSomething);
}
class MyOtherClass {
final void Function(int) callback;
MyOtherClass(this.callback);
void callCallaback() { callback(5); }
}
Here we define the type of the callback field to be the type of functions that can be called with one integer argument and which returns no useful value. The doSomething method has that type, so it can be assigned to callback.
You could also use a typedef to name the function:
typedef Int2VoidFunc = void Function(int);
// or: typedef void Int2VoidFunc(int arg);
class MyOtherClass {
final Int2VoidFunc callback;
MyOtherClass(this.callback);
void callCallaback() { callback(5); }
}
The effect is exactly the same, it just allows you to use a shorter name for the function type, but that only really makes sense if you use it a lot.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us