add keyboard click for submit

This commit is contained in:
2024-08-05 15:39:09 +02:00
parent d523b6411f
commit 58f2a954ed
2 changed files with 55 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:patient_manager/components/myDropdownInput.dart';
import 'package:patient_manager/components/myErrorMessage.dart';
import 'package:patient_manager/components/mySuccessMessage.dart';
@@ -41,6 +42,7 @@ class _AddPatientState extends State<AddPatient> {
final baseAPI = AppEnviroment.baseApiUrl;
late int futureDocOfficeId;
late bool medRequired;
final FocusNode _focusNode = FocusNode();
bool isFieldsFilled() {
if (medRequired) {
@@ -292,16 +294,7 @@ class _AddPatientState extends State<AddPatient> {
height: 100.0,
child: MyButton(
onTap: () {
if (isFieldsFilled()) {
addPatientAPICall();
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Input Error");
},
);
}
submitForm();
},
buttonText: "Add",
buttonColor:
@@ -316,6 +309,19 @@ class _AddPatientState extends State<AddPatient> {
);
}
void submitForm() {
if (isFieldsFilled()) {
addPatientAPICall();
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Input Error");
},
);
}
}
@override
void initState() {
medAidController.addListener(isRequired);
@@ -332,7 +338,17 @@ class _AddPatientState extends State<AddPatient> {
Widget build(BuildContext context) {
return Scaffold(
appBar: const MIHAppBar(barTitle: "Add Patient"),
body: displayForm(),
body: KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (event) async {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) {
submitForm();
}
},
child: displayForm(),
),
);
}
}

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:patient_manager/components/mihAppBar.dart';
import 'package:patient_manager/components/myDropdownInput.dart';
import 'package:patient_manager/components/myErrorMessage.dart';
@@ -50,6 +51,8 @@ class _EditPatientState extends State<EditPatient> {
late double width;
late double height;
final FocusNode _focusNode = FocusNode();
// Future getOfficeIdByUser(String endpoint) async {
// final response = await http.get(Uri.parse(endpoint));
// if (response.statusCode == 200) {
@@ -507,16 +510,7 @@ class _EditPatientState extends State<EditPatient> {
height: 100.0,
child: MyButton(
onTap: () {
if (isFieldsFilled()) {
updatePatientApiCall();
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Input Error");
},
);
}
submitForm();
},
buttonText: "Update",
buttonColor:
@@ -531,6 +525,19 @@ class _EditPatientState extends State<EditPatient> {
);
}
void submitForm() {
if (isFieldsFilled()) {
updatePatientApiCall();
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Input Error");
},
);
}
}
@override
void initState() {
getLoginUserEmail();
@@ -574,7 +581,17 @@ class _EditPatientState extends State<EditPatient> {
return Scaffold(
appBar: const MIHAppBar(barTitle: "Edit Patient"),
body: displayForm(),
body: KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (event) async {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) {
submitForm();
}
},
child: displayForm(),
),
);
}
}