Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import 'draggable.dart';
import 'dropdown.dart';
import 'elevated_button.dart';
import 'error.dart';
import 'expansion_tile.dart';
import 'file_picker.dart';
import 'flet_app_control.dart';
import 'floating_action_button.dart';
Expand Down Expand Up @@ -420,6 +421,13 @@ Widget createWidget(Key? key, ControlViewModel controlView, Control? parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled);
case "expansiontile":
return ExpansionTileControl(
key: key,
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled);
case "listview":
return ListViewControl(
key: key,
Expand Down
131 changes: 131 additions & 0 deletions package/lib/src/controls/expansion_tile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import 'package:flutter/material.dart';

import '../flet_app_services.dart';
import '../models/control.dart';
import '../utils/alignment.dart';
import '../utils/borders.dart';
import '../utils/colors.dart';
import '../utils/edge_insets.dart';
import 'create_control.dart';
import 'error.dart';

class ExpansionTileControl extends StatelessWidget {
final Control? parent;
final Control control;
final List<Control> children;
final bool parentDisabled;

const ExpansionTileControl(
{Key? key,
this.parent,
required this.control,
required this.children,
required this.parentDisabled})
: super(key: key);

@override
Widget build(BuildContext context) {
debugPrint("ExpansionTile build: ${control.id}");

final server = FletAppServices.of(context).server;

var ctrls = children.where((c) => c.name == "controls" && c.isVisible);
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);

if (titleCtrls.isEmpty) {
return const ErrorControl("ExpansionTile requires a title!");
}

bool disabled = control.isDisabled || parentDisabled;
bool onchange = control.attrBool("onchange", false)!;
bool maintainState = control.attrBool("maintainState", false)!;
bool initiallyExpanded = control.attrBool("maintainState", false)!;

var iconColor = HexColor.fromString(
Theme.of(context), control.attrString("iconColor", "")!);
var textColor = HexColor.fromString(
Theme.of(context), control.attrString("textColor", "")!);
var bgColor = HexColor.fromString(
Theme.of(context), control.attrString("bgColor", "")!);
var collapsedBgColor = HexColor.fromString(
Theme.of(context), control.attrString("collapsedBgColor", "")!);
var collapsedIconColor = HexColor.fromString(
Theme.of(context), control.attrString("collapsedIconColor", "")!);
var collapsedTextColor = HexColor.fromString(
Theme.of(context), control.attrString("collapsedTextColor", "")!);

var affinity = ListTileControlAffinity.values.firstWhere(
(e) =>
e.name.toLowerCase() ==
control.attrString("affinity", "")!.toLowerCase(),
orElse: () => ListTileControlAffinity.platform);
var clipBehavior = Clip.values.firstWhere(
(e) =>
e.name.toLowerCase() ==
control.attrString("clipBehavior", "")!.toLowerCase(),
orElse: () => Clip.none);

var expandedCrossAxisAlignment = parseCrossAxisAlignment(
control, "crossAxisAlignment", CrossAxisAlignment.center);

if (expandedCrossAxisAlignment == CrossAxisAlignment.baseline) {
return const ErrorControl(
'CrossAxisAlignment.baseline is not supported since the expanded '
'controls are aligned in a column, not a row. '
'Try aligning the controls differently.');
}

Function(bool)? onChange = (onchange) && !disabled
? (expanded) {
debugPrint(
"ExpansionTile ${control.id} was ${expanded ? "expanded" : "collapsed"}");
server.sendPageEvent(
eventTarget: control.id,
eventName: "change",
eventData: "$expanded");
}
: null;

Widget tile = ExpansionTile(
controlAffinity: affinity,
childrenPadding: parseEdgeInsets(control, "controlsPadding"),
tilePadding: parseEdgeInsets(control, "tilePadding"),
expandedAlignment: parseAlignment(control, "expandedAlignment"),
expandedCrossAxisAlignment: parseCrossAxisAlignment(
control, "crossAxisAlignment", CrossAxisAlignment.center),
backgroundColor: bgColor,
iconColor: iconColor,
textColor: textColor,
collapsedBackgroundColor: collapsedBgColor,
collapsedIconColor: collapsedIconColor,
collapsedTextColor: collapsedTextColor,
maintainState: maintainState,
initiallyExpanded: initiallyExpanded,
clipBehavior: clipBehavior,
shape: parseOutlinedBorder(control, "shape"),
collapsedShape: parseOutlinedBorder(control, "collapsedShape"),
onExpansionChanged: onChange,
leading: leadingCtrls.isNotEmpty
? createControl(control, leadingCtrls.first.id, disabled)
: null,
title: createControl(control, titleCtrls.first.id, disabled),
subtitle: subtitleCtrls.isNotEmpty
? createControl(control, subtitleCtrls.first.id, disabled)
: null,
trailing: trailingCtrls.isNotEmpty
? createControl(control, trailingCtrls.first.id, disabled)
: null,
children: ctrls.isNotEmpty
? ctrls.map((c) => createControl(control, c.id, disabled)).toList()
: [],
);

return constrainedControl(context, tile, parent, control);
}
}
1 change: 1 addition & 0 deletions sdk/python/packages/flet-core/src/flet_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from flet_core.draggable import Draggable
from flet_core.dropdown import Dropdown
from flet_core.elevated_button import ElevatedButton
from flet_core.expansion_tile import ExpansionTile, TileAffinity
from flet_core.file_picker import (
FilePicker,
FilePickerFileType,
Expand Down
1 change: 0 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
RotateValue,
ScaleValue,
ScrollMode,
ScrollModeString,
)


Expand Down
Loading