4
answers
1
watching
193
views

Thanks to everyone answering my previous question. Decide to put the entire flutter widget program here. Using input from I got from the experts here. 

Major Issues found -

keyboardType: Flutter complains The named parameter keyboardType isn't defined.
How do I define it here?

if (inValue.length ==0) Flutter says use isempty
So I replaced like this if (inValue.isEmpty) but then Flutter shows the following
The property "isEmpty" can't be unconditionally accessed the because the receiver can be null
Try making the access conditional (using?.) or adding a null check to the target('!')

Also the onsave feature isn't working. There are others too many too list

The entire code is listed below. This code was written in a book in 2019.

import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
_MyApp createState() => _MyApp();
}



class LoginData {
String username = "";
String password = "";

}

class _MyApp extends State {

LoginData loginData = LoginData();
final GlobalKey<FormState> _formkey = GlobalKey<FormState>();

@override
Widget build(BuildContext inContext) {
return MaterialApp(home: Scaffold(
body : Container(
padding : const EdgeInsets.all(50.0),
child : Form(
key: _formkey,
child: Column(
children: [
TextFormField(
keyboardType:
TextInputType.emailAddress,
validator: (String? inValue) {
if (inValue.length ==0) {
{//do something
return "Please enter username";}
}
return null;

};
},
onsaved: (String inValue) {
loginData.username = inValue;
},
decoration: const InputDecoration(
hintText: "[email protected]",
labelText: "Username (eMail address)"
)
),
TextFormField(
obscureText: true,
validator: (String inValue)
if (inValue.length < 10) {
return "Password must be >=10 in length";
}
return null;
},
onSaved: (String inValue) {
this.loginData.password = inValue;
},
decoration: InputDecoration(
hintText : "Password"
labelText : "Password"
)
),
ElevatedButton(
child : Text("Log In!"),
onPressed: (){
if (_formkey.currentState.validate()){
_formkey.currentState.save();
print ("Username: ${_loginData.username}");
print ("Password: $_loginData.password}");
}
}
)
]
)
)
)
));
}
}

For unlimited access to Homework Help, a Homework+ subscription is required.

Avatar image
Liked by dragon2020 and 2 others

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Avatar image
Liked by dragon2020 and 1 others
Already have an account? Log in
Avatar image
Liked by dragon2020 and 2 others
Already have an account? Log in
Already have an account? Log in

Related questions

Weekly leaderboard

Start filling in the gaps now
Log in