Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a copy with method to FeedbackThemeData #312

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Changes from 3 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
43 changes: 40 additions & 3 deletions feedback/lib/src/theme/feedback_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FeedbackThemeData {
this.bottomSheetDescriptionStyle = _defaultBottomSheetDescriptionStyle,
this.bottomSheetTextInputStyle = _defaultBottomSheetTextInputStyle,
this.sheetIsDraggable = true,
Brightness? brightness,
Color? dragHandleColor,
ColorScheme? colorScheme})
:
Expand All @@ -50,8 +51,9 @@ class FeedbackThemeData {
// ignore: prefer_is_empty
drawColors.length > 0,
'There must be at least one color to draw with',
),
brightness = ThemeData.estimateBrightnessForColor(feedbackSheetColor) {
) {
this.brightness =
brightness ??= ThemeData.estimateBrightnessForColor(feedbackSheetColor);
final bool isDark = brightness == Brightness.dark;
this.dragHandleColor =
dragHandleColor ?? (isDark ? Colors.black26 : Colors.white38);
Expand All @@ -71,6 +73,7 @@ class FeedbackThemeData {
color: Colors.white,
),
sheetIsDraggable: sheetIsDraggable,
brightness: Brightness.dark,
);

/// Create a light version of the [FeedbackThemeData]
Expand All @@ -81,10 +84,11 @@ class FeedbackThemeData {
feedbackSheetColor: _lightGrey,
bottomSheetDescriptionStyle: _defaultBottomSheetDescriptionStyle,
sheetIsDraggable: sheetIsDraggable,
brightness: Brightness.light,
);

/// Brightness of the theme based on the [background] color
final Brightness brightness;
late final Brightness brightness;

/// The background of the feedback view.
final Color background;
Expand Down Expand Up @@ -122,6 +126,39 @@ class FeedbackThemeData {

/// [ColorScheme] on the feedback UI
late final ColorScheme colorScheme;

/// Creates a copy of the current [FeedbackThemeData] with the given
/// optional fields replaced with the given values.
FeedbackThemeData copyWith({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll look into it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ueman done

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Color? background,
Color? feedbackSheetColor,
double? feedbackSheetHeight,
Color? activeFeedbackModeColor,
List<Color>? drawColors,
TextStyle? bottomSheetDescriptionStyle,
TextStyle? bottomSheetTextInputStyle,
bool? sheetIsDraggable,
Color? dragHandleColor,
Brightness? brightness,
ColorScheme? colorScheme,
}) {
return FeedbackThemeData(
background: background ?? this.background,
feedbackSheetColor: feedbackSheetColor ?? this.feedbackSheetColor,
feedbackSheetHeight: feedbackSheetHeight ?? this.feedbackSheetHeight,
activeFeedbackModeColor:
activeFeedbackModeColor ?? this.activeFeedbackModeColor,
drawColors: drawColors ?? this.drawColors,
bottomSheetDescriptionStyle:
bottomSheetDescriptionStyle ?? this.bottomSheetDescriptionStyle,
bottomSheetTextInputStyle:
bottomSheetTextInputStyle ?? this.bottomSheetTextInputStyle,
sheetIsDraggable: sheetIsDraggable ?? this.sheetIsDraggable,
dragHandleColor: dragHandleColor ?? this.dragHandleColor,
brightness: brightness ?? this.brightness,
colorScheme: colorScheme ?? this.colorScheme,
);
}
}

/// Provides an instance of [FeedbackThemeData] for all descendants.
Expand Down
Loading