Search code examples
flutterdartflutter-widgetflutterdriver

Scrolling not working with SingleChildScrollView


I want to do scrolling using flutter driver on a page that uses SingleChildScrollView.. the layout looks like this

return Scaffold(
      backgroundColor: PinColorsV2.neutralMin,
      body: NotificationListener<OverscrollIndicatorNotification>(
        onNotification: (overscroll) {
          overscroll.disallowGlow();
          return true;
        },
        child: LayoutBuilder(
          builder: (context, constraints) {
            return SingleChildScrollView(
              key: Key(ProfileSettingKey.profileScrollView),
              child: ConstrainedBox(
                constraints: BoxConstraints(
                  minWidth: constraints.maxWidth,
                  minHeight: constraints.maxHeight,
                ),
                child: IntrinsicHeight(
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    children: <Widget>[
                      BusinessCardProfileWidget(),
                      Expanded(
                        child: Padding(
                          padding: EdgeInsets.only(top: 10.0),
                          child: ProfileSettingsWidget(),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            );
          },
        ),
      ),
    );

and here's how i scroll in my flutter driver script:

await world.driver.scrollUntilVisible(ProfileSettingFinder.profileScrollView, ProfileSettingFinder.logout, dyScroll: -15000.0, timeout: scrollTimeoout);

the page actually scrolls, but it only scrolls once a little bit.. not until my widget that i search for is displayed..as far as i know scrollUntilVisible command should keep scrolling until my desired widget shown

i noticed that the behavior is different when the layout is using ListView.Builder.. this is on different page on the app

return ListView.builder(
      key: Key(HomeKey.homeListView),
      itemCount: 1,
      itemBuilder: (context, index) {
        return Column(
          children: <Widget>[
            _staticBanner(context, model),
            if (_remoteConfigService.agentDashboardEnabled) ...[
              UIHelper.vertSpace(12),
              AgentDashboardWidget(),
            ],
            if (_remoteConfigService.howToGetCommissionEnabled) ...[
              UIHelper.vertSpace(20),
              HowToGetCommissionWidget(),
            ],
            if (_remoteConfigService.featureToggles.infoForYouSectionEnabled) ...[
              InfoForYouWidget(),
            ],
            if (_remoteConfigService.projectFilterShortcutEnabled) ...[
              UIHelper.vertSpace(24),
              BuildingTypeFilterWidget(),
            ],
            if (_remoteConfigService.userSellingPointEnabled) ...[
              UIHelper.vertSpace(36),
              UserSellingPointWidget(
                onTapCallback: () => _goToBenefitWithPinhomeView(context, model),
              ),
            ],
            if (_remoteConfigService.featuredProjectEnabled) ...[
              UIHelper.vertSpace(28),
              ProjectHorizontalListWidget(
                type: ProjectHorizontalListType.featuredProjects,
              ),
            ],
            if (_remoteConfigService.newProjectEnabled) ...[
              UIHelper.vertSpace(28),
              ProjectHorizontalListWidget(
                type: ProjectHorizontalListType.latestProjects,
                widgetKey: Key(HomeKey.proyekTerbaruHeader)
              ),
            ],
            UIHelper.vertSpace(12),
          ],
        );
      },
    );

i can scroll on that ListView normally, until my desired widget found, using the exact same syntax.. something like

await world.driver.scrollUntilVisible(HomeFinder.homeListView, HomeFinder.proyekTerbaruHeader, dyScroll: -500.0, timeout: temot);

so do i have to use different command if i want to scroll on a layout that uses SingleChildScrollView?


Solution

  • Incase anyone stumbles upon this, with the new integration_test package this works:

    await tester.scrollUntilVisible(myFinder, 20,
              scrollable: find.descendant(of: find.byType(SingleChildScrollView), matching: find.byType(Scrollable)));