SignIn Page to detect enter press to submit
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:patient_manager/components/myErrorMessage.dart';
|
||||
import 'package:patient_manager/components/myPassInput.dart';
|
||||
import 'package:patient_manager/components/myTextInput.dart';
|
||||
@@ -19,6 +20,8 @@ class _SignInState extends State<SignIn> {
|
||||
final passwordController = TextEditingController();
|
||||
//bool _obscureText = true;
|
||||
bool successfulSignIn = false;
|
||||
// focus node to capture keyboard events
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
//sign user in
|
||||
Future<void> signUserIn() async {
|
||||
@@ -51,7 +54,29 @@ class _SignInState extends State<SignIn> {
|
||||
|
||||
@override
|
||||
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,
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
@@ -75,8 +100,9 @@ class _SignInState extends State<SignIn> {
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
color: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
),
|
||||
),
|
||||
//spacer
|
||||
@@ -110,8 +136,9 @@ class _SignInState extends State<SignIn> {
|
||||
height: 100.0,
|
||||
child: MyButton(
|
||||
buttonText: "Sign In",
|
||||
buttonColor:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
buttonColor: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
textColor:
|
||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
onTap: () {
|
||||
@@ -164,7 +191,10 @@ class _SignInState extends State<SignIn> {
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
const SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -173,6 +203,7 @@ class _SignInState extends State<SignIn> {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user