From 5b47cfc904ce9e64af8c2b2f66d282033addd183 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 11 May 2022 09:58:10 +0200 Subject: [PATCH] Add text selection theme (#170) 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 --- lib/src/themes/common_themes.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/src/themes/common_themes.dart b/lib/src/themes/common_themes.dart index 3f36f229b..7a2a44079 100644 --- a/lib/src/themes/common_themes.dart +++ b/lib/src/themes/common_themes.dart @@ -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 = @@ -240,6 +248,7 @@ ThemeData createYaruLightTheme( ), inputDecorationTheme: inputDecorationTheme, toggleButtonsTheme: _toggleButtonsTheme, + textSelectionTheme: _createTextSelectionTheme(colorScheme), ); } @@ -284,5 +293,6 @@ ThemeData createYaruDarkTheme( ), inputDecorationTheme: inputDecorationTheme, toggleButtonsTheme: _toggleButtonsTheme, + textSelectionTheme: _createTextSelectionTheme(colorScheme), ); }