add text form field to file upload
This commit is contained in:
@@ -2,14 +2,17 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_apis/mih_alert_services.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_apis/mih_file_api.dart';
|
import 'package:mzansi_innovation_hub/mih_apis/mih_file_api.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_apis/mih_validation_services.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/med_cert_input.dart';
|
import 'package:mzansi_innovation_hub/mih_components/med_cert_input.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_file_input.dart';
|
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_form.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_floating_menu.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_floating_menu.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_window.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_window.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart';
|
||||||
@@ -60,6 +63,7 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
final noRepeatsController = TextEditingController();
|
final noRepeatsController = TextEditingController();
|
||||||
final outputController = TextEditingController();
|
final outputController = TextEditingController();
|
||||||
late PlatformFile? selected;
|
late PlatformFile? selected;
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
late String env;
|
late String env;
|
||||||
|
|
||||||
Future<void> submitDocUploadForm() async {
|
Future<void> submitDocUploadForm() async {
|
||||||
@@ -217,7 +221,7 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void uploudFilePopUp() {
|
void uploudFilePopUp(double width) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@@ -227,59 +231,100 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
onWindowTapClose: () {
|
onWindowTapClose: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
windowBody: Column(
|
windowBody: Padding(
|
||||||
children: [
|
padding:
|
||||||
MIHFileField(
|
MzanziInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||||
controller: selectedFileController,
|
? EdgeInsets.symmetric(horizontal: width * 0.05)
|
||||||
hintText: "Select File",
|
: const EdgeInsets.symmetric(horizontal: 0),
|
||||||
editable: false,
|
child: Column(
|
||||||
required: true,
|
children: [
|
||||||
onPressed: () async {
|
MihForm(
|
||||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
formKey: _formKey,
|
||||||
type: FileType.custom,
|
formFields: [
|
||||||
allowedExtensions: ['jpg', 'png', 'pdf'],
|
Row(
|
||||||
withData: true,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
);
|
children: [
|
||||||
if (result == null) return;
|
Expanded(
|
||||||
final selectedFile = result.files.first;
|
child: MihTextFormField(
|
||||||
print("Selected file: $selectedFile");
|
fillColor: MzanziInnovationHub.of(context)!
|
||||||
setState(() {
|
.theme
|
||||||
selected = selectedFile;
|
.secondaryColor(),
|
||||||
});
|
inputColor: MzanziInnovationHub.of(context)!
|
||||||
setState(() {
|
.theme
|
||||||
selectedFileController.text = selectedFile.name;
|
.primaryColor(),
|
||||||
});
|
controller: selectedFileController,
|
||||||
},
|
hintText: "Selected File",
|
||||||
),
|
requiredText: true,
|
||||||
const SizedBox(height: 15),
|
readOnly: true,
|
||||||
MihButton(
|
validator: (value) {
|
||||||
onPressed: () {
|
return MihValidationServices().isEmpty(value);
|
||||||
if (isFileFieldsFilled()) {
|
},
|
||||||
submitDocUploadForm();
|
),
|
||||||
// uploadSelectedFile(selected);
|
),
|
||||||
Navigator.pop(context);
|
const SizedBox(width: 10),
|
||||||
} else {
|
MihButton(
|
||||||
showDialog(
|
onPressed: () async {
|
||||||
context: context,
|
FilePickerResult? result =
|
||||||
builder: (context) {
|
await FilePicker.platform.pickFiles(
|
||||||
return const MIHErrorMessage(errorType: "Input Error");
|
type: FileType.custom,
|
||||||
|
allowedExtensions: ['jpg', 'png', 'pdf'],
|
||||||
|
withData: true,
|
||||||
|
);
|
||||||
|
if (result == null) return;
|
||||||
|
final selectedFile = result.files.first;
|
||||||
|
print("Selected file: $selectedFile");
|
||||||
|
setState(() {
|
||||||
|
selected = selectedFile;
|
||||||
|
});
|
||||||
|
setState(() {
|
||||||
|
selectedFileController.text = selectedFile.name;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
child: Text(
|
||||||
|
"Attach",
|
||||||
|
style: TextStyle(
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
MihButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
|
submitDocUploadForm();
|
||||||
|
// uploadSelectedFile(selected);
|
||||||
|
Navigator.pop(context);
|
||||||
|
} else {
|
||||||
|
MihAlertServices().formNotFilledCompletely(context);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
buttonColor:
|
||||||
}
|
MzanziInnovationHub.of(context)!.theme.successColor(),
|
||||||
},
|
width: 300,
|
||||||
buttonColor:
|
child: Text(
|
||||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
"Add File",
|
||||||
width: 300,
|
style: TextStyle(
|
||||||
child: Text(
|
color: MzanziInnovationHub.of(context)!
|
||||||
"Add File",
|
.theme
|
||||||
style: TextStyle(
|
.primaryColor(),
|
||||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
fontSize: 20,
|
||||||
fontSize: 20,
|
fontWeight: FontWeight.bold,
|
||||||
fontWeight: FontWeight.bold,
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -391,7 +436,7 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getMenu() {
|
Widget getMenu(double width) {
|
||||||
if (widget.type == "personal") {
|
if (widget.type == "personal") {
|
||||||
return Positioned(
|
return Positioned(
|
||||||
right: 10,
|
right: 10,
|
||||||
@@ -415,7 +460,7 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
backgroundColor:
|
backgroundColor:
|
||||||
MzanziInnovationHub.of(context)!.theme.successColor(),
|
MzanziInnovationHub.of(context)!.theme.successColor(),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
uploudFilePopUp();
|
uploudFilePopUp(width);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -444,7 +489,7 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
backgroundColor:
|
backgroundColor:
|
||||||
MzanziInnovationHub.of(context)!.theme.successColor(),
|
MzanziInnovationHub.of(context)!.theme.successColor(),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
uploudFilePopUp();
|
uploudFilePopUp(width);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
@@ -489,70 +534,6 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> setIcons() {
|
|
||||||
if (widget.type == "personal") {
|
|
||||||
return [
|
|
||||||
Text(
|
|
||||||
"Documents",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 25,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
uploudFilePopUp();
|
|
||||||
},
|
|
||||||
icon: Icon(
|
|
||||||
Icons.add,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
return [
|
|
||||||
Text(
|
|
||||||
"Documents",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 25,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
medCertPopUp();
|
|
||||||
},
|
|
||||||
icon: Icon(
|
|
||||||
Icons.sick_outlined,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
prescritionPopUp();
|
|
||||||
},
|
|
||||||
icon: Icon(
|
|
||||||
Icons.medication_outlined,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
uploudFilePopUp();
|
|
||||||
},
|
|
||||||
icon: Icon(
|
|
||||||
Icons.add,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void successPopUp(String message) {
|
void successPopUp(String message) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -603,13 +584,14 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
double screenWidth = MediaQuery.of(context).size.width;
|
||||||
return MihPackageToolBody(
|
return MihPackageToolBody(
|
||||||
borderOn: false,
|
borderOn: false,
|
||||||
bodyItem: getBody(),
|
bodyItem: getBody(screenWidth),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getBody() {
|
Widget getBody(double width) {
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
MihSingleChildScroll(
|
MihSingleChildScroll(
|
||||||
@@ -641,7 +623,7 @@ class _PatientDocumentsState extends State<PatientDocuments> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
getMenu(),
|
getMenu(width),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user