From bffd4ea3238cf3c26a356acbd3e0d8c83b200f21 Mon Sep 17 00:00:00 2001 From: yaso Date: Tue, 17 Sep 2024 13:55:12 +0200 Subject: [PATCH] Use layout Builder for patient profile --- .../builder/buildFilesList.dart | 99 ++++---- .../builder/buildNotesList.dart | 87 +++---- .../patient_profile/patientDetails.dart | 76 +++--- .../patient_profile/patientFiles.dart | 80 ++----- .../patient_profile/patientNotes.dart | 80 ++----- .../patient_profile/patientView.dart | 217 ++++++++++++------ 6 files changed, 287 insertions(+), 352 deletions(-) diff --git a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildFilesList.dart b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildFilesList.dart index 8384e7d0..e13abb19 100644 --- a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildFilesList.dart +++ b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildFilesList.dart @@ -298,68 +298,57 @@ class _BuildFilesListState extends State { @override Widget build(BuildContext context) { - final Size size = MediaQuery.sizeOf(context); - //double width = size.width; - double height = size.height; if (widget.files.isNotEmpty) { - return SizedBox( - height: height - 177, - child: ListView.separated( - shrinkWrap: true, - separatorBuilder: (BuildContext context, int index) { - return Divider( - color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ); - }, - itemCount: widget.files.length, - itemBuilder: (context, index) { - return ListTile( - title: Text( - widget.files[index].file_name, - style: TextStyle( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), - subtitle: Text( - widget.files[index].insert_date, - style: TextStyle( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), - trailing: Icon( - Icons.arrow_forward, + return ListView.separated( + shrinkWrap: true, + separatorBuilder: (BuildContext context, int index) { + return Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ); + }, + itemCount: widget.files.length, + itemBuilder: (context, index) { + return ListTile( + title: Text( + widget.files[index].file_name, + style: TextStyle( color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), ), - onTap: () async { - await getFileUrlApiCall(widget.files[index].file_path) - .then((urlHere) { - //print(url); - setState(() { - fileUrl = urlHere; - }); + ), + subtitle: Text( + widget.files[index].insert_date, + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), + trailing: Icon( + Icons.arrow_forward, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + onTap: () async { + await getFileUrlApiCall(widget.files[index].file_path) + .then((urlHere) { + //print(url); + setState(() { + fileUrl = urlHere; }); + }); - viewFilePopUp( - widget.files[index].file_name, - widget.files[index].file_path, - widget.files[index].idpatient_files, - fileUrl); - }, - ); - }, - ), + viewFilePopUp( + widget.files[index].file_name, + widget.files[index].file_path, + widget.files[index].idpatient_files, + fileUrl); + }, + ); + }, ); } else { - return SizedBox( - height: height - 150, - child: const Center( - child: Text( - "No Documents Available", - style: TextStyle(fontSize: 25, color: Colors.grey), - textAlign: TextAlign.center, - ), + return const Center( + child: Text( + "No Documents Available", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, ), ); } diff --git a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildNotesList.dart b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildNotesList.dart index a203ee89..873b33e4 100644 --- a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildNotesList.dart +++ b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/builder/buildNotesList.dart @@ -275,60 +275,49 @@ class _BuildNotesListState extends State { @override Widget build(BuildContext context) { - final Size size = MediaQuery.sizeOf(context); - //double width = size.width; - double height = size.height; if (widget.notes.isNotEmpty) { - return SizedBox( - height: height - 173, - child: ListView.separated( - shrinkWrap: true, - separatorBuilder: (BuildContext context, int index) { - return Divider( - color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ); - }, - itemCount: widget.notes.length, - itemBuilder: (context, index) { - String notePreview = widget.notes[index].note_text; - if (notePreview.length > 30) { - notePreview = "${notePreview.substring(0, 30)} ..."; - } - return ListTile( - title: Text( - "${widget.notes[index].note_name}\n${widget.notes[index].doc_office} - ${widget.notes[index].doctor}", - style: TextStyle( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), - subtitle: Text( - "${widget.notes[index].insert_date}:\n$notePreview", - style: TextStyle( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), //Text(widget.notes[index].note_text), - trailing: Icon( - Icons.arrow_forward, + return ListView.separated( + shrinkWrap: true, + separatorBuilder: (BuildContext context, int index) { + return Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ); + }, + itemCount: widget.notes.length, + itemBuilder: (context, index) { + String notePreview = widget.notes[index].note_text; + if (notePreview.length > 30) { + notePreview = "${notePreview.substring(0, 30)} ..."; + } + return ListTile( + title: Text( + "${widget.notes[index].note_name}\n${widget.notes[index].doc_office} - ${widget.notes[index].doctor}", + style: TextStyle( color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), ), - onTap: () { - viewNotePopUp(widget.notes[index]); - }, - ); - }, - ), + ), + subtitle: Text( + "${widget.notes[index].insert_date}:\n$notePreview", + style: TextStyle( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + ), //Text(widget.notes[index].note_text), + trailing: Icon( + Icons.arrow_forward, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + onTap: () { + viewNotePopUp(widget.notes[index]); + }, + ); + }, ); } else { - return SizedBox( - height: height - 173, - child: const Center( - child: Text( - "No Notes Available", - style: TextStyle(fontSize: 25, color: Colors.grey), - textAlign: TextAlign.center, - ), + return const Center( + child: Text( + "No Notes Available", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, ), ); } diff --git a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientDetails.dart b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientDetails.dart index 76e461d9..8a5c1619 100644 --- a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientDetails.dart +++ b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientDetails.dart @@ -269,56 +269,34 @@ class _PatientDetailsState extends State { @override Widget build(BuildContext context) { - final Size size = MediaQuery.sizeOf(context); - //double width = size.width; - double height = size.height; - return Container( - alignment: Alignment.topCenter, - height: height - 100, - padding: const EdgeInsets.only(left: 10, right: 10, bottom: 10), - decoration: BoxDecoration( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - borderRadius: BorderRadius.circular(25.0), - border: Border.all( - color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 3.0), - ), - //constraints: const BoxConstraints.expand(height: 250.0), - child: SelectionArea( - child: SingleChildScrollView( - child: Column( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - //crossAxisAlignment: , - children: setIcons(), + return SelectionArea( + child: SingleChildScrollView( + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + //crossAxisAlignment: , + children: setIcons(), + ), + Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10), + getPatientDetailsField(), + const SizedBox(height: 10), + Text( + "Medical Aid Details", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 25, + fontWeight: FontWeight.bold, + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), ), - Divider( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor()), - const SizedBox(height: 10), - getPatientDetailsField(), - const SizedBox(height: 10), - Text( - "Medical Aid Details", - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 25, - fontWeight: FontWeight.bold, - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - ), - ), - Divider( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor()), - const SizedBox(height: 10), - getMedAidDetailsFields(), - ], - ), + ), + Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10), + getMedAidDetailsFields(), + ], ), ), ); diff --git a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientFiles.dart b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientFiles.dart index b7a8de47..4935b323 100644 --- a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientFiles.dart +++ b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientFiles.dart @@ -643,78 +643,34 @@ class _PatientFilesState extends State { @override Widget build(BuildContext context) { - final Size size = MediaQuery.sizeOf(context); - //double width = size.width; - double height = size.height; return FutureBuilder( future: futueFiles, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return Container( - height: height - 100, - decoration: BoxDecoration( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - borderRadius: BorderRadius.circular(25.0), - border: Border.all( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 3.0), - ), - child: const Center( - child: Mihloadingcircle(), - ), + return const Center( + child: Mihloadingcircle(), ); } else if (snapshot.hasData) { final filesList = snapshot.data!; - return Container( - //height: 300.0, - decoration: BoxDecoration( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - borderRadius: BorderRadius.circular(25.0), - border: Border.all( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 3.0), + return Column(children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: setIcons(), ), - child: Padding( - padding: const EdgeInsets.only(top: 5.0), - child: Column(children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: setIcons(), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20.0), - child: Divider( - color: MzanziInnovationHub.of(context)! - .theme - .secondaryColor()), - ), - const SizedBox(height: 10), - BuildFilesList( - files: filesList, - signedInUser: widget.signedInUser, - selectedPatient: widget.selectedPatient, - business: widget.business, - businessUser: widget.businessUser, - ), - ]), + Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10), + BuildFilesList( + files: filesList, + signedInUser: widget.signedInUser, + selectedPatient: widget.selectedPatient, + business: widget.business, + businessUser: widget.businessUser, ), - ); + ]); } else { - return Container( - height: height - 175, - decoration: BoxDecoration( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - borderRadius: BorderRadius.circular(25.0), - border: Border.all( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 3.0), - ), - child: const Center( - child: Text("Error Loading Notes"), - ), + return const Center( + child: Text("Error Loading Notes"), ); } }, diff --git a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientNotes.dart b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientNotes.dart index 064f9985..aff77356 100644 --- a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientNotes.dart +++ b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientNotes.dart @@ -331,78 +331,34 @@ class _PatientNotesState extends State { @override Widget build(BuildContext context) { - final Size size = MediaQuery.sizeOf(context); - //double width = size.width; - double height = size.height; return FutureBuilder( future: futueNotes, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return Container( - height: height - 100, - decoration: BoxDecoration( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - borderRadius: BorderRadius.circular(25.0), - border: Border.all( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 3.0), - ), - child: const Center( - child: Mihloadingcircle(), - ), + return const Center( + child: Mihloadingcircle(), ); } else if (snapshot.hasData) { final notesList = snapshot.data!; - return Container( - //height: 300.0, - decoration: BoxDecoration( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - borderRadius: BorderRadius.circular(25.0), - border: Border.all( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 3.0), + return Column(children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: setIcons(), ), - child: Padding( - padding: const EdgeInsets.only(top: 5.0), - child: Column(children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: setIcons(), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20.0), - child: Divider( - color: MzanziInnovationHub.of(context)! - .theme - .secondaryColor()), - ), - const SizedBox(height: 10), - BuildNotesList( - notes: notesList, - signedInUser: widget.signedInUser, - selectedPatient: widget.selectedPatient, - business: widget.business, - businessUser: widget.businessUser, - ), - ]), + Divider( + color: MzanziInnovationHub.of(context)!.theme.secondaryColor()), + const SizedBox(height: 10), + BuildNotesList( + notes: notesList, + signedInUser: widget.signedInUser, + selectedPatient: widget.selectedPatient, + business: widget.business, + businessUser: widget.businessUser, ), - ); + ]); } else { - return Container( - height: height - 100, - decoration: BoxDecoration( - color: MzanziInnovationHub.of(context)!.theme.primaryColor(), - borderRadius: BorderRadius.circular(25.0), - border: Border.all( - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - width: 3.0), - ), - child: const Center( - child: Text("Error Loading Notes"), - ), + return const Center( + child: Text("Error Loading Notes"), ); } }, diff --git a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientView.dart b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientView.dart index 68869fc9..903c1e91 100644 --- a/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientView.dart +++ b/Frontend/patient_manager/lib/MIH_Packages/patient_profile/patientView.dart @@ -4,6 +4,10 @@ import 'package:flutter/material.dart'; import 'package:patient_manager/MIH_Packages/patient_profile/patientDetails.dart'; import 'package:patient_manager/MIH_Packages/patient_profile/patientFiles.dart'; import 'package:patient_manager/MIH_Packages/patient_profile/patientNotes.dart'; +import 'package:patient_manager/components/MIH_Layout/MIH_Action.dart'; +import 'package:patient_manager/components/MIH_Layout/MIH_Body.dart'; +import 'package:patient_manager/components/MIH_Layout/MIH_Header.dart'; +import 'package:patient_manager/components/MIH_Layout/MIH_LayoutBuilder.dart'; import 'package:patient_manager/env/env.dart'; import 'package:patient_manager/main.dart'; import 'package:patient_manager/objects/arguments.dart'; @@ -100,6 +104,64 @@ class _PatientViewState extends State { } } + MIHAction getActionButton() { + return MIHAction( + icon: Icons.arrow_back, + iconSize: 35, + onTap: () { + Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false); + }, + ); + } + + MIHHeader getHeader() { + return MIHHeader( + headerAlignment: MainAxisAlignment.end, + headerItems: [ + IconButton( + onPressed: () { + setState(() { + _selectedIndex = 0; + }); + }, + icon: const Icon( + Icons.perm_identity, + size: 35, + ), + ), + IconButton( + onPressed: () { + setState(() { + _selectedIndex = 1; + }); + }, + icon: const Icon( + Icons.article_outlined, + size: 35, + ), + ), + IconButton( + onPressed: () { + setState(() { + _selectedIndex = 2; + }); + }, + icon: const Icon( + Icons.file_present, + size: 35, + ), + ), + ], + ); + } + + MIHBody getBody() { + return MIHBody( + borderOn: true, + bodyItems: [showSelection(_selectedIndex)], + ); + } + @override void dispose() { // TODO: implement dispose @@ -114,81 +176,86 @@ class _PatientViewState extends State { height = size.height; }); checkScreenSize(); - return Scaffold( - body: SafeArea( - child: SingleChildScrollView( - child: Stack( - children: [ - Container( - width: width, - height: height, - padding: const EdgeInsets.symmetric( - vertical: 10.0, horizontal: 15.0), - child: Column( - mainAxisSize: MainAxisSize.max, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - IconButton( - onPressed: () { - setState(() { - _selectedIndex = 0; - }); - }, - icon: const Icon( - Icons.perm_identity, - size: 35, - ), - ), - IconButton( - onPressed: () { - setState(() { - _selectedIndex = 1; - }); - }, - icon: const Icon( - Icons.article_outlined, - size: 35, - ), - ), - IconButton( - onPressed: () { - setState(() { - _selectedIndex = 2; - }); - }, - icon: const Icon( - Icons.file_present, - size: 35, - ), - ), - ], - ), - const SizedBox( - height: 10.0, - ), - showSelection(_selectedIndex), - ], - ), - ), - Positioned( - top: 10, - left: 5, - width: 50, - height: 50, - child: IconButton( - onPressed: () { - Navigator.of(context).pop(); - }, - icon: const Icon(Icons.arrow_back), - ), - ) - ], - ), - ), - ), + return MIHLayoutBuilder( + actionButton: getActionButton(), + header: getHeader(), + body: getBody(), ); + // return Scaffold( + // body: SafeArea( + // child: SingleChildScrollView( + // child: Stack( + // children: [ + // Container( + // width: width, + // height: height, + // padding: const EdgeInsets.symmetric( + // vertical: 10.0, horizontal: 15.0), + // child: Column( + // mainAxisSize: MainAxisSize.max, + // children: [ + // Row( + // crossAxisAlignment: CrossAxisAlignment.end, + // mainAxisAlignment: MainAxisAlignment.end, + // children: [ + // IconButton( + // onPressed: () { + // setState(() { + // _selectedIndex = 0; + // }); + // }, + // icon: const Icon( + // Icons.perm_identity, + // size: 35, + // ), + // ), + // IconButton( + // onPressed: () { + // setState(() { + // _selectedIndex = 1; + // }); + // }, + // icon: const Icon( + // Icons.article_outlined, + // size: 35, + // ), + // ), + // IconButton( + // onPressed: () { + // setState(() { + // _selectedIndex = 2; + // }); + // }, + // icon: const Icon( + // Icons.file_present, + // size: 35, + // ), + // ), + // ], + // ), + // const SizedBox( + // height: 10.0, + // ), + // showSelection(_selectedIndex), + // ], + // ), + // ), + // Positioned( + // top: 10, + // left: 5, + // width: 50, + // height: 50, + // child: IconButton( + // onPressed: () { + // Navigator.of(context).pop(); + // }, + // icon: const Icon(Icons.arrow_back), + // ), + // ) + // ], + // ), + // ), + // ), + // ); } }