MyTextField: added ability to show obscured text
parent
50aadf1b48
commit
3770418e29
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class MyTextField extends StatelessWidget {
|
class MyTextField extends StatefulWidget {
|
||||||
final String hintText;
|
final String hintText;
|
||||||
final bool obscureText;
|
final bool obscureText;
|
||||||
final TextEditingController controller;
|
final TextEditingController controller;
|
||||||
|
@ -14,14 +14,33 @@ class MyTextField extends StatelessWidget {
|
||||||
this.focusNode,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 25.0, vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 25.0, vertical: 8),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
obscureText: obscureText,
|
obscureText: _visibleText,
|
||||||
controller: controller,
|
controller: widget.controller,
|
||||||
focusNode: focusNode,
|
focusNode: widget.focusNode,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide:
|
borderSide:
|
||||||
|
@ -32,7 +51,15 @@ class MyTextField extends StatelessWidget {
|
||||||
BorderSide(color: Theme.of(context).colorScheme.primary),
|
BorderSide(color: Theme.of(context).colorScheme.primary),
|
||||||
),
|
),
|
||||||
filled: true,
|
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 {
|
} 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)
|
/// sign in (login)
|
||||||
///
|
///
|
||||||
/// @throws FirebaseAuthException
|
/// @throws FirebaseAuthException
|
||||||
Future<UserCredential> signInWithEmailPassword(String email, password) async {
|
Future<UserCredential> signInWithEmailPassword(String email, String password) async {
|
||||||
try {
|
try {
|
||||||
UserCredential userCredential = await _auth.signInWithEmailAndPassword(
|
UserCredential userCredential = await _auth.signInWithEmailAndPassword(
|
||||||
email: email,
|
email: email,
|
||||||
|
|
Loading…
Reference in New Issue