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/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,124 +54,152 @@ class _SignInState extends State<SignIn> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return KeyboardListener(
|
||||||
//backgroundColor: Colors.white,
|
focusNode: _focusNode,
|
||||||
body: SafeArea(
|
autofocus: true,
|
||||||
child: Center(
|
onKeyEvent: (event) {
|
||||||
child: SingleChildScrollView(
|
if (event is KeyDownEvent &&
|
||||||
physics: const BouncingScrollPhysics(),
|
event.logicalKey == LogicalKeyboardKey.enter) {
|
||||||
child: Column(
|
if (emailController.text.isEmpty || passwordController.text.isEmpty) {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
showDialog(
|
||||||
children: [
|
context: context,
|
||||||
//logo
|
builder: (context) {
|
||||||
Icon(
|
return const MyErrorMessage(errorType: "Input Error");
|
||||||
Icons.lock,
|
},
|
||||||
size: 100,
|
);
|
||||||
color:
|
} else {
|
||||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
signUserIn();
|
||||||
),
|
}
|
||||||
//spacer
|
|
||||||
const SizedBox(height: 10),
|
if (successfulSignIn) {
|
||||||
//Heading
|
Navigator.of(context).pushNamed('/homme');
|
||||||
Text(
|
}
|
||||||
'Sign In',
|
}
|
||||||
style: TextStyle(
|
},
|
||||||
fontSize: 25,
|
child: Scaffold(
|
||||||
fontWeight: FontWeight.bold,
|
//backgroundColor: Colors.white,
|
||||||
|
body: SafeArea(
|
||||||
|
child: Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
physics: const BouncingScrollPhysics(),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
//logo
|
||||||
|
Icon(
|
||||||
|
Icons.lock,
|
||||||
|
size: 100,
|
||||||
color:
|
color:
|
||||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
),
|
),
|
||||||
),
|
//spacer
|
||||||
//spacer
|
const SizedBox(height: 10),
|
||||||
const SizedBox(height: 25),
|
//Heading
|
||||||
//email input
|
Text(
|
||||||
SizedBox(
|
'Sign In',
|
||||||
width: 500.0,
|
style: TextStyle(
|
||||||
child: MyTextField(
|
fontSize: 25,
|
||||||
controller: emailController,
|
fontWeight: FontWeight.bold,
|
||||||
hintText: 'Email',
|
color: MzanziInnovationHub.of(context)!
|
||||||
editable: true,
|
.theme
|
||||||
required: true,
|
.secondaryColor(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
//spacer
|
||||||
//spacer
|
const SizedBox(height: 25),
|
||||||
const SizedBox(height: 25),
|
//email input
|
||||||
//password input
|
SizedBox(
|
||||||
SizedBox(
|
width: 500.0,
|
||||||
width: 500.0,
|
child: MyTextField(
|
||||||
child: MyPassField(
|
controller: emailController,
|
||||||
controller: passwordController,
|
hintText: 'Email',
|
||||||
hintText: 'Password',
|
editable: true,
|
||||||
required: true,
|
required: true,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
//spacer
|
||||||
//spacer
|
const SizedBox(height: 25),
|
||||||
const SizedBox(height: 10),
|
//password input
|
||||||
// sign in button
|
SizedBox(
|
||||||
SizedBox(
|
width: 500.0,
|
||||||
width: 500.0,
|
child: MyPassField(
|
||||||
height: 100.0,
|
controller: passwordController,
|
||||||
child: MyButton(
|
hintText: 'Password',
|
||||||
buttonText: "Sign In",
|
required: true,
|
||||||
buttonColor:
|
),
|
||||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
),
|
||||||
textColor:
|
//spacer
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
const SizedBox(height: 10),
|
||||||
onTap: () {
|
// sign in button
|
||||||
if (emailController.text.isEmpty ||
|
SizedBox(
|
||||||
passwordController.text.isEmpty) {
|
width: 500.0,
|
||||||
showDialog(
|
height: 100.0,
|
||||||
context: context,
|
child: MyButton(
|
||||||
builder: (context) {
|
buttonText: "Sign In",
|
||||||
return const MyErrorMessage(
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
errorType: "Input Error");
|
.theme
|
||||||
},
|
.secondaryColor(),
|
||||||
);
|
textColor:
|
||||||
} else {
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
signUserIn();
|
onTap: () {
|
||||||
}
|
if (emailController.text.isEmpty ||
|
||||||
|
passwordController.text.isEmpty) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return const MyErrorMessage(
|
||||||
|
errorType: "Input Error");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
signUserIn();
|
||||||
|
}
|
||||||
|
|
||||||
if (successfulSignIn) {
|
if (successfulSignIn) {
|
||||||
Navigator.of(context).pushNamed('/homme');
|
Navigator.of(context).pushNamed('/homme');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
//spacer
|
||||||
//spacer
|
//const SizedBox(height: 30),
|
||||||
//const SizedBox(height: 30),
|
//register text
|
||||||
//register text
|
SizedBox(
|
||||||
SizedBox(
|
width: 450.0,
|
||||||
width: 450.0,
|
height: 100.0,
|
||||||
height: 100.0,
|
child: Row(
|
||||||
child: Row(
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
children: [
|
||||||
children: [
|
const Text(
|
||||||
const Text(
|
'New User?',
|
||||||
'New User?',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
color: Color.fromARGB(255, 201, 200, 200)),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
width: 6,
|
|
||||||
),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: widget.onTap,
|
|
||||||
child: Text(
|
|
||||||
'Register Now',
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
color: MzanziInnovationHub.of(context)!
|
color: Color.fromARGB(255, 201, 200, 200)),
|
||||||
.theme
|
),
|
||||||
.secondaryColor(),
|
const SizedBox(
|
||||||
fontWeight: FontWeight.bold,
|
width: 6,
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: widget.onTap,
|
||||||
|
child: Text(
|
||||||
|
'Register Now',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
const SizedBox(
|
||||||
],
|
width: 15,
|
||||||
),
|
),
|
||||||
)
|
],
|
||||||
],
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user