-
Notifications
You must be signed in to change notification settings - Fork 489
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
8a2f30e
commit 21c95c7
Showing
9 changed files
with
295 additions
and
8 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,50 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../models/control.dart'; | ||
import '../utils/colors.dart'; | ||
import 'create_control.dart'; | ||
|
||
class CircleAvatarControl extends StatelessWidget { | ||
final Control? parent; | ||
final Control control; | ||
final List<Control> children; | ||
final bool parentDisabled; | ||
|
||
const CircleAvatarControl( | ||
{Key? key, | ||
this.parent, | ||
required this.control, | ||
required this.children, | ||
required this.parentDisabled}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
debugPrint("CircleAvatar build: ${control.id}"); | ||
|
||
bool disabled = control.isDisabled || parentDisabled; | ||
var foregroundImageUrl = control.attrString("foregroundImageUrl"); | ||
var backgroundImageUrl = control.attrString("backgroundImageUrl"); | ||
var contentCtrls = children.where((c) => c.name == "content"); | ||
|
||
var avatar = CircleAvatar( | ||
foregroundImage: foregroundImageUrl != null | ||
? NetworkImage(foregroundImageUrl) | ||
: null, | ||
backgroundImage: backgroundImageUrl != null | ||
? NetworkImage(backgroundImageUrl) | ||
: null, | ||
backgroundColor: | ||
HexColor.fromString(context, control.attrString("bgColor", "")!), | ||
foregroundColor: | ||
HexColor.fromString(context, control.attrString("color", "")!), | ||
radius: control.attrDouble("radius"), | ||
minRadius: control.attrDouble("minRadius"), | ||
maxRadius: control.attrDouble("maxRadius"), | ||
child: contentCtrls.isNotEmpty | ||
? createControl(control, contentCtrls.first.id, disabled) | ||
: null); | ||
|
||
return constrainedControl(avatar, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ enum ControlType { | |
alertDialog, | ||
banner, | ||
checkbox, | ||
circleAvatar, | ||
clipboard, | ||
column, | ||
container, | ||
|
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,146 @@ | ||
from typing import Optional | ||
|
||
from beartype import beartype | ||
|
||
from flet.constrained_control import ConstrainedControl | ||
from flet.control import Control, OptionalNumber | ||
from flet.ref import Ref | ||
|
||
|
||
class CircleAvatar(ConstrainedControl): | ||
def __init__( | ||
self, | ||
icon: str = None, | ||
ref: Ref = None, | ||
width: OptionalNumber = None, | ||
height: OptionalNumber = None, | ||
expand: int = None, | ||
opacity: OptionalNumber = None, | ||
tooltip: str = None, | ||
visible: bool = None, | ||
disabled: bool = None, | ||
data: any = None, | ||
# | ||
# Specific | ||
# | ||
foreground_image_url: str = None, | ||
background_image_url: str = None, | ||
radius: OptionalNumber = None, | ||
min_radius: OptionalNumber = None, | ||
max_radius: OptionalNumber = None, | ||
color: str = None, | ||
bgcolor: str = None, | ||
content: Control = None, | ||
): | ||
ConstrainedControl.__init__( | ||
self, | ||
ref=ref, | ||
width=width, | ||
height=height, | ||
expand=expand, | ||
opacity=opacity, | ||
tooltip=tooltip, | ||
visible=visible, | ||
disabled=disabled, | ||
data=data, | ||
) | ||
|
||
self.foreground_image_url = foreground_image_url | ||
self.background_image_url = background_image_url | ||
self.radius = radius | ||
self.min_radius = min_radius | ||
self.max_radius = max_radius | ||
self.color = color | ||
self.bgcolor = bgcolor | ||
self.content = content | ||
|
||
def _get_control_name(self): | ||
return "circleavatar" | ||
|
||
def _get_children(self): | ||
if self.__content == None: | ||
return [] | ||
self.__content._set_attr_internal("n", "content") | ||
return [self.__content] | ||
|
||
# foreground_image_url | ||
@property | ||
def foreground_image_url(self): | ||
return self._get_attr("foregroundImageUrl") | ||
|
||
@foreground_image_url.setter | ||
def foreground_image_url(self, value): | ||
self._set_attr("foregroundImageUrl", value) | ||
|
||
# background_image_url | ||
@property | ||
def background_image_url(self): | ||
return self._get_attr("backgroundImageUrl") | ||
|
||
@background_image_url.setter | ||
def background_image_url(self, value): | ||
self._set_attr("backgroundImageUrl", value) | ||
|
||
# icon | ||
@property | ||
def icon(self): | ||
return self._get_attr("icon") | ||
|
||
@icon.setter | ||
def icon(self, value): | ||
self._set_attr("icon", value) | ||
|
||
# radius | ||
@property | ||
def radius(self): | ||
return self._get_attr("radius") | ||
|
||
@radius.setter | ||
def radius(self, value): | ||
self._set_attr("radius", value) | ||
|
||
# min_radius | ||
@property | ||
def min_radius(self): | ||
return self._get_attr("minRadius") | ||
|
||
@min_radius.setter | ||
def min_radius(self, value): | ||
self._set_attr("minRadius", value) | ||
|
||
# max_radius | ||
@property | ||
def max_radius(self): | ||
return self._get_attr("maxRadius") | ||
|
||
@max_radius.setter | ||
def max_radius(self, value): | ||
self._set_attr("maxRadius", value) | ||
|
||
# color | ||
@property | ||
def color(self): | ||
return self._get_attr("color") | ||
|
||
@color.setter | ||
def color(self, value): | ||
self._set_attr("color", value) | ||
|
||
# bgcolor | ||
@property | ||
def bgcolor(self): | ||
return self._get_attr("bgcolor") | ||
|
||
@bgcolor.setter | ||
def bgcolor(self, value): | ||
self._set_attr("bgcolor", 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,29 @@ | ||
import flet | ||
from flet import CircleAvatar, Icon, Text, colors, icons | ||
|
||
|
||
def main(page): | ||
# a "normal" avatar with background image | ||
a1 = CircleAvatar( | ||
foreground_image_url="https://avatars.githubusercontent.com/u/5041459?s=88&v=4", | ||
content=Text("FF"), | ||
) | ||
# avatar with failing foregroung image and fallback text | ||
a2 = CircleAvatar( | ||
foreground_image_url="https://avatars.githubusercontent.com/u/_5041459?s=88&v=4", | ||
content=Text("FF"), | ||
) | ||
# avatar with icon, aka icon with inverse background | ||
a3 = CircleAvatar( | ||
content=Icon(icons.ABC), | ||
) | ||
# avatar with icon and custom colors | ||
a4 = CircleAvatar( | ||
content=Icon(icons.WARNING_ROUNDED), | ||
color=colors.YELLOW_200, | ||
bgcolor=colors.AMBER_700, | ||
) | ||
page.add(a1, a2, a3, a4) | ||
|
||
|
||
flet.app(target=main) |
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,17 @@ | ||
import flet | ||
from flet import Text | ||
|
||
|
||
def main(page): | ||
t = Text( | ||
value="This is a Text control sample", | ||
size=30, | ||
color="white", | ||
bgcolor="pink", | ||
weight="bold", | ||
italic=True, | ||
) | ||
page.add(t) | ||
|
||
|
||
flet.app(target=main) |
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,13 @@ | ||
import flet | ||
from flet import Checkbox, ElevatedButton, Row, TextField | ||
|
||
|
||
def main(page): | ||
def add_clicked(e): | ||
page.add(Checkbox(label=new_task.value)) | ||
|
||
new_task = TextField(hint_text="Whats needs to be done?", width=300) | ||
page.add(Row([new_task, ElevatedButton("Add", on_click=add_clicked)])) | ||
|
||
|
||
flet.app(target=main) |