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,59 +371,66 @@ class _MihReviewBusinessWindowState extends State<MihReviewBusinessWindow> {
} }
}, },
), ),
SizedBox( Visibility(
height: 15, visible: !widget.readOnly,
child: ValueListenableBuilder( child: SizedBox(
valueListenable: _counter, height: 15,
builder: child: ValueListenableBuilder(
(BuildContext context, int value, Widget? child) { valueListenable: _counter,
return Row( builder:
mainAxisSize: MainAxisSize.max, (BuildContext context, int value, Widget? child) {
mainAxisAlignment: MainAxisAlignment.end, return Row(
children: [ mainAxisSize: MainAxisSize.max,
Text( mainAxisAlignment: MainAxisAlignment.end,
"$value", children: [
style: TextStyle( Text(
color: getMissionVisionLimitColor(256), "$value",
fontWeight: FontWeight.bold, style: TextStyle(
color: getMissionVisionLimitColor(256),
fontWeight: FontWeight.bold,
),
), ),
), const SizedBox(width: 5),
const SizedBox(width: 5), Text(
Text( "/256",
"/256", style: TextStyle(
style: TextStyle( color: getMissionVisionLimitColor(256),
color: getMissionVisionLimitColor(256), fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), ),
), ],
], );
); },
}, ),
), ),
), ),
const SizedBox(height: 25), const SizedBox(height: 25),
Center( Visibility(
child: MihButton( visible: !widget.readOnly,
onPressed: () { child: Center(
if (_formKey.currentState!.validate()) { child: MihButton(
submitForm(); onPressed: () {
} else { if (_formKey.currentState!.validate()) {
MihAlertServices().formNotFilledCompletely(context); submitForm();
} } else {
}, MihAlertServices().formNotFilledCompletely(context);
buttonColor: }
MzansiInnovationHub.of(context)!.theme.successColor(), },
width: 300, buttonColor: MzansiInnovationHub.of(context)!
child: Text( .theme
widget.businessReview != null .successColor(),
? "Edit Review" width: 300,
: "Add Review", child: Text(
style: TextStyle( widget.businessReview != null
color: MzansiInnovationHub.of(context)! ? "Edit Review"
.theme : "Add Review",
.primaryColor(), style: TextStyle(
fontSize: 20, color: MzansiInnovationHub.of(context)!
fontWeight: FontWeight.bold, .theme
.primaryColor(),
fontSize: 20,
fontWeight: FontWeight.bold,
),
), ),
), ),
), ),