file upload window enhancement

This commit is contained in:
2024-09-27 12:34:29 +02:00
parent 05a877c6db
commit 7332582628

View File

@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:patient_manager/mih_components/mih_layout/mih_window.dart';
import 'package:patient_manager/mih_packages/patient_profile/builder/build_files_list.dart'; import 'package:patient_manager/mih_packages/patient_profile/builder/build_files_list.dart';
import 'package:patient_manager/mih_components/mih_inputs_and_buttons/mih_file_input.dart'; import 'package:patient_manager/mih_components/mih_inputs_and_buttons/mih_file_input.dart';
import 'package:patient_manager/mih_components/med_cert_input.dart'; import 'package:patient_manager/mih_components/med_cert_input.dart';
@@ -426,109 +427,63 @@ class _PatientFilesState extends State<PatientFiles> {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (context) => Dialog( builder: (context) => MIHWindow(
child: Stack( fullscreen: false,
children: [ windowTitle: "Upload File",
Container( windowTools: const [],
padding: const EdgeInsets.all(10.0), onWindowTapClose: () {
width: 700.0, Navigator.pop(context);
//height: 475.0, },
decoration: BoxDecoration( windowBody: [
color: MzanziInnovationHub.of(context)!.theme.primaryColor(), SizedBox(
borderRadius: BorderRadius.circular(25.0), width: 700,
border: Border.all( child: MIHFileField(
color: controller: selectedFileController,
MzanziInnovationHub.of(context)!.theme.secondaryColor(), hintText: "Select File",
width: 5.0), editable: false,
), required: true,
child: Column( onPressed: () async {
mainAxisSize: MainAxisSize.min, FilePickerResult? result = await FilePicker.platform.pickFiles(
children: [ type: FileType.custom,
Text( allowedExtensions: ['jpg', 'png', 'pdf'],
"Upload File", );
textAlign: TextAlign.center, if (result == null) return;
style: TextStyle( final selectedFile = result.files.first;
color: MzanziInnovationHub.of(context)! setState(() {
.theme selected = selectedFile;
.secondaryColor(), });
fontSize: 35.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25.0),
SizedBox(
width: 700,
child: MIHFileField(
controller: selectedFileController,
hintText: "Select File",
editable: false,
required: true,
onPressed: () async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['jpg', 'png', 'pdf'],
);
if (result == null) return;
final selectedFile = result.files.first;
setState(() {
selected = selectedFile;
});
setState(() { setState(() {
selectedFileController.text = selectedFile.name; selectedFileController.text = selectedFile.name;
}); });
}, },
),
),
const SizedBox(height: 30),
SizedBox(
width: 300,
height: 50,
child: MIHButton(
buttonText: "Add File",
buttonColor: MzanziInnovationHub.of(context)!
.theme
.secondaryColor(),
textColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(),
onTap: () {
if (isFileFieldsFilled()) {
uploadSelectedFile(selected);
Navigator.pop(context);
} else {
showDialog(
context: context,
builder: (context) {
return const MIHErrorMessage(
errorType: "Input Error");
},
);
}
},
),
)
],
),
), ),
Positioned( ),
top: 5, const SizedBox(height: 15),
right: 5, SizedBox(
width: 50, width: 300,
height: 50, height: 50,
child: IconButton( child: MIHButton(
onPressed: () { buttonText: "Add File",
buttonColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
onTap: () {
if (isFileFieldsFilled()) {
uploadSelectedFile(selected);
Navigator.pop(context); Navigator.pop(context);
}, } else {
icon: Icon( showDialog(
Icons.close, context: context,
color: MzanziInnovationHub.of(context)!.theme.errorColor(), builder: (context) {
size: 35, return const MIHErrorMessage(errorType: "Input Error");
), },
), );
}
},
), ),
], )
), ],
), ),
); );
} }