Skip to content

Commit

Permalink
Add text selection theme (#170)
Browse files Browse the repository at this point in the history
Flutter master has introduced a `DefaultSelectionStyle` widget that is
by default provided from MaterialApp. If no TextSelectionTheme is set in
the current theme context, TextField gets the default style that ends up
using the primary color from MaterialApp's theme data. This is not well
compatible with the newly added YaruTheme widget, which is created as a
child of MaterialApp. Providing the desired TextSelectionTheme avoids
that TextField would "bypass" YaruTheme.

Fixes: #160
  • Loading branch information
jpnurmi authored May 11, 2022
1 parent 539769b commit 5b47cfc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/themes/common_themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ AppBarTheme _createDarkAppBarTheme(ColorScheme colorScheme) {
);
}

// TextField
final inputDecorationTheme = InputDecorationTheme(
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(kButtonRadius)),
isDense: true,
);

TextSelectionThemeData _createTextSelectionTheme(ColorScheme colorScheme) {
return TextSelectionThemeData(
cursorColor: colorScheme.primary,
selectionColor: colorScheme.primary.withOpacity(0.40),
);
}

// Buttons

final _commonButtonStyle =
Expand Down Expand Up @@ -240,6 +248,7 @@ ThemeData createYaruLightTheme(
),
inputDecorationTheme: inputDecorationTheme,
toggleButtonsTheme: _toggleButtonsTheme,
textSelectionTheme: _createTextSelectionTheme(colorScheme),
);
}

Expand Down Expand Up @@ -284,5 +293,6 @@ ThemeData createYaruDarkTheme(
),
inputDecorationTheme: inputDecorationTheme,
toggleButtonsTheme: _toggleButtonsTheme,
textSelectionTheme: _createTextSelectionTheme(colorScheme),
);
}

0 comments on commit 5b47cfc

Please sign in to comment.