How can I adjust my code to work as the button on this image?
I’m trying to have Text with Icon in center Flutter using a button with gridview.
class ServicePage extends StatelessWidget {
const ServicePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 2,
children: List.generate(20, (index) {
return Center(
child: Wrap(
direction: Axis.vertical,
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
ElevatedButton.icon(
icon: Icon(
Icons.home,
size: 20,
),
label: Text('測試$index 15146513515464515144635125131'),
onPressed: () {
print('我是第$index個');
},
)
],
),
);
}),
);
}
}
2
Answers
You can use
Column
inside button:Output:
you can wrap the
Icon
andText
widgets in aColumn
widget like this: