In the ToggleButtons-Example there is not much space between the icons: https://api.flutter.dev/flutter/material/ToggleButtons-class.html
When I use the code provided, I get that
How can I remove the space on the left and on the right?
And is it possible scroll the toggleButtons - or even to "page" them (clicking f. e. on buttons on the left and on the right of the toggle buttons and "scroll/move" by one icon in a direction)?
How can I remove the space on the left and on the right?
How Bogdan Orzea said, in Flutter last release (version 1.9.1) isn't possible to change the padding of the ToggleButtons's children. Probably in the next Flutter release it will be possible. If you can't wait until the next release, you can update Flutter to version 1.12.13+hotfix.3 (beta). In this beta version the ToggleButtons's children will be square like is shown in ToggleButtons-Example, and you can change the padding using Padding Widget, like the code below:
ToggleButtons(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 40.0, right: 40.0),
child: Text('Option 1')
),
Padding(
padding: EdgeInsets.only(left: 40.0, right: 40.0),
child: Text('Option 2')
),
Padding(
padding: EdgeInsets.only(left: 40.0, right: 40.0),
child: Text('Option 3')
),
Padding(
padding: EdgeInsets.only(left: 40.0, right: 40.0),
child: Text('Option 4')
)
],
)
And is it possible scroll the toggleButtons - or even to "page" them (clicking f. e. on buttons on the left and on the right of the toggle buttons and "scroll/move" by one icon in a direction)?
Wrap your ToggleButton inside the SingleChildScrollView widget:
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ToggleButtons(
children: (...)
)
)
You can wrap any widget with a SingleChildScrollView
like this:
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ToggleButtons( ... ),
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With