add UX to add a file, any file.

This commit is contained in:
2024-06-27 16:13:24 +02:00
parent 2466636727
commit 7a86144819
25 changed files with 231 additions and 62 deletions
@@ -45,16 +45,17 @@ class _BuildFilesListState extends State<BuildFilesList> {
IconButton( IconButton(
onPressed: () { onPressed: () {
js.context.callMethod('open', [ 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( content: BuildPDFView(
pdfLink: pdfLink:
"http://localhost:9000/mih/${widget.files[index].file_name}.pdf"), "http://localhost:9000/mih/${widget.files[index].file_name}"),
actions: [ actions: [
TextButton( TextButton(
onPressed: () { onPressed: () {
@@ -1,9 +1,13 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:patient_manager/components/buildFilesList.dart'; import 'package:patient_manager/components/buildFilesList.dart';
import 'package:patient_manager/components/medCertInput.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/main.dart';
import 'package:patient_manager/objects/AppUser.dart'; import 'package:patient_manager/objects/AppUser.dart';
import 'package:patient_manager/objects/files.dart'; import 'package:patient_manager/objects/files.dart';
@@ -28,15 +32,19 @@ class PatientFiles extends StatefulWidget {
class _PatientFilesState extends State<PatientFiles> { class _PatientFilesState extends State<PatientFiles> {
String endpointFiles = "http://localhost:80/files/patients/"; String endpointFiles = "http://localhost:80/files/patients/";
String endpointUser = "http://localhost:80/docOffices/user/"; 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/"; String endpointInsertFiles = "http://localhost:80/files/insert/";
final startDateController = TextEditingController(); final startDateController = TextEditingController();
final endDateTextController = TextEditingController(); final endDateTextController = TextEditingController();
final retDateTextController = TextEditingController(); final retDateTextController = TextEditingController();
final selectedFileController = TextEditingController();
late Future<List<PFile>> futueFiles; late Future<List<PFile>> futueFiles;
late String userEmail = ""; late String userEmail = "";
late AppUser appUser; late AppUser appUser;
late PlatformFile selected;
Future<void> generateMedCert() async { Future<void> generateMedCert() async {
var response1 = await http.post( var response1 = await http.post(
@@ -53,9 +61,9 @@ class _PatientFilesState extends State<PatientFiles> {
"returnDate": retDateTextController.text, "returnDate": retDateTextController.text,
}), }),
); );
print(response1.statusCode); //print(response1.statusCode);
String fileName = 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) { if (response1.statusCode == 200) {
var response2 = await http.post( var response2 = await http.post(
Uri.parse(endpointInsertFiles), Uri.parse(endpointInsertFiles),
@@ -71,6 +79,46 @@ class _PatientFilesState extends State<PatientFiles> {
print(response2.statusCode); print(response2.statusCode);
if (response2.statusCode == 201) { if (response2.statusCode == 201) {
setState(() { 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 = futueFiles =
fetchFiles(endpointFiles + widget.patientIndex.toString()); 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 @override
void initState() { void initState() {
futueFiles = fetchFiles(endpointFiles + widget.patientIndex.toString()); futueFiles = fetchFiles(endpointFiles + widget.patientIndex.toString());
@@ -178,51 +330,19 @@ class _PatientFilesState extends State<PatientFiles> {
), ),
IconButton( IconButton(
onPressed: () { onPressed: () {
showDialog( medCertPopUp();
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"),
)
],
),
);
}, },
icon: const Icon(Icons.sick_outlined), icon: const Icon(Icons.sick_outlined),
), ),
IconButton( IconButton(
onPressed: () {}, onPressed: () {},
icon: const Icon(Icons.medication_outlined), icon: const Icon(Icons.medication_outlined),
),
IconButton(
onPressed: () {
uploudFilePopUp();
},
icon: const Icon(Icons.add),
) )
], ],
), ),
+50 -2
View File
@@ -21,10 +21,34 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: app_links name: app_links
sha256: "96e677810b83707ff5e10fac11e4839daa0ea4e0123c35864c092699165eb3db" sha256: a9905d6a60e814503fabc7523a9ed161b812d7ca69c99ad8ceea14279dc4f06b
url: "https://pub.dev" url: "https://pub.dev"
source: hosted 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: archive:
dependency: transitive dependency: transitive
description: description:
@@ -201,6 +225,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.1.1" 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: crypto:
dependency: transitive dependency: transitive
description: description:
@@ -273,6 +305,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "7.0.0" 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: fixnum:
dependency: transitive dependency: transitive
description: description:
@@ -294,6 +334,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.3" 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: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
+1 -1
View File
@@ -36,7 +36,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
syncfusion_flutter_pdfviewer: ^26.1.39 syncfusion_flutter_pdfviewer: ^26.1.39
#pdfx: ^2.6.0 file_picker: ^8.0.5
supabase_auth_ui: ^0.4.1 supabase_auth_ui: ^0.4.1
supabase_flutter: ^2.4.0 supabase_flutter: ^2.4.0
http: ^1.2.1 http: ^1.2.1
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+13 -13
View File
@@ -17,17 +17,17 @@ endobj
endobj endobj
4 0 obj 4 0 obj
<< <<
/BitsPerComponent 8 /ColorSpace /DeviceRGB /Filter [ /ASCII85Decode /FlateDecode ] /Height 100 /Length 1159 /Subtype /Image /BitsPerComponent 8 /ColorSpace /DeviceRGB /Filter [ /ASCII85Decode /FlateDecode ] /Height 100 /Length 1025 /Subtype /Image
/Type /XObject /Width 100 /Type /XObject /Width 100
>> >>
stream stream
Gb"/_bB>0d#Qs8iIlaoS>>g$#PERgSD:#&l^1I`DY;Jot\t#.j0$s?sls]6>ZVk+l8SkY[O(Ct`N*XX<AK.V'eZaZ&^>jB><Dut2!=mUVAUSc32lsOF'is0;Y'JpBo6"!^M8$kW?>]FlQ1qu/WZ&mh`:2WdqB#%4qnm/a\(r-,>J'::$554?nb$2TqtG:.R(q-p=Rj*TPon*4E;t!&]tPl'_i!?cNR^NhRDsGX:$JkMhpCoE$nFMkN0VNf42UrO*DEkq<8gJc;*X?1\l\Y+#-0>/(c!/PZm?aC-+^-<?GS.mYJZC<C0::nYY3c,JoKXn48/BPW`D!Z$GqAWmF^12W`mr[.L69N[pqW4I@'0#f&4*"?1h4'%6-hL6\&tAgpa6Y.Tu4L7cciHk;qJ/'\18ghUf/&rN4/F)HKpAq5[N6[o3Ya]NVqmcms/^iuUp)2AO68Go)a3jFQhnj/_]d.Z@a+/h/Hp"65Y5qMss)[jq,obU10c_[J%/k0Q7HLC>Dqa*Z<eZ+UOp**->9SZGHC]MpQUU$R'ka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aBhc9'%Q0j\#QG\+kS&MGOFlg.fYm@]KMjSEG!oV;*/bEl+h+Ij9%lASp%$j0eXMS&d@<\_&Oi^6Hs_gSVfmND_96`-s[]TX'M,m)&Zl'.%I1M-.DPa2*JXAp)>c0o*-Bac:Lh3Sl6QPJBk<q(73Am-94F'g,/oHD,XiiF2XTjD5rBss/X>'>Z,Wg+<#HO6aB*W>rjrFX_sg1cMnYHm0&hT6+nm_kl\O"maVn"YoXpYTJn=0WZd]H9V:)r4$_[2mqe(#PA.@R&$)Pp!tO$GKs^m<kr,PSKgrij3,->PPSP0#g_k0pVdKNihYSb=[Wd/nTK%?L!o'3\!?F>?8dm=ac*k(K]R@=W^,hYMi/dJ*b@YX@t`/qZn_6!\:<*?:Xf\L,"2E<E?aK1`?f[h5SAAN8_Z:M]to!nTbj"mh4H)W^Z5Z2ZHY9;*'(hap'YgeN6q0bbi#0EsOl+LsDpPh+p,LIFS)CXLu.XO/(KYG>i7P1QCS`QW72Uiq`GCAu0Uj0kWH\<04eB=d>9PpjZGc]lNZ!YGHEDi04ruaNBQAK8?E!]F35Wf(%_tPZ:jP)Tp?$'_gSFIJaQcf'u_2ZASKiF[s2fS:BDLGdd~>endstream
endobj endobj
5 0 obj 5 0 obj
<< <<
/Contents 9 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 8 0 R /Resources << /Contents 9 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 8 0 R /Resources <<
/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /XObject << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /XObject <<
/FormXob.a864f8048b8deb389d345068e0f01419 4 0 R /FormXob.cd283a2c1d6ad3d76ad89881508b17eb 4 0 R
>> >>
>> /Rotate 0 /Trans << >> /Rotate 0 /Trans <<
@@ -42,7 +42,7 @@ endobj
endobj endobj
7 0 obj 7 0 obj
<< <<
/Author (anonymous) /CreationDate (D:20240626135150+00'00') /Creator (ReportLab PDF Library - www.reportlab.com) /Keywords () /ModDate (D:20240626135150+00'00') /Producer (ReportLab PDF Library - www.reportlab.com) /Author (anonymous) /CreationDate (D:20240627140120+00'00') /Creator (ReportLab PDF Library - www.reportlab.com) /Keywords () /ModDate (D:20240627140120+00'00') /Producer (ReportLab PDF Library - www.reportlab.com)
/Subject (unspecified) /Title (untitled) /Trapped /False /Subject (unspecified) /Title (untitled) /Trapped /False
>> >>
endobj endobj
@@ -53,10 +53,10 @@ endobj
endobj endobj
9 0 obj 9 0 obj
<< <<
/Filter [ /ASCII85Decode /FlateDecode ] /Length 447 /Filter [ /ASCII85Decode /FlateDecode ] /Length 446
>> >>
stream stream
Gas2F5uWCi&;BTNMK`$4$:u.L33$hnc<)*(%XOo^/..6^e5$%W5[,1CVaCXiS,M3u>pr6bdI*T,^l:`9VP">Q#N\.)]Z3QhB>2h8K#aS2#%<0N9RS'n!EnB576M:V(h*=Tnf@;dQc?g394K>ON0,-=405F(MDQc%X(kl"c.8n)k]r(060+JuMdhNT=bF(kDI=9;`U!3`DY/JD85?BaQ<5W51#HC6gkHlZ!Me&.eWgsHIuUsiOWuh__/,fKad(-ZgBo=Z.\1!blAo>@/rV6Af;<T@=FG>tRo>#9b>hU,[mO8fOm`79?5I10>1loX%i#M!KXr#VAokQ,DS8$5-"]Y.ICH+lNu[5I7g[kG1s[M*mO+K)?8+9[oj['4+sNTd_SobjC>KbHf&n35KH`Ej&n29/pU'sKB\6$_S=DBHNi-$KkdH3&WbuG8\:XGWllN`.~>endstream Gas2F>>rBm&;B$=/'anN6V0U_4K?3TN9D[8d)S%=V:m8"Jdh\9["(PTR!-p$mXF>02\a2:Zs,s.gi2m5'U4.bTRe28hdamD1]Q\L&I_%!`F4FE8GseO-K$a6=PP,uNtE.4K"lqFrR)N"Bkco:M_VMI"V,;po2;A!DIm>#_S-q6$pAM`,`#]HHr2M)DkeI:jp#F[)SBD&n&>m*NVO:SFGZiY$J>WYk;MtB%;:H=>M]!^s0!#90QI;oZ9M^;<cY$od^6lj0iI+8lfOtW'FV#n'TK792HHGUU<P0QW)e2Ch@AN*N:c&CoX_+R1t&HDFkD89&Toh.XUaQt](P'1<gXun%,@Gc4`ZWk*[P?$@\:)bmO'N"Y<UE/rLu)Tj=D1E9[Gmoo0FGPeYXTK,Y:I8R:2o)Vu?.Z@5mH3jI@Z?4O$<pg(o.\`m34V"n)[R`Oc'~>endstream
endobj endobj
xref xref
0 10 0 10
@@ -65,15 +65,15 @@ xref
0000000114 00000 n 0000000114 00000 n
0000000221 00000 n 0000000221 00000 n
0000000333 00000 n 0000000333 00000 n
0000001683 00000 n 0000001549 00000 n
0000001949 00000 n 0000001815 00000 n
0000002017 00000 n 0000001883 00000 n
0000002313 00000 n 0000002179 00000 n
0000002372 00000 n 0000002238 00000 n
trailer trailer
<< <<
/ID /ID
[<36b4836a753ad82170aa5ba05dd47b32><36b4836a753ad82170aa5ba05dd47b32>] [<712dd983c575d0108ff950f2c16588c6><712dd983c575d0108ff950f2c16588c6>]
% ReportLab generated PDF document -- digest (http://www.reportlab.com) % ReportLab generated PDF document -- digest (http://www.reportlab.com)
/Info 7 0 R /Info 7 0 R
@@ -81,5 +81,5 @@ trailer
/Size 10 /Size 10
>> >>
startxref startxref
2909 2774
%%EOF %%EOF