give window a read only mode

This commit is contained in:
2025-07-22 10:41:59 +02:00
parent 00dea2f78a
commit 845c8a6688

View File

@@ -20,11 +20,13 @@ class MihReviewBusinessWindow extends StatefulWidget {
final Business business; final Business business;
final BusinessReview? businessReview; final BusinessReview? businessReview;
final double screenWidth; final double screenWidth;
final bool readOnly;
const MihReviewBusinessWindow({ const MihReviewBusinessWindow({
super.key, super.key,
required this.business, required this.business,
required this.businessReview, required this.businessReview,
required this.screenWidth, required this.screenWidth,
required this.readOnly,
}); });
@override @override
@@ -205,6 +207,16 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
} }
} }
String getWindowTitle() {
if (widget.readOnly) {
return "Review Details";
} else if (widget.businessReview != null) {
return "Edit Review";
} else {
return "Add Review";
}
}
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
@@ -240,11 +252,11 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
// return const Placeholder(); // return const Placeholder();
return MihPackageWindow( return MihPackageWindow(
fullscreen: false, fullscreen: false,
windowTitle: widget.businessReview != null ? "Edit Review" : "Add Review", windowTitle: getWindowTitle(),
onWindowTapClose: () { onWindowTapClose: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
menuOptions: widget.businessReview != null menuOptions: widget.businessReview != null && !widget.readOnly
? [ ? [
SpeedDialChild( SpeedDialChild(
child: Icon( child: Icon(
@@ -331,6 +343,7 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
controller: _reviewTitleController, controller: _reviewTitleController,
multiLineInput: false, multiLineInput: false,
requiredText: true, requiredText: true,
readOnly: widget.readOnly,
hintText: "Review Title", hintText: "Review Title",
validator: (value) { validator: (value) {
return MihValidationServices() return MihValidationServices()
@@ -346,7 +359,8 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
MzansiInnovationHub.of(context)!.theme.primaryColor(), MzansiInnovationHub.of(context)!.theme.primaryColor(),
controller: _reviewDescriptionController, controller: _reviewDescriptionController,
multiLineInput: true, multiLineInput: true,
requiredText: false, requiredText: widget.readOnly,
readOnly: widget.readOnly,
hintText: "Review Description", hintText: "Review Description",
validator: (value) { validator: (value) {
if (_reviewDescriptionController.text.isEmpty) { if (_reviewDescriptionController.text.isEmpty) {
@@ -357,7 +371,9 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
} }
}, },
), ),
SizedBox( Visibility(
visible: !widget.readOnly,
child: SizedBox(
height: 15, height: 15,
child: ValueListenableBuilder( child: ValueListenableBuilder(
valueListenable: _counter, valueListenable: _counter,
@@ -387,8 +403,11 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
}, },
), ),
), ),
),
const SizedBox(height: 25), const SizedBox(height: 25),
Center( Visibility(
visible: !widget.readOnly,
child: Center(
child: MihButton( child: MihButton(
onPressed: () { onPressed: () {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
@@ -397,8 +416,9 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
MihAlertServices().formNotFilledCompletely(context); MihAlertServices().formNotFilledCompletely(context);
} }
}, },
buttonColor: buttonColor: MzansiInnovationHub.of(context)!
MzansiInnovationHub.of(context)!.theme.successColor(), .theme
.successColor(),
width: 300, width: 300,
child: Text( child: Text(
widget.businessReview != null widget.businessReview != null
@@ -414,6 +434,7 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
), ),
), ),
), ),
),
], ],
), ),
], ],