Home > database >  Flutter overflow row item on the right side
Flutter overflow row item on the right side

Time:12-23

I want to show a list type widget inside the wrap widget, but I am getting an overflow error on the right side.

                               Wrap(
                                    direction: Axis.horizontal,
                                    runAlignment: WrapAlignment.start,
                                    runSpacing: 4,
                                    children: List.generate(3,(index){
                                       return _myContainer();
                                     })
                                  ),

This is how it looks now

enter image description here

what i want is like this

enter image description here

CodePudding user response:

Checkout below code,

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Padding(
          padding: EdgeInsets.all(20.0),
          child: Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(8.0),
              border: Border.all(color: Colors.grey),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text("Color"),
                ),
                Divider(
                  thickness: 1.5,
                ),
                Flexible(
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Wrap(
                        direction: Axis.horizontal,
                        runAlignment: WrapAlignment.start,
                        runSpacing: 12.0,
                        spacing: 12.0,
                        children: List.generate(10, (index) {
                          return inCard(name: "Hello World $index");
                        })),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget inCard({String name}) {
    return Container(
      padding: EdgeInsets.all(6.0),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(8.0),
        border: Border.all(color: Colors.black38),
      ),
      child: Text(
        name ?? "",
        style: TextStyle(color: Colors.purple),
      ),
    );
  }
}

enter image description here

CodePudding user response:

i was able to resolve this error using FittedBox in _myContainer

  • Related