From 845c8a6688ceec3737e08acc34e914af16bfeabf Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Tue, 22 Jul 2025 10:41:59 +0200 Subject: [PATCH] give window a read only mode --- .../mih_review_business_window.dart | 123 ++++++++++-------- 1 file changed, 72 insertions(+), 51 deletions(-) diff --git a/Frontend/lib/mih_packages/mzansi_profile/business_profile/components/mih_review_business_window.dart b/Frontend/lib/mih_packages/mzansi_profile/business_profile/components/mih_review_business_window.dart index 977f0916..9c12e472 100644 --- a/Frontend/lib/mih_packages/mzansi_profile/business_profile/components/mih_review_business_window.dart +++ b/Frontend/lib/mih_packages/mzansi_profile/business_profile/components/mih_review_business_window.dart @@ -20,11 +20,13 @@ class MihReviewBusinessWindow extends StatefulWidget { final Business business; final BusinessReview? businessReview; final double screenWidth; + final bool readOnly; const MihReviewBusinessWindow({ super.key, required this.business, required this.businessReview, required this.screenWidth, + required this.readOnly, }); @override @@ -205,6 +207,16 @@ class _MihReviewBusinessWindowState extends State { } } + String getWindowTitle() { + if (widget.readOnly) { + return "Review Details"; + } else if (widget.businessReview != null) { + return "Edit Review"; + } else { + return "Add Review"; + } + } + @override void dispose() { super.dispose(); @@ -240,11 +252,11 @@ class _MihReviewBusinessWindowState extends State { // return const Placeholder(); return MihPackageWindow( fullscreen: false, - windowTitle: widget.businessReview != null ? "Edit Review" : "Add Review", + windowTitle: getWindowTitle(), onWindowTapClose: () { Navigator.of(context).pop(); }, - menuOptions: widget.businessReview != null + menuOptions: widget.businessReview != null && !widget.readOnly ? [ SpeedDialChild( child: Icon( @@ -331,6 +343,7 @@ class _MihReviewBusinessWindowState extends State { controller: _reviewTitleController, multiLineInput: false, requiredText: true, + readOnly: widget.readOnly, hintText: "Review Title", validator: (value) { return MihValidationServices() @@ -346,7 +359,8 @@ class _MihReviewBusinessWindowState extends State { MzansiInnovationHub.of(context)!.theme.primaryColor(), controller: _reviewDescriptionController, multiLineInput: true, - requiredText: false, + requiredText: widget.readOnly, + readOnly: widget.readOnly, hintText: "Review Description", validator: (value) { if (_reviewDescriptionController.text.isEmpty) { @@ -357,59 +371,66 @@ class _MihReviewBusinessWindowState extends State { } }, ), - SizedBox( - height: 15, - child: ValueListenableBuilder( - valueListenable: _counter, - builder: - (BuildContext context, int value, Widget? child) { - return Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Text( - "$value", - style: TextStyle( - color: getMissionVisionLimitColor(256), - fontWeight: FontWeight.bold, + Visibility( + visible: !widget.readOnly, + child: SizedBox( + height: 15, + child: ValueListenableBuilder( + valueListenable: _counter, + builder: + (BuildContext context, int value, Widget? child) { + return Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text( + "$value", + style: TextStyle( + color: getMissionVisionLimitColor(256), + fontWeight: FontWeight.bold, + ), ), - ), - const SizedBox(width: 5), - Text( - "/256", - style: TextStyle( - color: getMissionVisionLimitColor(256), - fontWeight: FontWeight.bold, + const SizedBox(width: 5), + Text( + "/256", + style: TextStyle( + color: getMissionVisionLimitColor(256), + fontWeight: FontWeight.bold, + ), ), - ), - ], - ); - }, + ], + ); + }, + ), ), ), const SizedBox(height: 25), - Center( - child: MihButton( - onPressed: () { - if (_formKey.currentState!.validate()) { - submitForm(); - } else { - MihAlertServices().formNotFilledCompletely(context); - } - }, - buttonColor: - MzansiInnovationHub.of(context)!.theme.successColor(), - width: 300, - child: Text( - widget.businessReview != null - ? "Edit Review" - : "Add Review", - style: TextStyle( - color: MzansiInnovationHub.of(context)! - .theme - .primaryColor(), - fontSize: 20, - fontWeight: FontWeight.bold, + Visibility( + visible: !widget.readOnly, + child: Center( + child: MihButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + submitForm(); + } else { + MihAlertServices().formNotFilledCompletely(context); + } + }, + buttonColor: MzansiInnovationHub.of(context)! + .theme + .successColor(), + width: 300, + child: Text( + widget.businessReview != null + ? "Edit Review" + : "Add Review", + style: TextStyle( + color: MzansiInnovationHub.of(context)! + .theme + .primaryColor(), + fontSize: 20, + fontWeight: FontWeight.bold, + ), ), ), ),