forked from yaso_meth/mih-project
add UX to add a file, any file.
This commit is contained in:
@@ -45,16 +45,17 @@ class _BuildFilesListState extends State<BuildFilesList> {
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
js.context.callMethod('open', [
|
||||
'http://localhost:9000/mih/${widget.files[index].file_name}.pdf'
|
||||
'http://localhost:9000/mih/${widget.files[index].file_name}'
|
||||
]);
|
||||
//print(object)
|
||||
},
|
||||
icon: Icon(Icons.download),
|
||||
)
|
||||
icon: const Icon(Icons.download),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: BuildPDFView(
|
||||
pdfLink:
|
||||
"http://localhost:9000/mih/${widget.files[index].file_name}.pdf"),
|
||||
"http://localhost:9000/mih/${widget.files[index].file_name}"),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/buildFilesList.dart';
|
||||
import 'package:patient_manager/components/medCertInput.dart';
|
||||
import 'package:patient_manager/components/myTextInput.dart';
|
||||
import 'package:patient_manager/components/mybutton.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:patient_manager/objects/AppUser.dart';
|
||||
import 'package:patient_manager/objects/files.dart';
|
||||
@@ -28,15 +32,19 @@ class PatientFiles extends StatefulWidget {
|
||||
class _PatientFilesState extends State<PatientFiles> {
|
||||
String endpointFiles = "http://localhost:80/files/patients/";
|
||||
String endpointUser = "http://localhost:80/docOffices/user/";
|
||||
String endpointGenFiles = "http://localhost:80/files/generate/";
|
||||
String endpointGenFiles = "http://localhost:80/files/generate/med-cert/";
|
||||
String endpointFileUpload = "http://localhost:80/files/upload/file/";
|
||||
String endpointInsertFiles = "http://localhost:80/files/insert/";
|
||||
|
||||
final startDateController = TextEditingController();
|
||||
final endDateTextController = TextEditingController();
|
||||
final retDateTextController = TextEditingController();
|
||||
final selectedFileController = TextEditingController();
|
||||
|
||||
late Future<List<PFile>> futueFiles;
|
||||
late String userEmail = "";
|
||||
late AppUser appUser;
|
||||
late PlatformFile selected;
|
||||
|
||||
Future<void> generateMedCert() async {
|
||||
var response1 = await http.post(
|
||||
@@ -53,9 +61,9 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
"returnDate": retDateTextController.text,
|
||||
}),
|
||||
);
|
||||
print(response1.statusCode);
|
||||
//print(response1.statusCode);
|
||||
String fileName =
|
||||
"Med-Cert-${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}-${startDateController.text}";
|
||||
"Med-Cert-${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}-${startDateController.text}.pdf";
|
||||
if (response1.statusCode == 200) {
|
||||
var response2 = await http.post(
|
||||
Uri.parse(endpointInsertFiles),
|
||||
@@ -71,6 +79,46 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
print(response2.statusCode);
|
||||
if (response2.statusCode == 201) {
|
||||
setState(() {
|
||||
startDateController.clear();
|
||||
endDateTextController.clear();
|
||||
retDateTextController.clear();
|
||||
futueFiles =
|
||||
fetchFiles(endpointFiles + widget.patientIndex.toString());
|
||||
});
|
||||
String message = "Successfully added file";
|
||||
messagePopUp(message);
|
||||
} else {
|
||||
messagePopUp("error response 2");
|
||||
}
|
||||
} else {
|
||||
messagePopUp("error respose 1");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> uploadSelectedFile(PlatformFile file) async {
|
||||
//var strem = new http.ByteStream.fromBytes(file.bytes.)
|
||||
var request = http.MultipartRequest('POST', Uri.parse(endpointFileUpload));
|
||||
request.headers['Content-Type'] = 'multipart/form-data';
|
||||
request.files.add(await http.MultipartFile.fromBytes('file', file.bytes!,
|
||||
filename: file.name.replaceAll(RegExp(r' '), '-')));
|
||||
var response1 = await request.send();
|
||||
print(response1.statusCode);
|
||||
if (response1.statusCode == 200) {
|
||||
var response2 = await http.post(
|
||||
Uri.parse(endpointInsertFiles),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"file_path": file.name.replaceAll(RegExp(r' '), '-'),
|
||||
"file_name": file.name.replaceAll(RegExp(r' '), '-'),
|
||||
"patient_id": widget.patientIndex
|
||||
}),
|
||||
);
|
||||
print(response2.statusCode);
|
||||
if (response2.statusCode == 201) {
|
||||
setState(() {
|
||||
selectedFileController.clear();
|
||||
futueFiles =
|
||||
fetchFiles(endpointFiles + widget.patientIndex.toString());
|
||||
});
|
||||
@@ -131,6 +179,110 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
);
|
||||
}
|
||||
|
||||
void medCertPopUp() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Create Medical Certificate"),
|
||||
],
|
||||
),
|
||||
content: Medcertinput(
|
||||
startDateController: startDateController,
|
||||
endDateTextController: endDateTextController,
|
||||
retDateTextController: retDateTextController,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
generateMedCert();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text(
|
||||
"Generate",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Cancel"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void uploudFilePopUp() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Upload File"),
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
width: 700,
|
||||
height: 250,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: MyButton(
|
||||
onTap: () async {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles();
|
||||
if (result == null) return;
|
||||
final selectedFile = result.files.first;
|
||||
//selectedFile
|
||||
// print("Name: ${selectedFile.name}");
|
||||
// print("Extension: ${selectedFile.extension}");
|
||||
// print("Content: ${selectedFile.bytes}");
|
||||
|
||||
setState(() {
|
||||
selected = selectedFile;
|
||||
});
|
||||
|
||||
setState(() {
|
||||
selectedFileController.text = selectedFile.name;
|
||||
});
|
||||
},
|
||||
buttonText: "Select File"),
|
||||
),
|
||||
MyTextField(
|
||||
controller: selectedFileController,
|
||||
hintText: "Selected FIle",
|
||||
editable: false)
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
uploadSelectedFile(selected);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text(
|
||||
"Upload",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Cancel"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
futueFiles = fetchFiles(endpointFiles + widget.patientIndex.toString());
|
||||
@@ -178,51 +330,19 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Create Medical Certificate"),
|
||||
],
|
||||
),
|
||||
content: Medcertinput(
|
||||
startDateController: startDateController,
|
||||
endDateTextController:
|
||||
endDateTextController,
|
||||
retDateTextController:
|
||||
retDateTextController,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
//getPatientDetails();
|
||||
generateMedCert();
|
||||
Navigator.pop(context);
|
||||
//print(widget.patientIndex);
|
||||
},
|
||||
child: const Text(
|
||||
"Generate",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Cancel"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
medCertPopUp();
|
||||
},
|
||||
icon: const Icon(Icons.sick_outlined),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.medication_outlined),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
uploudFilePopUp();
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
@@ -21,10 +21,34 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: app_links
|
||||
sha256: "96e677810b83707ff5e10fac11e4839daa0ea4e0123c35864c092699165eb3db"
|
||||
sha256: a9905d6a60e814503fabc7523a9ed161b812d7ca69c99ad8ceea14279dc4f06b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.1"
|
||||
version: "6.1.3"
|
||||
app_links_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: app_links_linux
|
||||
sha256: "567139eca3ca9fb113f2082f3aaa75a26f30f0ebdbe5fa7f09a3913c5bebd630"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
app_links_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: app_links_platform_interface
|
||||
sha256: "58cff6f11df59b0e514dd5e4a61e988348ad5662f0e75d45d4e214ebea55c94c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
app_links_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: app_links_web
|
||||
sha256: "74586ed5f3c4786341e82a0fa43c39ec3f13108a550f74e80d8bf68aa11349d1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
archive:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -201,6 +225,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
cross_file:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: cross_file
|
||||
sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.4+1"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -273,6 +305,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.0.0"
|
||||
file_picker:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: file_picker
|
||||
sha256: "2ca051989f69d1b2ca012b2cf3ccf78c70d40144f0861ff2c063493f7c8c3d45"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.0.5"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -294,6 +334,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_plugin_android_lifecycle
|
||||
sha256: c6b0b4c05c458e1c01ad9bcc14041dd7b1f6783d487be4386f793f47a8a4d03e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.20"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
||||
@@ -36,7 +36,7 @@ dependencies:
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.2
|
||||
syncfusion_flutter_pdfviewer: ^26.1.39
|
||||
#pdfx: ^2.6.0
|
||||
file_picker: ^8.0.5
|
||||
supabase_auth_ui: ^0.4.1
|
||||
supabase_flutter: ^2.4.0
|
||||
http: ^1.2.1
|
||||
|
||||
Reference in New Issue
Block a user