Skip to content
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

Theme Enhancement #2955

Merged
merged 6 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/flet/lib/src/controls/tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ class _TabsControlState extends State<TabsControl>
overlayColor = getMaterialStateProperty<Color?>(
json.decode(overlayColorStr),
(jv) =>
HexColor.fromString(Theme.of(context), jv as String),
null) ??
HexColor.fromString(Theme.of(context), jv as String)) ??
TabBarTheme.of(context).overlayColor;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/flet/lib/src/utils/borders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ BorderRadius borderRadiusFromJSON(dynamic json) {
);
}

Border borderFromJSON(
ThemeData? theme, Map<String, dynamic> json, Color? defaultSideColor) {
Border borderFromJSON(ThemeData? theme, Map<String, dynamic> json,
[Color? defaultSideColor]) {
return Border(
top: borderSideFromJSON(theme, json['t'], defaultSideColor) ??
BorderSide.none,
Expand All @@ -82,8 +82,8 @@ Border borderFromJSON(
BorderSide.none);
}

BorderSide? borderSideFromJSON(
ThemeData? theme, dynamic json, Color? defaultSideColor) {
BorderSide? borderSideFromJSON(ThemeData? theme, dynamic json,
[Color? defaultSideColor]) {
return json != null
? BorderSide(
color: json['c'] != null
Expand Down
22 changes: 10 additions & 12 deletions packages/flet/lib/src/utils/buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ ButtonStyle? parseButtonStyle(ThemeData theme, Control control, String propName,
defaultShape);
}

ButtonStyle? buttonStyleFromJSON(
ThemeData theme,
Map<String, dynamic> json,
Color defaultForegroundColor,
Color defaultBackgroundColor,
Color defaultOverlayColor,
Color defaultShadowColor,
Color defaultSurfaceTintColor,
double defaultElevation,
EdgeInsets defaultPadding,
BorderSide defaultBorderSide,
OutlinedBorder defaultShape) {
ButtonStyle? buttonStyleFromJSON(ThemeData theme, Map<String, dynamic> json,
[Color? defaultForegroundColor,
Color? defaultBackgroundColor,
Color? defaultOverlayColor,
Color? defaultShadowColor,
Color? defaultSurfaceTintColor,
double? defaultElevation,
EdgeInsets? defaultPadding,
BorderSide? defaultBorderSide,
OutlinedBorder? defaultShape]) {
return ButtonStyle(
foregroundColor: getMaterialStateProperty<Color?>(
json["color"],
Expand Down
4 changes: 2 additions & 2 deletions packages/flet/lib/src/utils/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Map<String, MaterialAccentColor> _materialAccentColors = {

// https://stackoverflow.com/questions/50081213/how-do-i-use-hexadecimal-color-strings-in-flutter
extension HexColor on Color {
static Color? fromString(ThemeData? theme, String colorString) {
static Color? fromString(ThemeData? theme, [String colorString = ""]) {
var colorParts = colorString.split(",");

var colorValue = colorParts[0];
Expand Down Expand Up @@ -245,5 +245,5 @@ MaterialStateProperty<Color?>? parseMaterialStateColor(

final j1 = json.decode(v);
return getMaterialStateProperty<Color?>(
j1, (jv) => HexColor.fromString(theme, jv as String), null);
j1, (jv) => HexColor.fromString(theme, jv as String));
}
2 changes: 1 addition & 1 deletion packages/flet/lib/src/utils/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ MaterialStateProperty<Icon?>? parseMaterialStateIcon(
final j1 = json.decode(v);

return getMaterialStateProperty<Icon?>(
j1, (jv) => Icon(parseIcon(jv as String)), null);
j1, (jv) => Icon(parseIcon(jv as String)));
}
8 changes: 4 additions & 4 deletions packages/flet/lib/src/utils/material_state.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

MaterialStateProperty<T?>? getMaterialStateProperty<T>(dynamic jsonDictValue,
T Function(dynamic) converterFromJson, T defaultValue) {
MaterialStateProperty<T?>? getMaterialStateProperty<T>(dynamic jsonDictValue, T Function(dynamic) converterFromJson,
[T? defaultValue]) {
if (jsonDictValue == null) {
return null;
}
Expand All @@ -14,9 +14,9 @@ MaterialStateProperty<T?>? getMaterialStateProperty<T>(dynamic jsonDictValue,

class MaterialStateFromJSON<T> extends MaterialStateProperty<T?> {
late final Map<String, T> _states;
late final T _defaultValue;
late final T? _defaultValue;
MaterialStateFromJSON(Map<String, dynamic>? jsonDictValue,
T Function(dynamic) converterFromJson, T defaultValue) {
T Function(dynamic) converterFromJson, T? defaultValue) {
_defaultValue = defaultValue;
_states = {};
if (jsonDictValue != null) {
Expand Down
8 changes: 3 additions & 5 deletions packages/flet/lib/src/utils/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,16 @@ MenuStyle? parseMenuStyle(ThemeData theme, Control control, String propName,
defaultShape);
}

MenuStyle? menuStyleFromJSON(
ThemeData theme,
Map<String, dynamic> json,
Color? defaultBackgroundColor,
MenuStyle? menuStyleFromJSON(ThemeData theme, Map<String, dynamic> json,
[Color? defaultBackgroundColor,
Color? defaultShadowColor,
Color? defaultSurfaceTintColor,
double? defaultElevation,
Alignment? defaultAlignment,
MouseCursor? defaultMouseCursor,
EdgeInsets? defaultPadding,
BorderSide? defaultBorderSide,
OutlinedBorder? defaultShape) {
OutlinedBorder? defaultShape]) {
return MenuStyle(
alignment: json["alignment"] != null
? alignmentFromJson(json["alignment"])
Expand Down
Loading