Skip to content

Commit

Permalink
Theme Enhancement (flet-dev#2955)
Browse files Browse the repository at this point in the history
* initial commit

* HexColor.fromString default value

* Cleanup + Reformat

* TimePickerTheme

* MouseCursor moved to types

---------

Co-authored-by: Feodor Fitsner <feodor@appveyor.com>
  • Loading branch information
2 people authored and zrr1999 committed Jul 17, 2024
1 parent 3aa4b2f commit 2c79c25
Show file tree
Hide file tree
Showing 22 changed files with 1,712 additions and 164 deletions.
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

0 comments on commit 2c79c25

Please sign in to comment.