MyTextField: added ability to show obscured text
parent
50aadf1b48
commit
3770418e29
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyTextField extends StatelessWidget {
|
||||
class MyTextField extends StatefulWidget {
|
||||
final String hintText;
|
||||
final bool obscureText;
|
||||
final TextEditingController controller;
|
||||
|
@ -14,14 +14,33 @@ class MyTextField extends StatelessWidget {
|
|||
this.focusNode,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MyTextField> createState() => _MyTextFieldState();
|
||||
}
|
||||
|
||||
class _MyTextFieldState extends State<MyTextField> {
|
||||
late bool _visibleText;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_visibleText = widget.obscureText;
|
||||
}
|
||||
|
||||
void _toggleObscureText() {
|
||||
setState(() {
|
||||
_visibleText = !_visibleText;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 25.0, vertical: 8),
|
||||
child: TextField(
|
||||
obscureText: obscureText,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
obscureText: _visibleText,
|
||||
controller: widget.controller,
|
||||
focusNode: widget.focusNode,
|
||||
decoration: InputDecoration(
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
|
@ -32,7 +51,15 @@ class MyTextField extends StatelessWidget {
|
|||
BorderSide(color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
filled: true,
|
||||
hintText: hintText,
|
||||
hintText: widget.hintText,
|
||||
suffixIcon: widget.obscureText
|
||||
? IconButton(
|
||||
icon: Icon(
|
||||
_visibleText ? Icons.visibility : Icons.visibility_off,
|
||||
),
|
||||
onPressed: _toggleObscureText,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -45,7 +45,8 @@ class RegisterPage extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
showMsg(context, 'Registration error', 'Passwords do not match!');
|
||||
showMsg(context, 'Password Mismatch',
|
||||
'Password and repeated password do not match!');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class AuthService {
|
|||
/// sign in (login)
|
||||
///
|
||||
/// @throws FirebaseAuthException
|
||||
Future<UserCredential> signInWithEmailPassword(String email, password) async {
|
||||
Future<UserCredential> signInWithEmailPassword(String email, String password) async {
|
||||
try {
|
||||
UserCredential userCredential = await _auth.signInWithEmailAndPassword(
|
||||
email: email,
|
||||
|
|
Loading…
Reference in New Issue