diff --git a/lib/login/loginscreen.dart b/lib/login/loginscreen.dart index 40c7183..1425c4b 100644 --- a/lib/login/loginscreen.dart +++ b/lib/login/loginscreen.dart @@ -21,40 +21,23 @@ class LoginPage extends StatefulWidget { } class _LoginPageState extends State { - 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: [ - 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; - }); - }, - ))), - ), - ) + 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: 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 { + 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; + }); + }, + ))), + ), + ); + } +}