centered elements

This commit is contained in:
Specoolazius 2021-11-15 13:44:33 +01:00
parent 807d2a87cd
commit 3a684dd681

View File

@ -21,40 +21,23 @@ class LoginPage extends StatefulWidget {
}
class _LoginPageState extends State<LoginPage> {
bool _isPasswordObscure = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Welcome')),
// https://www.kindacode.com/article/flutter-show-hide-password-in-textfield-textformfield/
// https://www.kindacode.com/article/flutter-filteringtextinputformatter/
body: ListView(
children: <Widget>[
UsernameField(),
Padding(
padding: const EdgeInsets.all(10),
child: Center(
child: TextField(
obscureText: _isPasswordObscure,
decoration: InputDecoration(
hintText: 'Password',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10)),
suffixIcon: IconButton(
icon: Icon(_isPasswordObscure
? Icons.visibility
: Icons.visibility_off),
onPressed: () {
setState(() {
_isPasswordObscure = !_isPasswordObscure;
});
},
))),
),
)
body: Center(
child: new ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(20.0),
children: [
new UsernameField(),
new PasswordField(),
],
));
),
),
);
}
}
@ -75,3 +58,39 @@ class UsernameField extends StatelessWidget {
);
}
}
class PasswordField extends StatefulWidget {
const PasswordField({Key? key}) : super(key: key);
@override
_PasswordFieldState createState() => _PasswordFieldState();
}
class _PasswordFieldState extends State<PasswordField> {
bool _isPasswordObscure = true;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(10),
child: Center(
child: TextField(
obscureText: _isPasswordObscure,
decoration: InputDecoration(
hintText: 'Password',
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
suffixIcon: IconButton(
icon: Icon(_isPasswordObscure
? Icons.visibility
: Icons.visibility_off),
onPressed: () {
setState(() {
_isPasswordObscure = !_isPasswordObscure;
});
},
))),
),
);
}
}