Skip to content

Commit cbdae3a

Browse files
V1: More integration tests for themes and controls (#5632)
* Refactor DataTable decoration and update tests Improved DataTable decoration handling in datatable.dart by using type-safe casting and fallback logic. Updated integration tests to use per-test app instances, added a new themed DataTable test, and replaced golden images for macOS DataTable screenshots. * Refactor theme color handling and update docs Simplified theme color logic in Dart by removing primarySwatch and related properties. Updated Python Theme dataclass to remove primary_swatch and added documentation for color_scheme_seed. * Update theme color scheme handling and docs Refactored Dart theme parsing to use a local colorScheme variable and set shadowColor from colorScheme. Improved Python Theme class documentation for color_scheme and chip_theme, and removed unused color attributes. * Improve divider theme handling in theme parsing Refactored Dart theme parsing to use DividerThemeData for divider color and theme assignment. Added docstrings to Python Theme class for divider_theme, clarifying its usage and affected widgets. * Add Divider theme support and update tests Updated integration tests for Divider and DataTable to cover theme properties and added new golden images for Divider tests. Also removed unused divider_color from Theme. * Add default text to dropdown in test Set the 'text' property to 'Select a color' for the dropdown in the test_dropdown.py integration test. Updated golden images to reflect this UI change. * Refactor dropdown integration tests and add golden images Updated dropdown integration tests to use function-scoped async fixtures and split basic and theme tests. Added new golden images for macOS dropdown control states. Also removed redundant screenshot enabling in data table and divider tests. * Enhance Dropdown menu style customization Added support for specifying a custom MenuStyle for Dropdown controls, allowing configuration of background color, elevation, and width. Updated theme parsing to use 'dropdown_theme' for DropdownMenuTheme. Adjusted integration test golden images to reflect new styling options. Improved documentation for menu_style in Python Dropdown and DropdownTheme classes. * Fixed integration tests: Remove tester service from page initialization Eliminated appending the Tester service to the page's services list in FletTestApp. This may be part of a refactor or cleanup to simplify test app setup. * Add button theme integration test and docstring Introduces an integration test for button theme customization, including a golden image for macOS. Also adds a docstring to the Theme.button_theme property to clarify its purpose. * Enable text_style in button theme test Uncommented the text_style property in the button theme integration test and updated the golden image to reflect the new button appearance. * Add outlined button theme integration test and docstring Introduces an integration test for OutlinedButton theme, including a golden image for macOS. Also adds a docstring to the outlined_button_theme property in Theme to clarify its purpose. * Add TextButton theme integration test and docstring Introduced a new integration test for TextButton theme, including a golden image for macOS. Added a docstring to the Theme class for text_button_theme to clarify its purpose. Minor comment update in button theme test for color usage. * Add FilledButton theme integration test and docstring Introduces an integration test for FilledButton theme customization, including a golden image for macOS. Also adds a docstring to the filled_button_theme property in Theme to clarify its purpose. * Add IconButton theme support and integration test Introduces icon_button_theme to the Theme class for customizing IconButton appearance. Adds an integration test and golden image to verify IconButton theming on macOS. * Update ExpansionTile tests and theme documentation Renamed and added new golden images for ExpansionTile tests on macOS, updated test function names and added a new test for ExpansionTile properties. Also improved documentation for expansion_tile_theme in Theme class. * Update ExpansionTile properties and golden image Commented out the 'leading' icon, changed 'affinity' from TRAILING to LEADING, and updated the corresponding golden image for the ExpansionTile properties test on macOS. * Update ExpansionTile integration tests and screenshots Replaces the properties1.png screenshot with closed.png and expanded.png for macOS golden images. Refactors test_expansion_tile.py to use per-test flet_app instances, removes the properties1 test, and adds a new expanded state test with updated screenshot logic. * Add ExpansionTile theme tests and update screenshot names Renamed 'closed' screenshot to 'collapsed' in ExpansionTile tests for consistency. Added new integration tests and golden images for ExpansionTileTheme on macOS, including both collapsed and expanded states. Fixed clipBehavior parsing in ExpansionTileControl. * Comment out text_style in button theme tests The text_style property was commented out in button theme integration tests, due to issue #5620. Corresponding golden images were updated to reflect this change. * Add tests and docs for FloatingActionButton location Added new integration tests for FloatingActionButton with center top and end top locations, including corresponding golden images. Improved documentation for floating_action_button_theme in Theme to clarify its purpose. Renamed basic screenshot for consistency. * Add FloatingActionButton property tests and golden images Introduces new integration tests for FloatingActionButton properties, including visual states for elevation, focus, and disabled. Adds corresponding golden images for macOS to validate screenshot outputs. * Add hover state test for FloatingActionButton Introduced a new integration test to verify the hover state of FloatingActionButton on macOS, including screenshot comparison. Additional properties related to hover and feedback were set for more comprehensive coverage. * Refactor FloatingActionButtonTheme property names Renamed 'extended_text_style' to 'text_style' and 'extended_icon_label_spacing' to 'icon_label_spacing' in both Dart and Python implementations for consistency. Updated related documentation and integration tests, and added golden images for macOS FloatingActionButton theme states. * Refactor ListTile tests and update golden images Renamed and expanded ListTile integration tests for better coverage, including new tests for selected, focus, hover, and disabled states. Updated and added corresponding golden images for macOS. Improved docstrings in FloatingActionButtonTheme and Theme to clarify icon and content terminology and added missing docstrings for theme properties. * Enhance ListTile integration tests on macOS Expanded ListTile property coverage in integration tests by adding cases for custom shapes, dense tiles, and content padding. Updated golden images to reflect new test scenarios and improved property combinations for more comprehensive visual validation. * Refactor ListTile splash color property Replaced 'bgcolor_activated' with 'splash_color' in ListTile control for both Dart and Python implementations to improve clarity and consistency. Updated integration tests to cover additional ListTile properties and added new golden images for toggle input scenarios. * Refactor ListTile integration tests and update golden files Split the ListTile properties test into two separate tests, moving several property checks to a new test_properties2 and updating screenshot references to properties_3_normal and properties_3_hover. Added a new golden image and renamed existing ones to match the new test structure. * Update ListTile hover behavior and golden images Refactored ListTile hover color documentation to clarify it only applies when `toggle_inputs` is True. Updated and replaced golden test images for macOS ListTile to reflect new toggle input states and removed obsolete images. * updated tests * Refactor ListTile optional properties and theme key Changed several ListTile properties in Python and Dart from default values to Optional types to allow for unset states. Renamed 'min_tile_height' to 'min_height' in ListTileTheme for consistency, and updated related parsing logic in Dart. * Add ListTile theme integration test and golden image Introduces a new integration test for ListTile theme customization in Flet, including a golden screenshot for macOS. The test verifies various theme properties and ListTile configurations to ensure correct rendering. --------- Co-authored-by: Feodor Fitsner <feodor@appveyor.com>
1 parent 4afd78a commit cbdae3a

66 files changed

Lines changed: 1307 additions & 99 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/flet/lib/src/controls/datatable.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,24 @@ class DataTableControl extends StatelessWidget {
2929
var gradient = control.getGradient("gradient", theme);
3030
var horizontalLines = control.getBorderSide("horizontal_lLines", theme);
3131
var verticalLines = control.getBorderSide("vertical_lines", theme);
32-
var defaultDecoration =
33-
theme.dataTableTheme.decoration ?? const BoxDecoration();
32+
var defaultDecoration = theme.dataTableTheme.decoration as BoxDecoration? ??
33+
const BoxDecoration();
3434

3535
BoxDecoration? decoration;
36+
3637
if (bgcolor != null ||
3738
border != null ||
3839
borderRadius != null ||
3940
gradient != null) {
40-
decoration = (defaultDecoration as BoxDecoration).copyWith(
41+
decoration = defaultDecoration.copyWith(
4142
color: parseColor(bgcolor, theme),
4243
border: border,
4344
borderRadius: borderRadius,
4445
gradient: gradient);
4546
}
4647

4748
var datatable = DataTable(
48-
decoration: decoration,
49+
decoration: decoration ?? defaultDecoration,
4950
border: (horizontalLines != null || verticalLines != null)
5051
? TableBorder(
5152
horizontalInside: horizontalLines ?? BorderSide.none,

packages/flet/lib/src/controls/dropdown.dart

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ class _DropdownControlState extends State<DropdownControl> {
8181
widget.control.getColor("focused_border_color", context);
8282
var borderWidth = widget.control.getDouble("border_width");
8383
var focusedBorderWidth = widget.control.getDouble("focused_border_width");
84-
var menuWidth = widget.control.getDouble("menu_width", double.infinity)!;
84+
var menuWidth = widget.control.getDouble("menu_width");
85+
var bgColor = widget.control.getWidgetStateColor("bgcolor", theme);
86+
var elevation = widget.control.getWidgetStateDouble("elevation");
8587

8688
FormFieldInputBorder inputBorder = widget.control
8789
.getFormFieldInputBorder("border", FormFieldInputBorder.outline)!;
@@ -148,8 +150,30 @@ class _DropdownControlState extends State<DropdownControl> {
148150

149151
TextStyle? textStyle = widget.control.getTextStyle("text_style", theme);
150152
if (textSize != null || color != null) {
151-
textStyle = (textStyle ?? const TextStyle()).copyWith(
152-
fontSize: textSize, color: color ?? theme.colorScheme.onSurface);
153+
textStyle =
154+
(textStyle ?? theme.dropdownMenuTheme.textStyle ?? const TextStyle())
155+
.copyWith(
156+
fontSize: textSize,
157+
color: color ?? theme.colorScheme.onSurface);
158+
}
159+
160+
MenuStyle? menuStyle = widget.control.getMenuStyle("menu_style", theme);
161+
if (bgColor != null || elevation != null || menuWidth != null) {
162+
menuStyle =
163+
(menuStyle ?? theme.dropdownMenuTheme.menuStyle ?? const MenuStyle())
164+
.copyWith(
165+
backgroundColor: bgColor,
166+
elevation: elevation,
167+
fixedSize: WidgetStateProperty.all(
168+
Size.fromWidth(menuWidth ?? double.infinity)));
169+
}
170+
171+
if (textSize != null || color != null) {
172+
textStyle =
173+
(textStyle ?? theme.dropdownMenuTheme.textStyle ?? const TextStyle())
174+
.copyWith(
175+
fontSize: textSize,
176+
color: color ?? theme.colorScheme.onSurface);
153177
}
154178

155179
var items = widget.control
@@ -213,11 +237,12 @@ class _DropdownControlState extends State<DropdownControl> {
213237
errorText: widget.control.getString("error_text"),
214238
hintText: widget.control.getString("hint_text"),
215239
helperText: widget.control.getString("helper_text"),
216-
menuStyle: MenuStyle(
217-
backgroundColor: widget.control.getWidgetStateColor("bgcolor", theme),
218-
elevation: widget.control.getWidgetStateDouble("elevation"),
219-
fixedSize: WidgetStateProperty.all(Size.fromWidth(menuWidth)),
220-
),
240+
// menuStyle: MenuStyle(
241+
// backgroundColor: widget.control.getWidgetStateColor("bgcolor", theme),
242+
// elevation: widget.control.getWidgetStateDouble("elevation"),
243+
// fixedSize: WidgetStateProperty.all(Size.fromWidth(menuWidth)),
244+
// ),
245+
menuStyle: menuStyle,
221246
inputDecorationTheme: inputDecorationTheme,
222247
onSelected: widget.control.disabled
223248
? null

packages/flet/lib/src/controls/expansion_tile.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class ExpansionTileControl extends StatelessWidget {
5252

5353
var affinity = control.getListTileControlAffinity(
5454
"affinity", ListTileControlAffinity.platform)!;
55-
var clipBehavior =
56-
parseClip(control.getString("clip_behavior"), Clip.none)!;
55+
var clipBehavior = parseClip(control.getString("clip_behavior"));
5756

5857
var expandedCrossAxisAlignment = control.getCrossAxisAlignment(
5958
"expanded_cross_axis_alignment", CrossAxisAlignment.center)!;

packages/flet/lib/src/controls/list_tile.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class ListTileControl extends StatelessWidget with FletStoreMixin {
7474
Widget tile = ListTile(
7575
autofocus: control.getBool("autofocus", false)!,
7676
contentPadding: control.getPadding("content_padding"),
77-
isThreeLine: control.getBool("is_three_line", false)!,
77+
isThreeLine: control.getBool("is_three_line"),
7878
selected: control.getBool("selected", false)!,
79-
dense: control.getBool("dense", false)!,
79+
dense: control.getBool("dense"),
8080
onTap: onPressed,
8181
onLongPress: onLongPress,
8282
enabled: !control.disabled,
@@ -89,7 +89,7 @@ class ListTileControl extends StatelessWidget with FletStoreMixin {
8989
selectedColor: control.getColor("selected_color", context),
9090
focusColor: control.getColor("focus_color", context),
9191
tileColor: control.getColor("bgcolor", context),
92-
splashColor: control.getColor("bgcolor_activated", context),
92+
splashColor: control.getColor("splash_color", context),
9393
hoverColor: control.getColor("hover_color", context),
9494
iconColor: control.getColor("icon_color", context),
9595
textColor: control.getColor("text_color", context),

packages/flet/lib/src/utils/theme.dart

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,21 @@ ThemeData parseTheme(
9494
{ThemeData? parentTheme}) {
9595
ThemeData? theme = parentTheme;
9696

97-
var primarySwatch = parseColor(value?["primary_swatch"], theme);
98-
var colorSchemeSeed = parseColor(value?["color_scheme_seed"], theme);
99-
100-
if (colorSchemeSeed != null) primarySwatch = null;
101-
102-
if (colorSchemeSeed == null && primarySwatch == null) {
103-
colorSchemeSeed = Colors.blue;
104-
}
97+
var colorSchemeSeed =
98+
parseColor(value?["color_scheme_seed"], theme) ?? Colors.blue;
10599

106100
// create new theme
107101
theme ??= ThemeData(
108-
primarySwatch:
109-
primarySwatch != null ? primarySwatch as MaterialColor : null,
110102
colorSchemeSeed: colorSchemeSeed,
111103
fontFamily: value?["font_family"],
112104
brightness: brightness,
113-
useMaterial3: value?["use_material3"] ?? primarySwatch == null,
105+
useMaterial3: value?["use_material3"],
114106
);
115107

108+
ColorScheme? colorScheme = parseColorScheme(value?["color_scheme"], theme);
109+
DividerThemeData? dividerTheme =
110+
parseDividerTheme(value?["divider_theme"], theme);
111+
116112
theme = theme.copyWith(
117113
extensions: {
118114
SystemUiOverlayStyleTheme(value?["system_overlay_style"] != null
@@ -124,7 +120,7 @@ ThemeData parseTheme(
124120
parseVisualDensity(value?["visual_density"], theme.visualDensity)!,
125121
pageTransitionsTheme: parsePageTransitions(
126122
value?["page_transitions"], theme.pageTransitionsTheme)!,
127-
colorScheme: parseColorScheme(value?["color_scheme"], theme),
123+
colorScheme: colorScheme,
128124
textTheme: parseTextTheme(value?["text_theme"], theme, theme.textTheme),
129125
primaryTextTheme: parseTextTheme(
130126
value?["primary_text_theme"], theme, theme.primaryTextTheme),
@@ -140,13 +136,10 @@ ThemeData parseTheme(
140136
canvasColor: parseColor(value?["canvas_color"], theme),
141137
scaffoldBackgroundColor: parseColor(value?["scaffold_bgcolor"], theme),
142138
cardColor: parseColor(value?["card_bgcolor"], theme),
143-
dividerColor: parseColor(value?["divider_color"], theme),
139+
dividerColor: dividerTheme?.color,
144140
hintColor: parseColor(value?["hint_color"], theme),
145-
shadowColor: parseColor(value?["shadow_color"], theme),
141+
shadowColor: colorScheme?.shadow,
146142
secondaryHeaderColor: parseColor(value?["secondary_header_color"], theme),
147-
primaryColor: parseColor(value?["primary_color"], theme),
148-
primaryColorLight: parseColor(value?["primary_color_light"], theme),
149-
primaryColorDark: parseColor(value?["primary_color_dark"], theme),
150143
dialogTheme: parseDialogTheme(value?["dialog_theme"], theme),
151144
bottomSheetTheme:
152145
parseBottomSheetTheme(value?["bottom_sheet_theme"], theme),
@@ -160,15 +153,14 @@ ThemeData parseTheme(
160153
radioTheme: parseRadioTheme(value?["radio_theme"], theme),
161154
badgeTheme: parseBadgeTheme(value?["badge_theme"], theme),
162155
switchTheme: parseSwitchTheme(value?["switch_theme"], context),
163-
dividerTheme: parseDividerTheme(value?["divider_theme"], theme),
156+
dividerTheme: dividerTheme,
164157
snackBarTheme: parseSnackBarTheme(value?["snackbar_theme"], theme),
165158
bannerTheme: parseBannerTheme(value?["banner_theme"], theme),
166159
datePickerTheme: parseDatePickerTheme(value?["date_picker_theme"], theme),
167160
navigationRailTheme:
168161
parseNavigationRailTheme(value?["navigation_rail_theme"], theme),
169162
appBarTheme: parseAppBarTheme(value?["appbar_theme"], theme),
170-
dropdownMenuTheme:
171-
parseDropdownMenuTheme(value?["dropdown_menu_theme"], theme),
163+
dropdownMenuTheme: parseDropdownMenuTheme(value?["dropdown_theme"], theme),
172164
listTileTheme: parseListTileTheme(value?["list_tile_theme"], theme),
173165
tooltipTheme: parseTooltipTheme(value?["tooltip_theme"], context),
174166
expansionTileTheme:
@@ -538,8 +530,8 @@ FloatingActionButtonThemeData? parseFloatingActionButtonTheme(
538530
shape: parseShape(value["shape"], theme),
539531
enableFeedback: parseBool(value["enable_feedback"]),
540532
extendedPadding: parsePadding(value["extended_padding"]),
541-
extendedTextStyle: parseTextStyle(value["extended_text_style"], theme),
542-
extendedIconLabelSpacing: parseDouble(value["extended_icon_label_spacing"]),
533+
extendedTextStyle: parseTextStyle(value["text_style"], theme),
534+
extendedIconLabelSpacing: parseDouble(value["icon_label_spacing"]),
543535
mouseCursor: parseWidgetStateMouseCursor(value["mouse_cursor"]),
544536
iconSize: parseDouble(value["icon_size"]),
545537
extendedSizeConstraints:
@@ -858,7 +850,7 @@ ListTileThemeData? parseListTileTheme(
858850
leadingAndTrailingTextStyle:
859851
parseTextStyle(value["leading_and_trailing_text_style"], theme),
860852
mouseCursor: parseWidgetStateMouseCursor(value["mouse_cursor"]),
861-
minTileHeight: parseDouble(value["min_tile_height"]),
853+
minTileHeight: parseDouble(value["min_height"]),
862854
);
863855
}
864856

1.83 KB
9.61 KB
Binary file not shown.
24.7 KB
319 Bytes

0 commit comments

Comments
 (0)