diff --git a/feedback/example/lib/main.dart b/feedback/example/lib/main.dart index 18889d6b..2445774c 100644 --- a/feedback/example/lib/main.dart +++ b/feedback/example/lib/main.dart @@ -60,6 +60,7 @@ class _MyAppState extends State { ], localeOverride: const Locale('en'), mode: FeedbackMode.draw, + supportedModes: FeedbackMode.values, pixelRatio: 1, child: MaterialApp( title: 'Feedback Demo', diff --git a/feedback/lib/src/better_feedback.dart b/feedback/lib/src/better_feedback.dart index 9657add6..1edba033 100644 --- a/feedback/lib/src/better_feedback.dart +++ b/feedback/lib/src/better_feedback.dart @@ -111,6 +111,7 @@ class BetterFeedback extends StatefulWidget { this.localizationsDelegates, this.localeOverride, this.mode = FeedbackMode.draw, + this.supportedModes = FeedbackMode.values, this.pixelRatio = 3.0, }) : assert( pixelRatio > 0, @@ -166,6 +167,11 @@ class BetterFeedback extends StatefulWidget { /// See [FeedbackMode] for other options. final FeedbackMode mode; + /// Set the default supported modes. + /// By default all modes will be supported. + /// See [FeedbackMode] for more info. + final List supportedModes; + /// The pixelRatio describes the scale between /// the logical pixels and the size of the output image. /// Specifying 1.0 will give you a 1:1 mapping between @@ -233,6 +239,7 @@ class _BetterFeedbackState extends State { isFeedbackVisible: controller.isVisible, drawColors: FeedbackTheme.of(context).drawColors, mode: widget.mode, + supportedModes: widget.supportedModes, 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..4c88c217 100644 --- a/feedback/lib/src/controls_column.dart +++ b/feedback/lib/src/controls_column.dart @@ -12,6 +12,7 @@ class ControlsColumn extends StatelessWidget { ControlsColumn({ super.key, required this.mode, + required this.supportedModes, required this.activeColor, required this.onColorChanged, required this.onUndo, @@ -33,6 +34,7 @@ class ControlsColumn extends StatelessWidget { final List colors; final Color activeColor; final FeedbackMode mode; + final List supportedModes; @override Widget build(BuildContext context) { @@ -54,50 +56,54 @@ class ControlsColumn extends StatelessWidget { icon: const Icon(Icons.close), 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 (supportedModes.contains(FeedbackMode.navigate)) ...[ + _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), + ), ), - ), - _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), + ], + if (supportedModes.contains(FeedbackMode.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), - onPressed: isNavigatingActive ? null : onUndo, - ), - IconButton( - key: const ValueKey('clear_button'), - icon: const Icon(Icons.delete), - onPressed: isNavigatingActive ? null : onClearDrawing, - ), - for (final color in colors) - _ColorSelectionIconButton( - key: ValueKey(color), - color: color, - onPressed: isNavigatingActive ? null : onColorChanged, - isActive: activeColor == color, + IconButton( + key: const ValueKey('undo_button'), + icon: const Icon(Icons.undo), + onPressed: isNavigatingActive ? null : onUndo, + ), + IconButton( + key: const ValueKey('clear_button'), + icon: const Icon(Icons.delete), + onPressed: isNavigatingActive ? null : onClearDrawing, ), + for (final color in colors) + _ColorSelectionIconButton( + key: ValueKey(color), + color: color, + onPressed: isNavigatingActive ? null : onColorChanged, + isActive: activeColor == color, + ), + ], ], ), ); diff --git a/feedback/lib/src/feedback_widget.dart b/feedback/lib/src/feedback_widget.dart index ee1c679c..52161749 100644 --- a/feedback/lib/src/feedback_widget.dart +++ b/feedback/lib/src/feedback_widget.dart @@ -2,11 +2,11 @@ import 'package:feedback/feedback.dart'; import 'package:feedback/src/controls_column.dart'; -import 'package:feedback/src/scale_and_fade.dart'; import 'package:feedback/src/feedback_bottom_sheet.dart'; import 'package:feedback/src/paint_on_background.dart'; import 'package:feedback/src/painter.dart'; import 'package:feedback/src/scale_and_clip.dart'; +import 'package:feedback/src/scale_and_fade.dart'; import 'package:feedback/src/screenshot.dart'; import 'package:feedback/src/theme/feedback_theme.dart'; import 'package:feedback/src/utilities/back_button_interceptor.dart'; @@ -25,6 +25,7 @@ class FeedbackWidget extends StatefulWidget { required this.isFeedbackVisible, required this.drawColors, required this.mode, + required this.supportedModes, required this.pixelRatio, required this.feedbackBuilder, }) : assert( @@ -36,6 +37,7 @@ class FeedbackWidget extends StatefulWidget { final bool isFeedbackVisible; final FeedbackMode mode; + final List supportedModes; final double pixelRatio; final Widget child; final List drawColors; @@ -82,6 +84,7 @@ class FeedbackWidgetState extends State @override void initState() { super.initState(); + BackButtonInterceptor.add(backButtonIntercept); } @@ -110,6 +113,9 @@ class FeedbackWidgetState extends State super.didUpdateWidget(oldWidget); // update feedback mode with the initial value mode = widget.mode; + if (!widget.supportedModes.contains(mode)) { + mode = widget.supportedModes.first; + } if (oldWidget.isFeedbackVisible != widget.isFeedbackVisible && oldWidget.isFeedbackVisible == false) { // Feedback is now visible, @@ -223,6 +229,7 @@ class FeedbackWidgetState extends State minScale: .7, child: ControlsColumn( mode: mode, + supportedModes: widget.supportedModes, activeColor: painterController.drawColor, colors: widget.drawColors, onColorChanged: (color) { diff --git a/feedback/test/controls_column_test.dart b/feedback/test/controls_column_test.dart index 0560ff1b..310ec52b 100644 --- a/feedback/test/controls_column_test.dart +++ b/feedback/test/controls_column_test.dart @@ -1,13 +1,14 @@ import 'package:feedback/src/controls_column.dart'; import 'package:feedback/src/feedback_mode.dart'; import 'package:feedback/src/l18n/localization.dart'; -import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; void main() { Widget create({ Color? activeColor, FeedbackMode? mode, + List? supportedModes, ValueChanged? onColorChanged, VoidCallback? onUndo, ValueChanged? onControlModeChanged, @@ -19,6 +20,7 @@ void main() { child: ControlsColumn( activeColor: activeColor ?? Colors.red, mode: mode ?? FeedbackMode.draw, + supportedModes: supportedModes ?? FeedbackMode.values, colors: colors ?? [Colors.red, Colors.green, Colors.blue, Colors.yellow], onClearDrawing: onClearDrawing ?? () {},