'ListView with scrollDirection: axis.Horizontal not dynamic

I have this code

  body: SingleChildScrollView(
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        HomeHeader(),
        Container(
          padding: EdgeInsets.only(top: 5, bottom: 10),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              TitleCard(title: "Popular Coffee Bean"),
              SizedBox(height: 5),
              PopularCoffeeBeans(), //widget Overflowed
              SizedBox(height: 10),
              TitleCard(title: "Implementation"),
              SizedBox(height: 5),
            ],
          ),
        ),
      ],
    ),
  );

I want to try auto set height that the column shrinks to fit the children. I dont know whats wrong in my code.

I have try to wrap my first Column with Flexible or Expanded Widget, but thats still not working. any solve for this?

this is my output

enter image description here



Solution 1:[1]

The error is not in your column but in your PopularCoffeBeans() Widget. In that container, wherever you have defined the height increase it by 26 pixels. And as for the problem of running it in smaller screen size, I guess you are trying to define height using the screen height which is usually not a good practice. It is better to define a fixed width to avoid the override solution.

Solution 2:[2]

try giving more height to PopularCoffeeBean card your container seem to be overflowing from card container

Solution 3:[3]

There are a lot of ways to do this, but few common ones that come to mind are:

  • Write a method to convert one object to another (there is a lot of info about this online)
    • Brute force example:

      var availableUpgrades = originList.Select(x => new AvailableUpgrade() { alreadyBoughtUpgradePrice = x.alreadyBoughtUpgradePrice, alredyBoughtUpgradeAmount = x.alredyBoughtUpgradeAmount, alreadyBoughtUpgradeName = x.alreadyBoughtUpgradeName}).ToList();

  • Use some existing mapping nuget/lib to do this

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Siddharth Agrawal
Solution 2 Aniket
Solution 3