Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions feedback/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class _MyAppState extends State<MyApp> {
],
localeOverride: const Locale('en'),
mode: FeedbackMode.draw,
supportedModes: FeedbackMode.values,
pixelRatio: 1,
child: MaterialApp(
title: 'Feedback Demo',
Expand Down
7 changes: 7 additions & 0 deletions feedback/lib/src/better_feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<FeedbackMode> 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
Expand Down Expand Up @@ -233,6 +239,7 @@ class _BetterFeedbackState extends State<BetterFeedback> {
isFeedbackVisible: controller.isVisible,
drawColors: FeedbackTheme.of(context).drawColors,
mode: widget.mode,
supportedModes: widget.supportedModes,
pixelRatio: widget.pixelRatio,
feedbackBuilder:
widget.feedbackBuilder ?? simpleFeedbackBuilder,
Expand Down
88 changes: 47 additions & 41 deletions feedback/lib/src/controls_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,6 +34,7 @@ class ControlsColumn extends StatelessWidget {
final List<Color> colors;
final Color activeColor;
final FeedbackMode mode;
final List<FeedbackMode> supportedModes;

@override
Widget build(BuildContext context) {
Expand All @@ -54,50 +56,54 @@ class ControlsColumn extends StatelessWidget {
icon: const Icon(Icons.close),
onPressed: onCloseFeedback,
),
_ColumnDivider(),
RotatedBox(
quarterTurns: 1,
child: MaterialButton(
key: const ValueKey<String>('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<String>('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<String>('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<String>('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<String>('undo_button'),
icon: const Icon(Icons.undo),
onPressed: isNavigatingActive ? null : onUndo,
),
IconButton(
key: const ValueKey<String>('clear_button'),
icon: const Icon(Icons.delete),
onPressed: isNavigatingActive ? null : onClearDrawing,
),
for (final color in colors)
_ColorSelectionIconButton(
key: ValueKey<Color>(color),
color: color,
onPressed: isNavigatingActive ? null : onColorChanged,
isActive: activeColor == color,
IconButton(
key: const ValueKey<String>('undo_button'),
icon: const Icon(Icons.undo),
onPressed: isNavigatingActive ? null : onUndo,
),
IconButton(
key: const ValueKey<String>('clear_button'),
icon: const Icon(Icons.delete),
onPressed: isNavigatingActive ? null : onClearDrawing,
),
for (final color in colors)
_ColorSelectionIconButton(
key: ValueKey<Color>(color),
color: color,
onPressed: isNavigatingActive ? null : onColorChanged,
isActive: activeColor == color,
),
],
],
),
);
Expand Down
9 changes: 8 additions & 1 deletion feedback/lib/src/feedback_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -25,6 +25,7 @@
required this.isFeedbackVisible,
required this.drawColors,
required this.mode,
required this.supportedModes,
required this.pixelRatio,
required this.feedbackBuilder,
}) : assert(
Expand All @@ -36,6 +37,7 @@

final bool isFeedbackVisible;
final FeedbackMode mode;
final List<FeedbackMode> supportedModes;
final double pixelRatio;
final Widget child;
final List<Color> drawColors;
Expand Down Expand Up @@ -82,6 +84,7 @@
@override
void initState() {
super.initState();

BackButtonInterceptor.add(backButtonIntercept);
}

Expand Down Expand Up @@ -110,6 +113,9 @@
super.didUpdateWidget(oldWidget);
// update feedback mode with the initial value
mode = widget.mode;
if (!widget.supportedModes.contains(mode)) {
mode = widget.supportedModes.first;

Check warning on line 117 in feedback/lib/src/feedback_widget.dart

View check run for this annotation

Codecov / codecov/patch

feedback/lib/src/feedback_widget.dart#L117

Added line #L117 was not covered by tests
}
if (oldWidget.isFeedbackVisible != widget.isFeedbackVisible &&
oldWidget.isFeedbackVisible == false) {
// Feedback is now visible,
Expand Down Expand Up @@ -223,6 +229,7 @@
minScale: .7,
child: ControlsColumn(
mode: mode,
supportedModes: widget.supportedModes,
activeColor: painterController.drawColor,
colors: widget.drawColors,
onColorChanged: (color) {
Expand Down
4 changes: 3 additions & 1 deletion feedback/test/controls_column_test.dart
Original file line number Diff line number Diff line change
@@ -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<FeedbackMode>? supportedModes,
ValueChanged<Color>? onColorChanged,
VoidCallback? onUndo,
ValueChanged<FeedbackMode>? onControlModeChanged,
Expand All @@ -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 ?? () {},
Expand Down