Can anyone explain me how can I build widget as ListView
builder with 2 lines of items. I got an example of this type, you can check out it by the picture below:
Asked
Active
Viewed 332 times
0

ישו אוהב אותך
- 28,609
- 11
- 78
- 96

Pation
- 159
- 1
- 11
-
look here https://stackoverflow.com/questions/51089041/list-of-horizontal-list-in-flutter – Jitesh Mohite Mar 28 '21 at 10:48
-
that is not what i need – Pation Mar 28 '21 at 11:04
2 Answers
0
This snippet should help you. You can try it at https://dartpad.dev/028daa76945938f0e5c14aea6a8bf84b?null_safety=true
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
width: 500.0,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: ['English', 'Russian', 'Spanish']
.map((language) => LanguageButton(
language: language,
))
.toList(),
),
SizedBox(height: 20,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: ['Some really long language', 'French', 'German']
.map((language) => LanguageButton(
language: language,
))
.toList(),
),
],
),
);
}
}
class LanguageButton extends StatelessWidget {
final String language;
const LanguageButton({Key? key, required this.language}) : super(key: key);
@override
Widget build(BuildContext context) {
return OutlinedButton(
style: OutlinedButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(30),
),
),
),
onPressed: () {
// TODO
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 8.0),
child: Text(language),
),
);
}
}
I used a Column
instead of a ListView.builder
. Maybe that's good enough for what you need. The gist is to have each line as a Row
and set the mainAxisAlignment
to spaceBetween
.

dumazy
- 13,857
- 12
- 66
- 113
-
-
What exactly do you need? Could you specify a bit more in the question? – dumazy Mar 28 '21 at 11:18
-
I need no scrollable listview builder with buttons of languages, button size should have adaptive width by length of language name – Pation Mar 28 '21 at 11:25
0
An option is to use the Wrap widget with direction set to horizontal.
@override
Widget build(BuildContext context) {
final lorem = [
'accusamus',
'dignissimos',
'ducimus',
'blanditiis',
'praesentium',
'voluptatum'
];
return Container(
height: 100,
width: 250,
child: Wrap(
direction: Axis.horizontal,
children: List.generate(
lorem.length,
(index) => Padding(
padding: const EdgeInsets.all(8.0),
child: Text(lorem[index]),
),
),
),
);
}

glavigno
- 483
- 5
- 10