You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I notice that when the TabContainer widget get build, all it children get build at the same time even thought only one tab is displayed.To fix this issue you should treat the children property in your TabContainer widget as List and not a List so only the displayed widgets gets build and not all of them.
Here is an example of a solution :
import 'package:flutter/material.dart';
import 'package:tab_container/tab_container.dart';
class MyCustomTabBar extends StatefulWidget {
final TabController controller;
final TabEdge tabEdge;
final double tabsStart;
final double tabsEnd;
final double? tabMaxLength;
final BorderRadius borderRadius;
final BorderRadius tabBorderRadius;
final EdgeInsets childPadding;
final TextStyle? selectedTextStyle;
final TextStyle? unselectedTextStyle;
final Color? color;
final double? tabExtent;
final List<Widget> tabs;
final List<Widget> children;
// Continu Add other properties
const MyCustomTabBar(
{super.key,
required this.controller,
required this.tabEdge,
required this.tabsStart,
required this.tabsEnd,
this.tabMaxLength,
required this.borderRadius,
required this.tabBorderRadius,
required this.childPadding,
this.selectedTextStyle,
this.unselectedTextStyle,
this.color,
this.tabExtent,
required this.tabs,
required this.children});
@override
State<MyCustomTabBar> createState() => _MyCustomTabBarState();
}
class _MyCustomTabBarState extends State<MyCustomTabBar> {
late List<WidgetBuilder> _childrenBuilders; // Add this and use it
@override
void initState() {
super.initState();
_childrenBuilders = widget.children.map((e) => (context) => e).toList();
widget.controller.addListener(() {
if (widget.controller.indexIsChanging) {
setState(() {});
}
});
}
@override
void dispose() {
super.dispose();
widget.controller.removeListener(
() {},
);
}
@override
Widget build(BuildContext context) {
return TabContainer(
controller: widget.controller,
tabEdge: widget.tabEdge,
tabsStart: widget.tabsStart,
tabsEnd: widget.tabsEnd,
tabMaxLength: widget.tabMaxLength ?? double.infinity,
borderRadius: widget.borderRadius,
tabBorderRadius: widget.tabBorderRadius,
childPadding: widget.childPadding,
selectedTextStyle: widget.selectedTextStyle,
unselectedTextStyle: widget.unselectedTextStyle,
color: widget.color,
tabExtent: widget.tabExtent ?? 50,
tabs: widget.tabs,
child: _getTab(context),
// Continu Add other properties
);
}
Widget _getTab(BuildContext context) {
return _childrenBuilders[widget.controller.index](context);
}
}
The text was updated successfully, but these errors were encountered:
I notice that when the TabContainer widget get build, all it children get build at the same time even thought only one tab is displayed.To fix this issue you should treat the children property in your TabContainer widget as List and not a List so only the displayed widgets gets build and not all of them.
Here is an example of a solution :
The text was updated successfully, but these errors were encountered: