Hope below is what you are looking for. Converting row of widgets into column of widgets in flutter based on screen size.
This can be achieved using Wrap Widget in flutter.
Here is the complete code for the above example.
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@
override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: MyWidget(),
),
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget({
super.key,
});
@
override
Widget build(BuildContext context) {
return Center(
child: Wrap(
spacing: 10.0,
alignment: WrapAlignment.start,
children: const [
MyContainer(),
MyContainer(),
MyContainer(),
MyContainer(),
MyContainer(),
MyContainer(),
],
),
);
}
}
class MyContainer extends StatelessWidget {
const MyContainer({
super.key,
});
@
override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 50,
width: 50,
color: Colors.red,
),
);
}
}
Thanks,Srikanth