How to convert row of widgets into column of widgets in flutter based on screen size?

This Article is posted by seven.srikanth at 11/26/2022 2:05:48 AM



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

Tags: Rows into Columns; Columns to rows; Screen Size;








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com