flutter - correct way to create a box that starts at minHeight, grows to maxHeight

后端 未结 5 2033
时光说笑
时光说笑 2020-12-15 02:39

I have a container that I want to start off at a minimum size and grow (if its contents grow while user is adding content) to a maximum size, then stop.

The correct

5条回答
  •  我在风中等你
    2020-12-15 03:09

    Below Example will help you to grow Size of the widget as required

    Container(
              color: Colors.blueAccent,
              constraints: BoxConstraints(
                  minHeight: 100, minWidth: double.infinity, maxHeight: 400),
              child: ListView(
                shrinkWrap: true,
                children: [
                  ...List.generate(
                    10,  // Replace this with 1, 2 to see min height works. 
                    (index) => Text(
                      'Sample Test: ${index}',
                      style: TextStyle(fontSize: 60, color: Colors.black),
                    ),
                  ),
                ],
              ),
            ),
    

    Output for Min Height for Single Item:

    Output for Min Height for 10 Items:

    Note: This will show widgets as per mentioned max-height.

提交回复
热议问题