Skip to content

Commit

Permalink
Fix button styles crashing UI
Browse files Browse the repository at this point in the history
Fix #1390
  • Loading branch information
FeodorFitsner committed May 12, 2023
1 parent 46c522c commit 4230cbc
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
6 changes: 1 addition & 5 deletions client/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ void main([List<String>? args]) async {
//debugPrint("Uri.base: ${Uri.base}");

if (kDebugMode) {
if (kIsWeb) {
pageUrl = "http://localhost:8550";
} else {
pageUrl = "tcp://localhost:8550";
}
pageUrl = "http://localhost:8550";
}

if (kIsWeb) {
Expand Down
2 changes: 0 additions & 2 deletions package/lib/src/utils/material_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import 'package:flutter/material.dart';

MaterialStateProperty<T?>? getMaterialStateProperty<T>(dynamic jsonDictValue,
T Function(dynamic) converterFromJson, T defaultValue) {
debugPrint("jsonDictValue: $jsonDictValue");
if (jsonDictValue == null) {
return null;
}
var j = jsonDictValue;
if (j is! Map<String, dynamic>) {
j = {"": j};
debugPrint("jsonDictValue DICT: $j");
}
return MaterialStateFromJSON(j, converterFromJson, defaultValue);
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ def _convert_attr_json(self, value):
else None
)

def _wrap_attr_dict(self, value):
if value is None or isinstance(value, Dict):
return value
return {"": value}

def __str__(self):
attrs = {}
for k, v in self.__attrs.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def _before_build_command(self):
self.__style.bgcolor = self.__bgcolor
if self.__style.elevation != self.__elevation:
self.__style.elevation = self.__elevation
if self.__style is not None:
self.__style.side = self._wrap_attr_dict(self.__style.side)
self.__style.shape = self._wrap_attr_dict(self.__style.shape)
self._set_attr_json("style", self.__style)

def _get_children(self):
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/icon_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def _get_control_name(self):

def _before_build_command(self):
super()._before_build_command()
if self.__style is not None:
self.__style.side = self._wrap_attr_dict(self.__style.side)
self.__style.shape = self._wrap_attr_dict(self.__style.shape)
self._set_attr_json("style", self.__style)

def _get_children(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def _get_control_name(self):

def _before_build_command(self):
super()._before_build_command()
if self.__style is not None:
self.__style.side = self._wrap_attr_dict(self.__style.side)
self.__style.shape = self._wrap_attr_dict(self.__style.shape)
self._set_attr_json("style", self.__style)

def _get_children(self):
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/text_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def _get_control_name(self):

def _before_build_command(self):
super()._before_build_command()
if self.__style is not None:
self.__style.side = self._wrap_attr_dict(self.__style.side)
self.__style.shape = self._wrap_attr_dict(self.__style.shape)
self._set_attr_json("style", self.__style)

def _get_children(self):
Expand Down

0 comments on commit 4230cbc

Please sign in to comment.