From 554852dd1e0aabad21bfde70f1e238ef6d68c4a5 Mon Sep 17 00:00:00 2001 From: Sadra Kafiri Date: Wed, 13 Aug 2025 16:22:50 +0330 Subject: [PATCH] add showModeButtons property --- feedback/example/lib/main.dart | 1 + feedback/lib/src/better_feedback.dart | 7 ++++ feedback/lib/src/controls_column.dart | 52 +++++++++++++------------ feedback/lib/src/feedback_widget.dart | 3 ++ feedback/test/controls_column_test.dart | 2 + 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/feedback/example/lib/main.dart b/feedback/example/lib/main.dart index 20cc49b4..636fd54f 100644 --- a/feedback/example/lib/main.dart +++ b/feedback/example/lib/main.dart @@ -41,6 +41,7 @@ class _MyAppState extends State { scrollController: scrollController, ) : null, + showModeButtons: true, theme: FeedbackThemeData( background: Colors.grey, feedbackSheetColor: Colors.grey[50]!, diff --git a/feedback/lib/src/better_feedback.dart b/feedback/lib/src/better_feedback.dart index 9657add6..3715036c 100644 --- a/feedback/lib/src/better_feedback.dart +++ b/feedback/lib/src/better_feedback.dart @@ -112,6 +112,7 @@ class BetterFeedback extends StatefulWidget { this.localeOverride, this.mode = FeedbackMode.draw, this.pixelRatio = 3.0, + this.showModeButtons = true, }) : assert( pixelRatio > 0, 'pixelRatio needs to be larger than 0', @@ -176,6 +177,11 @@ class BetterFeedback extends StatefulWidget { /// for information on the underlying implementation. final double pixelRatio; + /// Displays the mode switch buttons in the feedback UI. + /// + /// If set to `false`, the mode can only be changed through the `mode` property. + final bool showModeButtons; + /// Call `BetterFeedback.of(context)` to get an /// instance of [FeedbackData] on which you can call `.show()` or `.hide()` /// to enable or disable the feedback view. @@ -233,6 +239,7 @@ class _BetterFeedbackState extends State { isFeedbackVisible: controller.isVisible, drawColors: FeedbackTheme.of(context).drawColors, mode: widget.mode, + showModeButtons: widget.showModeButtons, pixelRatio: widget.pixelRatio, feedbackBuilder: widget.feedbackBuilder ?? simpleFeedbackBuilder, diff --git a/feedback/lib/src/controls_column.dart b/feedback/lib/src/controls_column.dart index 27eec0d1..684f4ea5 100644 --- a/feedback/lib/src/controls_column.dart +++ b/feedback/lib/src/controls_column.dart @@ -17,6 +17,7 @@ class ControlsColumn extends StatelessWidget { required this.onUndo, required this.onControlModeChanged, required this.onCloseFeedback, + required this.showModeButtons, required this.onClearDrawing, required this.colors, }) : assert( @@ -32,6 +33,7 @@ class ControlsColumn extends StatelessWidget { final VoidCallback onClearDrawing; final List colors; final Color activeColor; + final bool showModeButtons; final FeedbackMode mode; @override @@ -55,32 +57,34 @@ class ControlsColumn extends StatelessWidget { onPressed: onCloseFeedback, ), _ColumnDivider(), - RotatedBox( - quarterTurns: 1, - child: MaterialButton( - key: const ValueKey('navigate_button'), - onPressed: isNavigatingActive - ? null - : () => onControlModeChanged(FeedbackMode.navigate), - disabledTextColor: - FeedbackTheme.of(context).activeFeedbackModeColor, - child: Text(FeedbackLocalizations.of(context).navigate), + if (showModeButtons) ...[ + RotatedBox( + quarterTurns: 1, + child: MaterialButton( + key: const ValueKey('navigate_button'), + onPressed: isNavigatingActive + ? null + : () => onControlModeChanged(FeedbackMode.navigate), + disabledTextColor: + FeedbackTheme.of(context).activeFeedbackModeColor, + child: Text(FeedbackLocalizations.of(context).navigate), + ), ), - ), - _ColumnDivider(), - RotatedBox( - quarterTurns: 1, - child: MaterialButton( - key: const ValueKey('draw_button'), - minWidth: 20, - onPressed: isNavigatingActive - ? () => onControlModeChanged(FeedbackMode.draw) - : null, - disabledTextColor: - FeedbackTheme.of(context).activeFeedbackModeColor, - child: Text(FeedbackLocalizations.of(context).draw), + _ColumnDivider(), + RotatedBox( + quarterTurns: 1, + child: MaterialButton( + key: const ValueKey('draw_button'), + minWidth: 20, + onPressed: isNavigatingActive + ? () => onControlModeChanged(FeedbackMode.draw) + : null, + disabledTextColor: + FeedbackTheme.of(context).activeFeedbackModeColor, + child: Text(FeedbackLocalizations.of(context).draw), + ), ), - ), + ], IconButton( key: const ValueKey('undo_button'), icon: const Icon(Icons.undo), diff --git a/feedback/lib/src/feedback_widget.dart b/feedback/lib/src/feedback_widget.dart index 5a9a2715..be069434 100644 --- a/feedback/lib/src/feedback_widget.dart +++ b/feedback/lib/src/feedback_widget.dart @@ -24,6 +24,7 @@ class FeedbackWidget extends StatefulWidget { required this.child, required this.isFeedbackVisible, required this.drawColors, + required this.showModeButtons, required this.mode, required this.pixelRatio, required this.feedbackBuilder, @@ -35,6 +36,7 @@ class FeedbackWidget extends StatefulWidget { ); final bool isFeedbackVisible; + final bool showModeButtons; final FeedbackMode mode; final double pixelRatio; final Widget child; @@ -219,6 +221,7 @@ class FeedbackWidgetState extends State child: ControlsColumn( mode: mode, activeColor: painterController.drawColor, + showModeButtons: widget.showModeButtons, colors: widget.drawColors, onColorChanged: (color) { setState(() { diff --git a/feedback/test/controls_column_test.dart b/feedback/test/controls_column_test.dart index 0560ff1b..90251572 100644 --- a/feedback/test/controls_column_test.dart +++ b/feedback/test/controls_column_test.dart @@ -8,6 +8,7 @@ void main() { Widget create({ Color? activeColor, FeedbackMode? mode, + bool? showNavigateButton, ValueChanged? onColorChanged, VoidCallback? onUndo, ValueChanged? onControlModeChanged, @@ -19,6 +20,7 @@ void main() { child: ControlsColumn( activeColor: activeColor ?? Colors.red, mode: mode ?? FeedbackMode.draw, + showModeButtons: showNavigateButton ?? true, colors: colors ?? [Colors.red, Colors.green, Colors.blue, Colors.yellow], onClearDrawing: onClearDrawing ?? () {},