Hmm... I can't understand why my project have error... Please hlep me.
[Error Message]
Error: The getter 'user' isn't defined for the class '_CreatePageState'.
- '_CreatePageState' is from 'package:insta_clone2_start/create_page.dart'('lib/create_page.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'user'.
context, MaterialPageRoute(builder:(context) => HomePage(user)),
^^^^
[Environment] **NON null_safety
environment:
sdk: ">=2.7.0 <3.0.0"
[HomePage Code]
class HomePage extends StatelessWidget {
final FirebaseUser user;
HomePage(this.user);
[Create Page1]
class CreatePage extends StatefulWidget {
final FirebaseUser user;
CreatePage(this.user);
@override
_CreatePageState createState() => _CreatePageState();
}
[Create Page2]
Navigator.push(
context, MaterialPageRoute(builder:(context) => HomePage(user)),
);
CodePudding user response:
try this :
Navigator.push(
context, MaterialPageRoute(builder:(context) => HomePage(widget.user)),
);
CodePudding user response:
class MyApp extends StatelessWidget {
FirebaseUser e=FirebaseUser();//create object from class FirebaseUser
@override
Widget build(BuildContext context) {
return GetMaterialApp(
home:Scaffold(
appBar: AppBar(),
floatingActionButton: FloatingActionButton(onPressed: (){
Navigator.push(
context, MaterialPageRoute(builder:(context) => HomePage(user:e)),//see the difference
);
}),
));
}
}