4
answers
1
watching
289
views

I asked this question before I still don't get it. Using Flutter ver 3.3.2 

Return value is missing see attachment on the bottom of this page.

 

Here is the full code and the screenshot below the full code. Also when putting in the answer can you put in the full code. Because I put in the previous answers I still got error messages.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {

runApp(const MyApp());
}
class MyAppState extends State<MyApp>{
@override
Widget build(BuildContext context) {
return;
}
}
class MyApp extends StatefulWidget {

const MyApp({super.key});

@override

MyAppState createState() => MyAppState();
}

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?.isEmpty?? true) {
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 == null) {
return "Password cannot be null";
} else if (inValue.length < 10) {
return "Password must be >= 10 in length";
}
return null;
},

onSaved: (String? inValue) {
loginData.password = inValue!;
},

decoration: const InputDecoration(
hintText : "Password",
labelText : "Password"
),
),

ElevatedButton(

child : const Text("Log In!"),

onPressed: (){

if (_formkey.currentState!.validate()){

_formkey.currentState!.save();

if (kDebugMode) {
debugPrint ("Username: ${loginData.username}");
}
if (kDebugMode) {
debugPrint ("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 2 others
Already have an account? Log in
Avatar image
Liked by dragon2020 and 1 others
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in

Related questions

Weekly leaderboard

Start filling in the gaps now
Log in