Skip to content

Commit 0d7a1b5

Browse files
committed
Tabs completed
1 parent 4d5790e commit 0d7a1b5

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

client/lib/controls/tabs.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class TabsControl extends StatefulWidget {
2727
}
2828

2929
class _TabsControlState extends State<TabsControl>
30-
with SingleTickerProviderStateMixin {
30+
with TickerProviderStateMixin {
31+
int _tabsCount = 0;
3132
List<String> _tabsIndex = [];
3233
String? _value;
3334
TabController? _tabController;
@@ -36,7 +37,8 @@ class _TabsControlState extends State<TabsControl>
3637
void initState() {
3738
super.initState();
3839
_tabsIndex = widget.children.map((c) => c.attrString("key", "")!).toList();
39-
_tabController = TabController(length: widget.children.length, vsync: this);
40+
_tabsCount = widget.children.length;
41+
_tabController = TabController(length: _tabsCount, vsync: this);
4042
_tabController!.addListener(() {
4143
if (_tabController!.indexIsChanging == true) {
4244
return;
@@ -53,6 +55,11 @@ class _TabsControlState extends State<TabsControl>
5355
Widget build(BuildContext context) {
5456
debugPrint("TabsControl build: ${widget.control.id}");
5557

58+
if (widget.children.length != _tabsCount) {
59+
_tabsCount = widget.children.length;
60+
_tabController = TabController(length: _tabsCount, vsync: this);
61+
}
62+
5663
bool disabled = widget.control.isDisabled || widget.parentDisabled;
5764

5865
String? value = widget.control.attrString("value");

sdk/python/playground/tabs-test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,30 @@ def main(page: Page):
4646
page.update()
4747
sleep(3)
4848
t.value = "tab2"
49+
t.tabs.pop(0)
4950
t.tabs[1].content = Text("Blah blah blah")
5051
page.update()
52+
sleep(3)
53+
t.tabs.clear()
54+
page.update()
55+
sleep(3)
56+
t.tabs.append(
57+
Tab(
58+
key="tab4",
59+
text="Tab 4",
60+
icon=icons.LOCK,
61+
content=Text("This is Tab 4"),
62+
)
63+
)
64+
t.tabs.append(
65+
Tab(
66+
key="tab5",
67+
text="Tab 5",
68+
icon=icons.SIP_SHARP,
69+
content=Text("This is Tab 5"),
70+
)
71+
)
72+
page.update()
5173

5274

5375
flet.app(

0 commit comments

Comments
 (0)