-
Couldn't load subscription status.
- Fork 586
Added Container.blur and Container.shadow properties
#1076
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
Changes from all commits
81a4b1c
ebf1463
fdef401
75cd15f
d655440
469f438
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import '../models/control.dart'; | ||
| import '../utils/numbers.dart'; | ||
| import '../utils/transforms.dart'; | ||
| import 'colors.dart'; | ||
|
|
||
| List<BoxShadow> parseBoxShadow( | ||
| ThemeData theme, Control control, String propName) { | ||
| var v = control.attrString(propName, null); | ||
| if (v == null) { | ||
| return []; | ||
| } | ||
|
|
||
| final j1 = json.decode(v); | ||
| return boxShadowsFromJSON(theme, j1); | ||
| } | ||
|
|
||
| List<BoxShadow> boxShadowsFromJSON(ThemeData theme, dynamic json) { | ||
| if (json is List) { | ||
| return json.map((e) => boxShadowFromJSON(theme, e)).toList(); | ||
| } else { | ||
| return [boxShadowFromJSON(theme, json)]; | ||
| } | ||
| } | ||
|
|
||
| BoxShadow boxShadowFromJSON(ThemeData theme, dynamic json) { | ||
| var offset = json["offset"] != null ? offsetFromJSON(json["offset"]) : null; | ||
| return BoxShadow( | ||
| color: json["color"] != null | ||
| ? HexColor.fromString(theme, json["color"]) ?? const Color(0xFF000000) | ||
| : const Color(0xFF000000), | ||
| offset: offset != null ? Offset(offset.x, offset.y) : Offset.zero, | ||
| blurStyle: json["blur_style"] != null | ||
| ? BlurStyle.values | ||
| .firstWhere((e) => e.name.toLowerCase() == json["blur_style"]) | ||
| : BlurStyle.normal, | ||
| blurRadius: | ||
| json["blur_radius"] != null ? parseDouble(json["blur_radius"]) : 0.0, | ||
| spreadRadius: json["spread_radius"] != null | ||
| ? parseDouble(json["spread_radius"]) | ||
| : 0.0); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| import dataclasses | ||
| import json | ||
| from typing import Any, Optional, Union | ||
| from dataclasses import field | ||
| from enum import Enum | ||
| from typing import Any, List, Optional, Tuple, Union | ||
|
|
||
| from flet_core.alignment import Alignment | ||
| from flet_core.border import Border | ||
|
|
@@ -35,6 +38,36 @@ | |
| from typing_extensions import Literal | ||
|
|
||
|
|
||
| class BlurTileMode(Enum): | ||
| CLAMP = "clamp" | ||
| DECAL = "decal" | ||
| MIRROR = "mirror" | ||
| REPEATED = "repeated" | ||
|
|
||
|
|
||
| class ShadowBlurStyle(Enum): | ||
| NORMAL = "normal" | ||
| SOLID = "solid" | ||
| OUTER = "outer" | ||
| INNER = "inner" | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class Blur: | ||
| sigma_x: float | ||
| sigma_y: float | ||
|
Comment on lines
+57
to
+58
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. Why only |
||
| tile_mode: BlurTileMode = field(default=BlurTileMode.CLAMP) | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class BoxShadow: | ||
| spread_radius: Optional[float] = field(default=None) | ||
| blur_radius: Optional[float] = field(default=None) | ||
|
Comment on lines
+64
to
+65
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. Same here. |
||
| color: Optional[str] = field(default=None) | ||
| offset: OffsetValue = field(default=None) | ||
| tile_mode: ShadowBlurStyle = field(default=ShadowBlurStyle.NORMAL) | ||
FeodorFitsner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class Container(ConstrainedControl): | ||
| """ | ||
| Container allows to decorate a control with background color and border and position it with padding, margin and alignment. | ||
|
|
@@ -110,6 +143,10 @@ def __init__( | |
| clip_behavior: Optional[ClipBehavior] = None, | ||
| ink: Optional[bool] = None, | ||
| animate: AnimationValue = None, | ||
| blur: Union[ | ||
| None, float, int, Tuple[Union[float, int], Union[float, int]], Blur | ||
| ] = None, | ||
| shadow: Union[None, BoxShadow, List[BoxShadow]] = None, | ||
| on_click=None, | ||
| on_long_press=None, | ||
| on_hover=None, | ||
|
|
@@ -168,6 +205,8 @@ def convert_container_tap_event_data(e): | |
| self.clip_behavior = clip_behavior | ||
| self.ink = ink | ||
| self.animate = animate | ||
| self.blur = blur | ||
| self.shadow = shadow | ||
| self.on_click = on_click | ||
| self.on_long_press = on_long_press | ||
| self.on_hover = on_hover | ||
|
|
@@ -184,6 +223,8 @@ def _before_build_command(self): | |
| self._set_attr_json("alignment", self.__alignment) | ||
| self._set_attr_json("gradient", self.__gradient) | ||
| self._set_attr_json("animate", self.__animate) | ||
| self._set_attr_json("blur", self.__blur) | ||
| self._set_attr_json("shadow", self.__shadow if self.__shadow else None) | ||
|
|
||
| def _get_children(self): | ||
| children = [] | ||
|
|
@@ -258,6 +299,29 @@ def blend_mode(self, value: BlendMode): | |
| def __set_blend_mode(self, value: BlendModeString): | ||
| self._set_attr("blendMode", value) | ||
|
|
||
| # blur | ||
| @property | ||
| def blur(self): | ||
| return self.__blur | ||
|
|
||
| @blur.setter | ||
| def blur( | ||
| self, | ||
| value: Union[ | ||
| None, float, int, Tuple[Union[float, int], Union[float, int]], Blur | ||
| ], | ||
| ): | ||
| self.__blur = value | ||
|
|
||
| # shadow | ||
| @property | ||
| def shadow(self): | ||
| return self.__shadow | ||
|
|
||
| @shadow.setter | ||
| def shadow(self, value: Union[None, BoxShadow, List[BoxShadow]]): | ||
| self.__shadow = value if value is not None else [] | ||
|
|
||
| # border | ||
| @property | ||
| def border(self) -> Optional[Border]: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.