I am new to flutter and I was trying to test some liblaries. But unfortunately when I run this code, I get error:
error mesage:
error G4A9793AD: The value 'null' can't be assigned to the parameter type 'Key' because 'Key' is not nullable.
...some code...
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MainPage(title: 'Flutter Convex BottomBar Sample'),
);
}
}
class MainPage extends StatefulWidget {
MainPage({required Key key, required this.title}) : super(key: key);
...some code...
CodePudding user response:
You can't pass a value of null
to the key
parameter because it's non-nullable (can't have null
as value) to mark it as nullable you should add ?
:
MainPage({required Key? key, required this.title}) : super(key: key);
Anyway I think that's not what you want because its also not allowed. Simply drop the required
keyword or pass a valid key to it:
MainPage({Key key, required this.title}) : super(key: key);
CodePudding user response:
Either remove the Key key
variable from MainPage
by deleting it,
OR just provide a key
home: MainPage(title: 'Flutter Convex BottomBar Sample',key : Key('homepage'),),