I try to create a custom tab widget into Flutter app
I would like to have each specific square which contain 1 divider colored and Text layouted into Column widget.
My text display correctly but all tried code never displayed my color blue divider.
I also try trick that wrapped Row or Column by Container or IntrinsicHeight like explain here : Trick to display Divider into Row
I also changed background color but nothing change.
Why flutter refuse to display me my Divider widget in this context :
class _TabAppState extends State<TabApp>
{
@override
Widget build(BuildContext context)
{
return Container(
width: 250,
height: 200,
color: const Color(0xFF000000),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Divider(color: Colors.blue),
Container(height: 100, child: Column(children: [Divider(color: Colors.blue, height: 25, thickness: 2, indent: 5, endIndent: 5), Text('Tab 1', style: Theme.of(context).textTheme.labelLarge)])),
SizedBox(height: 100, child: Column(children: [Divider(color: Colors.blue, height: 25, thickness: 2, indent: 5, endIndent: 5)])),
Column(children: [VerticalDivider(color: Colors.blue, width: 30), Text('Tab 2', style: Theme.of(context).textTheme.labelLarge)]),
Container(child: Column(children: [SizedBox(height: 10, width: 50), Text('Tab 3', style: Theme.of(context).textTheme.labelLarge)])),
Container(child: Column(children: [Divider(color: Colors.blue, height: 25, thickness: 2, indent: 5, endIndent: 5)])),
],
),
),
);
}
}
Thank you for give me help or way to resolve this…
2
Answers
The main issue is here how constraints is passing down to the Divider widget. You can use
VerticalDivider
in Row, and the contains are not getting the proper constraints(width) for Divider widget. you can use several approach like fixed width, Expanded orIntrinsicWidth
. Here is the demoThe issue you’re facing is related to the way you are trying to display Divider widgets within a Row. By default, Divider widgets take up very little space, and they might not display as expected when used within a Row without enough space. Here’s a modified version of your code that should display the blue dividers as intended:
In this code:
I’ve wrapped the Divider widgets with Container to give them some width (in the case of horizontal dividers) and height (in the case of vertical dividers) so that they are visible within the Row.
I’ve adjusted the width and height of the Divider widgets and the VerticalDivider widget as needed for your layout.
This should ensure that your blue dividers are displayed correctly within your custom tab widget. Adjust the width and height values as necessary to achieve the desired visual appearance.