I am getting this error, can't print the value in name. Why do I get errors like that here? The getter 'name' isn't defined for the type 'StatefulWidget'. Try importing the library that defines 'name', correcting the name to the name of an existing getter, or defining a getter or field named 'name'
class Otpnewuser extends StatelessWidget {
String name;
Otpnewuser({Key key, @required this.name}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Image.asset('assets/logo-sm.jpg', fit: BoxFit.cover),
backgroundColor: const Color.fromARGB(255, 111, 70, 173),
centerTitle: true),
body: const Center(child: OtpUser()),
));
}
}
class OtpUser extends StatefulWidget {
const OtpUser({Key key}) : super(key: key);
@override
OtpUserState createState() => OtpUserState();
}
class OtpUserState extends State {
void method() {
print(widget.name);
}