'capture value from login fields
I'm facing a problem getting values from the login field, I solved it, I'm using an elegant model, and I'm trying to modify it, seeing some examples I can't adapt to my problem.
main.dart file
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Login',
theme: ThemeData(
primaryColor: kPrimaryColor,
scaffoldBackgroundColor: Colors.white,
),
home: LoginScreen(),
);
}
}
my login.dart file
class LoginScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Body(),
);
}
}
they are in a separate file, I think it's better that way, but all the examples that I see people use practically inside a single file, the buttons are one for each file for that module
my file body.dart
class Body extends StatelessWidget {
final TextEditingController usuarioController = TextEditingController();
final TextEditingController _senhaController = TextEditingController();
/* const Body({
Key? key,
}) : super(key: key);*/
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Background(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"LOGIN",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: size.height * 0.03),
SvgPicture.asset(
"assets/icons/login.svg",
height: size.height * 0.35,
),
SizedBox(height: size.height * 0.03),
RoundedInputField(
hintText: "Seu Email",
onChanged: (value) {},
),
RoundedPasswordField(
onChanged: (value) {},
),
RoundedButton(
text: "LOGIN",
callbackClickLogin: () {},
),
SizedBox(height: size.height * 0.03),
],
),enter code here
),
);
}
}
I saw in an example that I need to define
final TextEditingController userController = TextEditingController();
to get data from the user field,
and final TextEditingController _passwordController = TextEditingController();
to get the password values.
and this is the click-to-login button
my file button_login.dart
class RoundedButton extends StatelessWidget {
final text of the String;
final Function() callbackClickLogin;
final color Color, textColor;
constRounded Button({
Key? key,
necessary this.text,
required this.callbackClickLogin,
this.color = kPrimaryColor,
this.textColor = Colors.white,
}) : super(key: key);
@overlay
Widget Build (BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
width: size.width * 0.8,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
child: newElevatedButton(),
),
);
}
//Used:ElevatedButton as FlatButton is deprecated.
//Here we have to apply customizations to the Button inheriting the styleFrom
newElevatedButton() widget {
return HighButton(
child: Text(
text,
style: TextStyle (color: textColor),
),
onPressed: callbackClickLogin,
style: ElevatedButton.styleFrom(
primary color,
padding: EdgeInsets.symmetric(horizontal: 40, vertical: 20),
Text Style: Text Style(
color: textColor, fontSize: 14, fontWeight: FontWeight.w500)
),
);
}
}
I don't know how to retrieve the values when I click the login button, as I want to get the values and pass them to another class in another file that will make a query via api.
I'm new to flutter.
thank you all.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
