Skip to content

Commit

Permalink
Add high contrast themes (#144)
Browse files Browse the repository at this point in the history
* Add high contrast themes

* hc dark fix checks
  • Loading branch information
Feichtmeier committed Apr 1, 2022
1 parent 8c363fa commit 039d246
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
11 changes: 10 additions & 1 deletion example/lib/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class _HomePageState extends State<HomePage> {
final textController = TextEditingController(
text:
'My code fails, I do not know why.\nMy code works, I do not know why.\nText in other scripts: Tamaziɣt Taqbaylit, 中文(简体), Čeština, Беларуская, Ελληνικά, עברית, Русский, བོད་ཡིག, Norsk bokmål.');
var themeName = 'Yaru-light';

int _selectedIndex = 0;
final List<Widget> _views = <Widget>[
Expand Down Expand Up @@ -64,6 +63,16 @@ class _HomePageState extends State<HomePage> {
),
),
actions: [
ColorDisk(
color: themeMode.value == ThemeMode.light
? Colors.black
: Colors.white,
selected: (lightTheme.value == yaruHighContrastLight ||
darkTheme.value == yaruHighContrastDark),
onPressed: () {
lightTheme.value = yaruHighContrastLight;
darkTheme.value = yaruHighContrastDark;
}),
ColorDisk(
color: YaruColors.ubuntuOrange,
selected:
Expand Down
8 changes: 8 additions & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
17 changes: 11 additions & 6 deletions lib/src/themes/common_themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ ElevatedButtonThemeData _getElevatedButtonThemeData(Color color) {
return ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
primary: color,
onPrimary: Colors.white,
onPrimary: ThemeData.estimateBrightnessForColor(color) == Brightness.light
? Colors.black
: Colors.white,
visualDensity: _commonButtonStyle.visualDensity,
elevation: 0,
shape: RoundedRectangleBorder(
Expand Down Expand Up @@ -170,9 +172,11 @@ Color _getCheckFillColor(Set<MaterialState> states, MaterialColor selectedColor,
: YaruColors.warmGrey.shade300;
}

Color _getCheckColor(Set<MaterialState> states) {
Color _getCheckColor(Set<MaterialState> states, Color color) {
if (!states.contains(MaterialState.disabled)) {
return Colors.white;
return ThemeData.estimateBrightnessForColor(color) == Brightness.light
? Colors.black
: Colors.white;
}
return YaruColors.warmGrey;
}
Expand All @@ -185,7 +189,8 @@ CheckboxThemeData _getCheckBoxThemeData(
),
fillColor: MaterialStateProperty.resolveWith(
(states) => _getCheckFillColor(states, primaryColor, brightness)),
checkColor: MaterialStateProperty.resolveWith(_getCheckColor),
checkColor: MaterialStateProperty.resolveWith(
(states) => _getCheckColor(states, primaryColor.shade500)),
);
}

Expand Down Expand Up @@ -245,7 +250,7 @@ ThemeData createYaruDarkTheme(
required MaterialColor primaryColor,
Color? elevatedButtonColor}) {
return ThemeData(
tabBarTheme: TabBarTheme(labelColor: colorScheme.onBackground),
tabBarTheme: TabBarTheme(labelColor: Colors.white.withOpacity(0.8)),
dialogTheme: _dialogThemeDark,
brightness: Brightness.dark,
primaryColor: colorScheme.primary,
Expand Down Expand Up @@ -276,7 +281,7 @@ ThemeData createYaruDarkTheme(
),
bottomNavigationBarTheme: BottomNavigationBarThemeData(
selectedItemColor: colorScheme.primary,
unselectedItemColor: colorScheme.onBackground.withOpacity(0.8),
unselectedItemColor: Colors.white.withOpacity(0.8),
),
inputDecorationTheme: inputDecorationTheme,
toggleButtonsTheme: _toggleButtonsTheme,
Expand Down
32 changes: 32 additions & 0 deletions lib/src/themes/high_contrast.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:yaru/src/colors/yaru_colors.dart';

import 'package:yaru/src/themes/common_themes.dart';

final b = YaruColors.createMaterialColor(Colors.black);
final yaruHighContrastLight = createYaruLightTheme(
colorScheme: ColorScheme.fromSwatch(
primarySwatch: b,
primaryColorDark: YaruColors.coolGrey,
accentColor: Colors.black,
cardColor: Colors.white,
backgroundColor: Colors.white,
errorColor: YaruColors.red,
brightness: Brightness.light,
),
primaryColor: b,
);

final w = YaruColors.createMaterialColor(Colors.white);
final yaruHighContrastDark = createYaruDarkTheme(
colorScheme: ColorScheme.fromSwatch(
primarySwatch: w,
primaryColorDark: Colors.white,
accentColor: Colors.white,
cardColor: Colors.black,
backgroundColor: Colors.black,
errorColor: YaruColors.red,
brightness: Brightness.dark,
),
primaryColor: w,
);
3 changes: 2 additions & 1 deletion lib/yaru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ library yaru;
export 'package:yaru/src/colors/flavor_colors.dart';
export 'package:yaru/src/colors/yaru_colors.dart';
export 'package:yaru/src/themes/common_themes.dart';
export 'package:yaru/src/themes/high_contrast.dart';
export 'package:yaru/src/themes/yaru_accents.dart';
export 'package:yaru/src/themes/yaru_dark.dart';
export 'package:yaru/src/themes/yaru_kubuntu_dark.dart';
export 'package:yaru/src/themes/yaru_kubuntu_light.dart';
Expand All @@ -17,4 +19,3 @@ export 'package:yaru/src/themes/yaru_ubuntu_studio_dark.dart';
export 'package:yaru/src/themes/yaru_ubuntu_studio_light.dart';
export 'package:yaru/src/themes/yaru_xubuntu_dark.dart';
export 'package:yaru/src/themes/yaru_xubuntu_light.dart';
export 'package:yaru/src/themes/yaru_accents.dart';

0 comments on commit 039d246

Please sign in to comment.