flutterdart

How to Change width of element inside ListView?


I have a ListView with some items, but my problem is that the item inside the ListView will expand through the all-screen width, and I tried to use SizedBox and Container but it doesn't work for me. Here is my code:

  body: ListView.builder(
    itemCount: 10,
    itemBuilder: (ctx, index) {
      return SizedBox(
        width: 10,
        height: 10,
        child: Card(
          color: btnColor,
          child: Text(
            "Helo",
            // loremIpsum,
            style: TextStyle(color: Colors.black.withOpacity(0.6)),
          ),
        ),
      );
    },
  ),

Solution

  • I fixed my issue from this link:

    body: ListView.builder(
            itemCount: 10,
            itemBuilder: (ctx, index) {
              return Row(
                children: [
                  Container(height: 50, width: 50, color: Colors.black),
                ],
              );
            },
          ),
    

    Just use Row inside the ListView