-
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
03548c5
commit afc67a5
Showing
4 changed files
with
177 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
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,73 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../models/control.dart'; | ||
import '../utils/edge_insets.dart'; | ||
import '../web_socket_client.dart'; | ||
import 'create_control.dart'; | ||
|
||
class ListTileControl extends StatelessWidget { | ||
final Control? parent; | ||
final Control control; | ||
final List<Control> children; | ||
final bool parentDisabled; | ||
|
||
const ListTileControl( | ||
{Key? key, | ||
this.parent, | ||
required this.control, | ||
required this.children, | ||
required this.parentDisabled}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
debugPrint("ListTile build: ${control.id}"); | ||
|
||
var leadingCtrls = | ||
children.where((c) => c.name == "leading" && c.isVisible); | ||
var titleCtrls = children.where((c) => c.name == "title" && c.isVisible); | ||
var subtitleCtrls = | ||
children.where((c) => c.name == "subtitle" && c.isVisible); | ||
var trailingCtrls = | ||
children.where((c) => c.name == "trailing" && c.isVisible); | ||
|
||
bool selected = control.attrBool("selected", false)!; | ||
bool dense = control.attrBool("dense", false)!; | ||
bool isThreeLine = control.attrBool("isThreeLine", false)!; | ||
bool autofocus = control.attrBool("autofocus", false)!; | ||
bool disabled = control.isDisabled || parentDisabled; | ||
|
||
Function()? onPressed = disabled | ||
? null | ||
: () { | ||
debugPrint("ListTile ${control.id} clicked!"); | ||
ws.pageEventFromWeb( | ||
eventTarget: control.id, | ||
eventName: "click", | ||
eventData: control.attrs["data"] ?? ""); | ||
}; | ||
|
||
ListTile tile = ListTile( | ||
autofocus: autofocus, | ||
contentPadding: parseEdgeInsets(control, "contentPadding"), | ||
isThreeLine: isThreeLine, | ||
selected: selected, | ||
dense: dense, | ||
onTap: onPressed, | ||
leading: leadingCtrls.isNotEmpty | ||
? createControl(control, leadingCtrls.first.id, disabled) | ||
: null, | ||
title: titleCtrls.isNotEmpty | ||
? createControl(control, titleCtrls.first.id, disabled) | ||
: null, | ||
subtitle: subtitleCtrls.isNotEmpty | ||
? createControl(control, subtitleCtrls.first.id, disabled) | ||
: null, | ||
trailing: trailingCtrls.isNotEmpty | ||
? createControl(control, trailingCtrls.first.id, disabled) | ||
: null, | ||
); | ||
|
||
return constrainedControl(tile, 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import logging | ||
|
||
import flet | ||
from flet import ( | ||
Card, | ||
Column, | ||
Container, | ||
Icon, | ||
Image, | ||
ListTile, | ||
PopupMenuButton, | ||
PopupMenuItem, | ||
Text, | ||
icons, | ||
padding, | ||
) | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
def main(page): | ||
page.title = "ListTile Examples" | ||
# page.theme_mode = "dark" | ||
page.add( | ||
Card( | ||
content=Container( | ||
width=500, | ||
content=Column( | ||
[ | ||
ListTile( | ||
title=Text("One-line list tile"), | ||
), | ||
ListTile(title=Text("One-line dense list tile"), dense=True), | ||
ListTile( | ||
leading=Icon(icons.SETTINGS), | ||
title=Text("One-line selected list tile"), | ||
selected=True, | ||
), | ||
ListTile( | ||
leading=Image(src="/icons/icon-192.png", fit="contain"), | ||
title=Text("One-line with leading control"), | ||
), | ||
ListTile( | ||
title=Text("One-line with trailing control"), | ||
trailing=PopupMenuButton( | ||
icon=icons.MORE_VERT, | ||
items=[ | ||
PopupMenuItem(text="Item 1"), | ||
PopupMenuItem(text="Item 2"), | ||
], | ||
), | ||
), | ||
ListTile( | ||
leading=Icon(icons.ALBUM), | ||
title=Text("One-line with leading and trailing controls"), | ||
trailing=PopupMenuButton( | ||
icon=icons.MORE_VERT, | ||
items=[ | ||
PopupMenuItem(text="Item 1"), | ||
PopupMenuItem(text="Item 2"), | ||
], | ||
), | ||
), | ||
ListTile( | ||
leading=Icon(icons.SNOOZE), | ||
title=Text("Two-line with leading and trailing controls"), | ||
subtitle=Text("Here is a second title."), | ||
trailing=PopupMenuButton( | ||
icon=icons.MORE_VERT, | ||
items=[ | ||
PopupMenuItem(text="Item 1"), | ||
PopupMenuItem(text="Item 2"), | ||
], | ||
), | ||
), | ||
], | ||
spacing=0, | ||
), | ||
padding=padding.symmetric(vertical=10), | ||
) | ||
) | ||
) | ||
|
||
|
||
flet.app(name="test1", port=8550, target=main, view=flet.WEB_BROWSER) |