class _RigestritState extends State<Rigestrit> {
final _auth = FirebaseAuth.instance;
late String email;
late String password;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: backrond,
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('تسجيل' ,style: logo, textAlign: TextAlign.center,),
SizedBox(height: 50,),
ButtenHint(hint: 'الايميل ', onpressed:(value){ email = value;}, obscureText: false, ),
ButtenHint(hint: 'كلمة السر ', onpressed:(value){password = value;}, obscureText: true, ),
Mybouttn(color: blueColor, titel: 'تسجيل', onpressed: () async {//to send the data to firebase
try{
final newUer = await _auth.createUserWithEmailAndPassword(email: email, password: password);
Navigator.pushNamed(context, home.homePage);
}catch(e){
print(e);
}
}),
CodePudding user response:
Name and Email are initialized as late but not initialized before accessing the field.
Fields are initialized with the value
String email = '';
String password = '';
or it should be initialized before accessing the value
late String email;
late String password;
@override
void initState(){
email = '';
password = '';
super.initState();
}
And the late keyword is mostly used to define the final value when the value might be available in the future.