2

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

2
  • Have you tried using GridView() ? Commented Dec 21, 2021 at 13:30
  • is your _myContainer() has fixed width? Commented Dec 21, 2021 at 15:37

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

i was able to resolve this error using FittedBox in _myContainer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.