-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b70802
commit 03548c5
Showing
7 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../models/control.dart'; | ||
import '../utils/edge_insets.dart'; | ||
import 'create_control.dart'; | ||
|
||
class CardControl extends StatelessWidget { | ||
final Control? parent; | ||
final Control control; | ||
final List<Control> children; | ||
final bool parentDisabled; | ||
|
||
const CardControl( | ||
{Key? key, | ||
this.parent, | ||
required this.control, | ||
required this.children, | ||
required this.parentDisabled}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
debugPrint("Card build: ${control.id}"); | ||
|
||
var contentCtrls = | ||
children.where((c) => c.name == "content" && c.isVisible); | ||
bool disabled = control.isDisabled || parentDisabled; | ||
|
||
return constrainedControl( | ||
Card( | ||
elevation: control.attrDouble("elevation"), | ||
margin: parseEdgeInsets(control, "margin"), | ||
child: contentCtrls.isNotEmpty | ||
? createControl(control, contentCtrls.first.id, disabled) | ||
: null), | ||
parent, | ||
control); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from typing import Optional, Union | ||
|
||
from beartype import beartype | ||
|
||
from flet import border_radius, margin, padding | ||
from flet.alignment import Alignment | ||
from flet.border import Border | ||
from flet.border_radius import BorderRadius | ||
from flet.constrained_control import ConstrainedControl | ||
from flet.control import BorderStyle, Control, MarginValue, OptionalNumber, PaddingValue | ||
from flet.ref import Ref | ||
|
||
try: | ||
from typing import Literal | ||
except: | ||
from typing_extensions import Literal | ||
|
||
|
||
class Card(ConstrainedControl): | ||
def __init__( | ||
self, | ||
ref: Ref = None, | ||
width: OptionalNumber = None, | ||
height: OptionalNumber = None, | ||
expand: Union[bool, int] = None, | ||
opacity: OptionalNumber = None, | ||
tooltip: str = None, | ||
visible: bool = None, | ||
disabled: bool = None, | ||
data: any = None, | ||
# | ||
# Specific | ||
# | ||
content: Control = None, | ||
margin: MarginValue = None, | ||
elevation: OptionalNumber = None, | ||
): | ||
ConstrainedControl.__init__( | ||
self, | ||
ref=ref, | ||
width=width, | ||
height=height, | ||
expand=expand, | ||
opacity=opacity, | ||
tooltip=tooltip, | ||
visible=visible, | ||
disabled=disabled, | ||
data=data, | ||
) | ||
|
||
self.content = content | ||
self.margin = margin | ||
self.elevation = elevation | ||
|
||
def _get_control_name(self): | ||
return "card" | ||
|
||
def _get_children(self): | ||
children = [] | ||
if self.__content != None: | ||
self.__content._set_attr_internal("n", "content") | ||
children.append(self.__content) | ||
return children | ||
|
||
# margin | ||
@property | ||
def margin(self): | ||
return self.__margin | ||
|
||
@margin.setter | ||
@beartype | ||
def margin(self, value: MarginValue): | ||
self.__margin = value | ||
if value and isinstance(value, (int, float)): | ||
value = margin.all(value) | ||
self._set_attr_json("margin", value) | ||
|
||
# elevation | ||
@property | ||
def elevation(self) -> OptionalNumber: | ||
return self._get_attr("elevation") | ||
|
||
@elevation.setter | ||
@beartype | ||
def elevation(self, value: OptionalNumber): | ||
self._set_attr("elevation", value) | ||
|
||
# content | ||
@property | ||
def content(self): | ||
return self.__content | ||
|
||
@content.setter | ||
@beartype | ||
def content(self, value: Optional[Control]): | ||
self.__content = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
from typing import Optional, Union | ||
|
||
from beartype import beartype | ||
|
||
from flet import padding | ||
from flet.constrained_control import ConstrainedControl | ||
from flet.control import Control, OptionalNumber, PaddingValue | ||
from flet.ref import Ref | ||
|
||
|
||
class ListTile(ConstrainedControl): | ||
def __init__( | ||
self, | ||
text: str = None, | ||
ref: Ref = None, | ||
width: OptionalNumber = None, | ||
height: OptionalNumber = None, | ||
expand: Union[bool, int] = None, | ||
opacity: OptionalNumber = None, | ||
tooltip: str = None, | ||
visible: bool = None, | ||
disabled: bool = None, | ||
data: any = None, | ||
# | ||
# Specific | ||
# | ||
content_padding: PaddingValue = None, | ||
leading: Control = None, | ||
title: Control = None, | ||
subtitle: Control = None, | ||
trailing: Control = None, | ||
is_three_line: bool = None, | ||
selected: bool = None, | ||
autofocus: bool = None, | ||
on_click=None, | ||
): | ||
ConstrainedControl.__init__( | ||
self, | ||
ref=ref, | ||
width=width, | ||
height=height, | ||
expand=expand, | ||
opacity=opacity, | ||
tooltip=tooltip, | ||
visible=visible, | ||
disabled=disabled, | ||
data=data, | ||
) | ||
|
||
self.content_padding = content_padding | ||
self.leading = leading | ||
self.title = title | ||
self.subtitle = subtitle | ||
self.trailing = trailing | ||
self.is_three_line = is_three_line | ||
self.selected = selected | ||
self.autofocus = autofocus | ||
self.on_click = on_click | ||
|
||
def _get_control_name(self): | ||
return "listtile" | ||
|
||
def _get_children(self): | ||
children = [] | ||
if self.__leading: | ||
self.__leading._set_attr_internal("n", "leading") | ||
children.append(self.__leading) | ||
if self.__title: | ||
self.__title._set_attr_internal("n", "title") | ||
children.append(self.__title) | ||
if self.__subtitle: | ||
self.__subtitle._set_attr_internal("n", "subtitle") | ||
children.append(self.__subtitle) | ||
if self.__trailing: | ||
self.__trailing._set_attr_internal("n", "trailing") | ||
children.append(self.__trailing) | ||
return children | ||
|
||
# content_padding | ||
@property | ||
def content_padding(self): | ||
return self.__content_padding | ||
|
||
@content_padding.setter | ||
@beartype | ||
def content_padding(self, value: PaddingValue): | ||
self.__content_padding = value | ||
if value and isinstance(value, (int, float)): | ||
value = padding.all(value) | ||
self._set_attr_json("contentPadding", value) | ||
|
||
# leading | ||
@property | ||
def leading(self): | ||
return self.__leading | ||
|
||
@leading.setter | ||
@beartype | ||
def leading(self, value: Optional[Control]): | ||
self.__leading = value | ||
|
||
# title | ||
@property | ||
def title(self): | ||
return self.__title | ||
|
||
@title.setter | ||
@beartype | ||
def title(self, value: Optional[Control]): | ||
self.__title = value | ||
|
||
# subtitle | ||
@property | ||
def subtitle(self): | ||
return self.__subtitle | ||
|
||
@subtitle.setter | ||
@beartype | ||
def subtitle(self, value: Optional[Control]): | ||
self.__subtitle = value | ||
|
||
# trailing | ||
@property | ||
def trailing(self): | ||
return self.__trailing | ||
|
||
@trailing.setter | ||
@beartype | ||
def trailing(self, value: Optional[Control]): | ||
self.__trailing = value | ||
|
||
# is_three_line | ||
@property | ||
def is_three_line(self): | ||
return self._get_attr("isThreeLine", data_type="bool", def_value=False) | ||
|
||
@is_three_line.setter | ||
@beartype | ||
def is_three_line(self, value: Optional[bool]): | ||
self._set_attr("isThreeLine", value) | ||
|
||
# selected | ||
@property | ||
def selected(self): | ||
return self._get_attr("selected", data_type="bool", def_value=False) | ||
|
||
@selected.setter | ||
@beartype | ||
def selected(self, value: Optional[bool]): | ||
self._set_attr("selected", value) | ||
|
||
# autofocus | ||
@property | ||
def autofocus(self): | ||
return self._get_attr("autofocus", data_type="bool", def_value=False) | ||
|
||
@autofocus.setter | ||
@beartype | ||
def autofocus(self, value: Optional[bool]): | ||
self._set_attr("autofocus", value) | ||
|
||
# on_click | ||
@property | ||
def on_click(self): | ||
return self._get_event_handler("click") | ||
|
||
@on_click.setter | ||
def on_click(self, handler): | ||
self._add_event_handler("click", handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import flet | ||
from flet import Card, Container, Text | ||
|
||
|
||
def main(page): | ||
page.title = "Card Examples" | ||
# page.theme_mode = "dark" | ||
page.add( | ||
Card( | ||
content=Container( | ||
content=Text("A regular card with padded content"), padding=10 | ||
), | ||
margin=0, | ||
), | ||
Card( | ||
content=Container(content=Text("A card with custom elevation"), padding=10), | ||
elevation=5, | ||
), | ||
) | ||
|
||
|
||
flet.app(name="test1", port=8550, target=main, view=flet.WEB_BROWSER) |