Home > Software engineering >  Flutter ListView scroll doesn't stop scrolling even when there is no content
Flutter ListView scroll doesn't stop scrolling even when there is no content

Time:09-08

ListView doesn't stop scrolling when I reach the end of content, It keeps scrolling (not infinite scrolling).

How do I stop the scroll when there is no more content to scroll to?

Tried replacing ListView with Column --> didn't work.

Tried adding SingleChildScrollView --> didn't work.

Tried adding physics: NeverScrollableScrollPhysics() to ListView --> didn't work.

Edit: Tried removing the Expanded widget --> didn't work.

It is as there is extra height at the end, but there shouldn't be anything.

Simplified code:

Expanded(
                    child: ListView(
                      children: [
                        Obx(() => Column()),
                        Obx(() => Text("Example")),
                        Row()
                      ],
                    ),
                  )

Gif of the problem: https://imgur.com/a/MsZBanu

Also, in there is some gray overlay over the whole screen when the Flutter Inspector is working

Expanded(
            child: ListView(
              shrinkWrap: true,
              children: [
                Obx(
                  () => NameAndLocationWidget(
                    mountainsController: _mountainsController,

                    locationName: 'Lokacija',
                    name:
                        '${_mountainsController.mountain.value != null ? _mountainsController.mountain.value!.name : "-"}',
                    pathsController: null,
                    fontSize: AppFontSizes.aboutMountainTitle,
                  ),
                ),
                Obx(
                  () => Padding(
                    padding: const EdgeInsets.symmetric(
                        horizontal: AppPaddings
                            .aboutMountainMountainNameHorizontalPadding),
                    child: Text(
                      '${_mountainsController.mountain.value != null ? _mountainsController.mountain.value!.description : "-"}',
                      style: const TextStyle(
                        color: AppColors.aboutMountainDescriptionTextColor,
                        fontSize: AppFontSizes.aboutMountainDescriptionText,
                        height:
                            AppConstants.aboutMountainDescriptionTextHeight,
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(
                      horizontal: AppPaddings
                          .aboutMountainMountainNameHorizontalPadding,
                      vertical: AppPaddings
                          .aboutMountainMountainNameVerticalPadding),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      DistanceTimeDifficultyWidget(
                        dTDInfoName: 'distance'.tr,
                        dTDInfoValue: '6 - 10 km',
                      ),
                      DistanceTimeDifficultyWidget(
                        dTDInfoName: 'time'.tr,
                        dTDInfoValue: '2 - 4 h',
                      ),
                      DistanceTimeDifficultyWidget(
                        dTDInfoName: 'difficulty'.tr,
                        dTDInfoValue: 'Easy',
                      ),
                    ],
                  ),
                )
              ],
            ),
          )

CodePudding user response:

With shrinkWrap: true, you can change this behavior.

Also, refer to this flutter : https://api.flutter.dev/flutter/widgets/ScrollView/shrinkWrap.html

CodePudding user response:

What do you want to do? Please share the screan you want to code.

  • Related