-
Notifications
You must be signed in to change notification settings - Fork 326
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
Alternating colors look nice in tables when embedded in IDE #8498
Changes from 1 commit
afcfecf
faa0e99
c417036
9ebff57
3b829aa
3fed782
8804dc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
// TODO(kenz): remove once min flutter version of devtools_app_shared >= 3.25 | ||
// ignore_for_file: deprecated_member_use, analysis performed with newer flutter version than min sdk | ||
|
||
import 'dart:math' as math; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import '../ui_utils.dart'; | ||
|
@@ -71,61 +73,63 @@ ThemeData _baseTheme({ | |
// TODO(kenz): do we need to pass in the foreground color from the [IdeTheme] | ||
// as well as the background color? | ||
return theme.copyWith( | ||
tabBarTheme: theme.tabBarTheme.copyWith( | ||
tabAlignment: TabAlignment.start, | ||
dividerColor: Colors.transparent, | ||
labelStyle: theme.regularTextStyle, | ||
labelPadding: | ||
const EdgeInsets.symmetric(horizontal: defaultTabBarPadding), | ||
), | ||
canvasColor: backgroundColor, | ||
scaffoldBackgroundColor: backgroundColor, | ||
iconButtonTheme: IconButtonThemeData( | ||
style: IconButton.styleFrom( | ||
padding: const EdgeInsets.all(densePadding), | ||
minimumSize: Size(defaultButtonHeight, defaultButtonHeight), | ||
fixedSize: Size(defaultButtonHeight, defaultButtonHeight), | ||
tabBarTheme: theme.tabBarTheme.copyWith( | ||
tabAlignment: TabAlignment.start, | ||
dividerColor: Colors.transparent, | ||
labelStyle: theme.regularTextStyle, | ||
labelPadding: | ||
const EdgeInsets.symmetric(horizontal: defaultTabBarPadding), | ||
), | ||
), | ||
outlinedButtonTheme: OutlinedButtonThemeData( | ||
style: OutlinedButton.styleFrom( | ||
minimumSize: Size(buttonMinWidth, defaultButtonHeight), | ||
fixedSize: Size.fromHeight(defaultButtonHeight), | ||
foregroundColor: theme.colorScheme.onSurface, | ||
padding: const EdgeInsets.symmetric(horizontal: denseSpacing), | ||
canvasColor: backgroundColor, | ||
scaffoldBackgroundColor: backgroundColor, | ||
iconButtonTheme: IconButtonThemeData( | ||
style: IconButton.styleFrom( | ||
padding: const EdgeInsets.all(densePadding), | ||
minimumSize: Size(defaultButtonHeight, defaultButtonHeight), | ||
fixedSize: Size(defaultButtonHeight, defaultButtonHeight), | ||
), | ||
), | ||
), | ||
textButtonTheme: TextButtonThemeData( | ||
style: TextButton.styleFrom( | ||
padding: const EdgeInsets.all(densePadding), | ||
minimumSize: Size(buttonMinWidth, defaultButtonHeight), | ||
fixedSize: Size.fromHeight(defaultButtonHeight), | ||
outlinedButtonTheme: OutlinedButtonThemeData( | ||
style: OutlinedButton.styleFrom( | ||
minimumSize: Size(buttonMinWidth, defaultButtonHeight), | ||
fixedSize: Size.fromHeight(defaultButtonHeight), | ||
foregroundColor: theme.colorScheme.onSurface, | ||
padding: const EdgeInsets.symmetric(horizontal: denseSpacing), | ||
), | ||
), | ||
), | ||
elevatedButtonTheme: ElevatedButtonThemeData( | ||
style: ElevatedButton.styleFrom( | ||
minimumSize: Size(buttonMinWidth, defaultButtonHeight), | ||
fixedSize: Size.fromHeight(defaultButtonHeight), | ||
backgroundColor: theme.colorScheme.primary, | ||
foregroundColor: theme.colorScheme.onPrimary, | ||
padding: const EdgeInsets.symmetric(horizontal: denseSpacing), | ||
textButtonTheme: TextButtonThemeData( | ||
style: TextButton.styleFrom( | ||
padding: const EdgeInsets.all(densePadding), | ||
minimumSize: Size(buttonMinWidth, defaultButtonHeight), | ||
fixedSize: Size.fromHeight(defaultButtonHeight), | ||
), | ||
), | ||
), | ||
menuButtonTheme: MenuButtonThemeData( | ||
style: ButtonStyle( | ||
textStyle: WidgetStatePropertyAll<TextStyle>(theme.regularTextStyle), | ||
fixedSize: const WidgetStatePropertyAll<Size>(Size.fromHeight(24.0)), | ||
elevatedButtonTheme: ElevatedButtonThemeData( | ||
style: ElevatedButton.styleFrom( | ||
minimumSize: Size(buttonMinWidth, defaultButtonHeight), | ||
fixedSize: Size.fromHeight(defaultButtonHeight), | ||
backgroundColor: theme.colorScheme.primary, | ||
foregroundColor: theme.colorScheme.onPrimary, | ||
padding: const EdgeInsets.symmetric(horizontal: denseSpacing), | ||
), | ||
), | ||
), | ||
dropdownMenuTheme: DropdownMenuThemeData( | ||
textStyle: theme.regularTextStyle, | ||
), | ||
progressIndicatorTheme: ProgressIndicatorThemeData( | ||
linearMinHeight: defaultLinearProgressIndicatorHeight, | ||
), | ||
primaryTextTheme: _devToolsTextTheme(theme, theme.primaryTextTheme), | ||
textTheme: _devToolsTextTheme(theme, theme.textTheme), | ||
); | ||
menuButtonTheme: MenuButtonThemeData( | ||
style: ButtonStyle( | ||
textStyle: WidgetStatePropertyAll<TextStyle>(theme.regularTextStyle), | ||
fixedSize: const WidgetStatePropertyAll<Size>(Size.fromHeight(24.0)), | ||
), | ||
), | ||
dropdownMenuTheme: DropdownMenuThemeData( | ||
textStyle: theme.regularTextStyle, | ||
), | ||
progressIndicatorTheme: ProgressIndicatorThemeData( | ||
linearMinHeight: defaultLinearProgressIndicatorHeight, | ||
), | ||
primaryTextTheme: _devToolsTextTheme(theme, theme.primaryTextTheme), | ||
textTheme: _devToolsTextTheme(theme, theme.textTheme), | ||
colorScheme: theme.colorScheme.copyWith( | ||
surface: backgroundColor, | ||
)); | ||
} | ||
|
||
TextTheme _devToolsTextTheme(ThemeData theme, TextTheme textTheme) { | ||
|
@@ -359,11 +363,10 @@ extension DevToolsSharedColorScheme on ColorScheme { | |
Color get _devtoolsLink => | ||
isLight ? const Color(0xFF1976D2) : Colors.lightBlueAccent; | ||
|
||
Color get alternatingBackgroundColor1 => | ||
isLight ? Colors.white : const Color(0xFF1B1B1F); | ||
Color get alternatingBackgroundColor1 => surface; | ||
|
||
Color get alternatingBackgroundColor2 => | ||
isLight ? const Color(0xFFF2F0F4) : const Color(0xFF303033); | ||
isLight ? surface.darken() : surface.lighten(); | ||
|
||
Color get selectedRowBackgroundColor => | ||
isLight ? const Color(0xFFC7C6CA) : const Color(0xFF5E5E62); | ||
|
@@ -599,3 +602,23 @@ ButtonStyle _generateButtonStyle({ | |
} | ||
return buttonStyle; | ||
} | ||
|
||
extension on Color { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we already have these utilities in devtools_app: https://github.com/flutter/devtools/blob/master/packages/devtools_app/lib/src/shared/common_widgets.dart/#L944 Instead of creating new utility methods here, can we move the existing ones to devtools_app_shared: https://github.com/flutter/devtools/blob/master/packages/devtools_app_shared/lib/src/ui/ui_utils.dart/#L1 |
||
Color darken({int percent = 10}) { | ||
assert(1 <= percent && percent <= 100); | ||
final p = percent / 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make these methods take a value between 0.0 and 1.0 instead of having to / 100 to get the percentage? This is similar to flutter's opacity APIs for example. |
||
final hslColor = HSLColor.fromColor(this); | ||
return hslColor | ||
.withLightness(math.max(0.0, hslColor.lightness - p)) | ||
.toColor(); | ||
} | ||
|
||
Color lighten({int percent = 10}) { | ||
assert(1 <= percent && percent <= 100); | ||
final p = percent / 100; | ||
final hslColor = HSLColor.fromColor(this); | ||
return hslColor | ||
.withLightness(math.min(1.0, hslColor.lightness + p)) | ||
.toColor(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really want to override the surface color specified by the
darkColorScheme
andlightColorScheme
definitions?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the darkColorScheme and lightColorScheme, the surface color is the same as this backgroundColor. This makes sure that the surface color for IDE themes matches the IDE's background color.