SignIn Page to detect enter press to submit

This commit is contained in:
2024-07-19 13:34:34 +02:00
parent 029ddbf6d8
commit a65081ef7f

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:patient_manager/components/myErrorMessage.dart'; import 'package:patient_manager/components/myErrorMessage.dart';
import 'package:patient_manager/components/myPassInput.dart'; import 'package:patient_manager/components/myPassInput.dart';
import 'package:patient_manager/components/myTextInput.dart'; import 'package:patient_manager/components/myTextInput.dart';
@@ -19,6 +20,8 @@ class _SignInState extends State<SignIn> {
final passwordController = TextEditingController(); final passwordController = TextEditingController();
//bool _obscureText = true; //bool _obscureText = true;
bool successfulSignIn = false; bool successfulSignIn = false;
// focus node to capture keyboard events
final FocusNode _focusNode = FocusNode();
//sign user in //sign user in
Future<void> signUserIn() async { Future<void> signUserIn() async {
@@ -51,7 +54,29 @@ class _SignInState extends State<SignIn> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) {
if (emailController.text.isEmpty || passwordController.text.isEmpty) {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Input Error");
},
);
} else {
signUserIn();
}
if (successfulSignIn) {
Navigator.of(context).pushNamed('/homme');
}
}
},
child: Scaffold(
//backgroundColor: Colors.white, //backgroundColor: Colors.white,
body: SafeArea( body: SafeArea(
child: Center( child: Center(
@@ -75,8 +100,9 @@ class _SignInState extends State<SignIn> {
style: TextStyle( style: TextStyle(
fontSize: 25, fontSize: 25,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: color: MzanziInnovationHub.of(context)!
MzanziInnovationHub.of(context)!.theme.secondaryColor(), .theme
.secondaryColor(),
), ),
), ),
//spacer //spacer
@@ -110,8 +136,9 @@ class _SignInState extends State<SignIn> {
height: 100.0, height: 100.0,
child: MyButton( child: MyButton(
buttonText: "Sign In", buttonText: "Sign In",
buttonColor: buttonColor: MzanziInnovationHub.of(context)!
MzanziInnovationHub.of(context)!.theme.secondaryColor(), .theme
.secondaryColor(),
textColor: textColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(), MzanziInnovationHub.of(context)!.theme.primaryColor(),
onTap: () { onTap: () {
@@ -164,7 +191,10 @@ class _SignInState extends State<SignIn> {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
) ),
const SizedBox(
width: 15,
),
], ],
), ),
) )
@@ -173,6 +203,7 @@ class _SignInState extends State<SignIn> {
), ),
), ),
), ),
),
); );
} }
} }