import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class SignIn extends StatefulWidget {
const SignIn({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _SignInState();
}
class _SignInState extends State<SignIn> {
bool obscureTextPassword = true;
@override
Widget build(BuildContext context) => Card(child: Container(width: 300,child: Column(children: [_emailField(),_passwordField(),
],),),);}
Widget _emailField() => const Padding(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 24),
child: TextField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(
fontSize: 16,
color: Colors.black,
),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Indirizzo Email',
hintStyle: TextStyle(fontSize: 17),
icon: Icon(
FontAwesomeIcons.envelope,
color: Colors.black,
size: 22,
)),
),
);
Widget _passwordField() => Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 24),
child: TextField(
obscureText: obscureTextPassword,
style: const TextStyle(
fontSize: 16,
color: Colors.black,
),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Password',
hintStyle: const TextStyle(fontSize: 17),
icon: const Icon(
FontAwesomeIcons.lock,
color: Colors.black,
size: 22,
),
suffixIcon: GestureDetector(
onTap: () {
setState(() {
obscureTextPassword = !obscureTextPassword;
});
},
child: Icon(
obscureTextPassword
? FontAwesomeIcons.eye
: FontAwesomeIcons.eyeSlash,
size: 15,
color: Colors.black)),
),
),
);
2
Answers
Add the variable both to your state class (
_SignInState
) and your widget class (SignIn
). Assign them in both constructors. Then pass the variable from the widget class to the state class inWidget.createState
. You can then access the variable in the build method.It would be great if you could mention more details. But I’ll provide you with an example let me know if it resolves the issue you are facing: