add keyboard click for submit
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:patient_manager/components/myDropdownInput.dart';
|
import 'package:patient_manager/components/myDropdownInput.dart';
|
||||||
import 'package:patient_manager/components/myErrorMessage.dart';
|
import 'package:patient_manager/components/myErrorMessage.dart';
|
||||||
import 'package:patient_manager/components/mySuccessMessage.dart';
|
import 'package:patient_manager/components/mySuccessMessage.dart';
|
||||||
@@ -41,6 +42,7 @@ class _AddPatientState extends State<AddPatient> {
|
|||||||
final baseAPI = AppEnviroment.baseApiUrl;
|
final baseAPI = AppEnviroment.baseApiUrl;
|
||||||
late int futureDocOfficeId;
|
late int futureDocOfficeId;
|
||||||
late bool medRequired;
|
late bool medRequired;
|
||||||
|
final FocusNode _focusNode = FocusNode();
|
||||||
|
|
||||||
bool isFieldsFilled() {
|
bool isFieldsFilled() {
|
||||||
if (medRequired) {
|
if (medRequired) {
|
||||||
@@ -292,16 +294,7 @@ class _AddPatientState extends State<AddPatient> {
|
|||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: MyButton(
|
child: MyButton(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (isFieldsFilled()) {
|
submitForm();
|
||||||
addPatientAPICall();
|
|
||||||
} else {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const MyErrorMessage(errorType: "Input Error");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
buttonText: "Add",
|
buttonText: "Add",
|
||||||
buttonColor:
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
medAidController.addListener(isRequired);
|
medAidController.addListener(isRequired);
|
||||||
@@ -332,7 +338,17 @@ class _AddPatientState extends State<AddPatient> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const MIHAppBar(barTitle: "Add Patient"),
|
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(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:patient_manager/components/mihAppBar.dart';
|
import 'package:patient_manager/components/mihAppBar.dart';
|
||||||
import 'package:patient_manager/components/myDropdownInput.dart';
|
import 'package:patient_manager/components/myDropdownInput.dart';
|
||||||
import 'package:patient_manager/components/myErrorMessage.dart';
|
import 'package:patient_manager/components/myErrorMessage.dart';
|
||||||
@@ -50,6 +51,8 @@ class _EditPatientState extends State<EditPatient> {
|
|||||||
late double width;
|
late double width;
|
||||||
late double height;
|
late double height;
|
||||||
|
|
||||||
|
final FocusNode _focusNode = FocusNode();
|
||||||
|
|
||||||
// Future getOfficeIdByUser(String endpoint) async {
|
// Future getOfficeIdByUser(String endpoint) async {
|
||||||
// final response = await http.get(Uri.parse(endpoint));
|
// final response = await http.get(Uri.parse(endpoint));
|
||||||
// if (response.statusCode == 200) {
|
// if (response.statusCode == 200) {
|
||||||
@@ -507,16 +510,7 @@ class _EditPatientState extends State<EditPatient> {
|
|||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: MyButton(
|
child: MyButton(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (isFieldsFilled()) {
|
submitForm();
|
||||||
updatePatientApiCall();
|
|
||||||
} else {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const MyErrorMessage(errorType: "Input Error");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
buttonText: "Update",
|
buttonText: "Update",
|
||||||
buttonColor:
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
getLoginUserEmail();
|
getLoginUserEmail();
|
||||||
@@ -574,7 +581,17 @@ class _EditPatientState extends State<EditPatient> {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const MIHAppBar(barTitle: "Edit Patient"),
|
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(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user