flutter CustomScrollView It scrolls even if the height isn't full enough

71 Views Asked by At

I am trying to use CustomScrollView to create a view whose height scrolls according to the content inside.

But with CustomScrollView, it scrolls even if its height is not full enough.

Is there any way to solve this?

here is my code

CustomScrollView(
          slivers: [
            SliverToBoxAdapter(
              child: Padding(
                padding: const EdgeInsets.all(20.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      faqInfo.title,
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                      style: titleTextStyle,
                    ),
                    const SizedBox(
                      height: 10,
                    ),
                    Text(
                      '${faqInfo.lastEditTime.year}년 ${faqInfo.lastEditTime.month}월 ${faqInfo.lastEditTime.day}일'
                      '${'${faqInfo.lastEditTime.year}'.padLeft(2, '0')}:${'${faqInfo.lastEditTime.year}'.padLeft(2, '0')}',
                      style: TextStyle(
                        fontSize: normalSize,
                        color: lightTextColor,
                      ),
                    ),
                    const SizedBox(
                      height: 20,
                    ),
                    Container(
                      height: 1,
                      color: lightGrayColor,
                    )
                  ],
                ),
              ),
            )
          ],
        ),

enter image description here

1

There are 1 best solutions below

0
Mohammad Abdullah On BEST ANSWER
you can simply add **physics: const NeverScrollableScrollPhysics(),** in CustomScrollView

CustomScrollView(
      physics: const NeverScrollableScrollPhysics(),
      slivers: [
        SliverToBoxAdapter(
          child: Padding(
            padding: const EdgeInsets.all(20.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  faqInfo.title,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: titleTextStyle,
                ),
                const SizedBox(
                  height: 10,
                ),
                Text(
                  '${faqInfo.lastEditTime.year}년 ${faqInfo.lastEditTime.month}월 ${faqInfo.lastEditTime.day}일'
                  '${'${faqInfo.lastEditTime.year}'.padLeft(2, '0')}:${'${faqInfo.lastEditTime.year}'.padLeft(2, '0')}',
                  style: TextStyle(
                    fontSize: normalSize,
                    color: lightTextColor,
                  ),
                ),
                const SizedBox(
                  height: 20,
                ),
                Container(
                  height: 1,
                  color: lightGrayColor,
                )
              ],
            ),
          ),
        )
      ],
    )