0

I have some stateless scrollable widget like this

`class ProfileScreen extends StatelesslWidget {
final dataKey = new GlobalKey();

 @override
  Widget build(BuildContext context) {
    BlocProvider.of<StepsBloc>(context).add(CheckStatus());
    return Scaffold(
      backgroundColor: NorbuColors.darkGrey,
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: Padding(
              padding: const EdgeInsets.only(
                  left: 20, right: 20, top: 48, bottom: 15),
              child: _ProfileReg(),
            ),
          ),
          SliverToBoxAdapter(
            key: dataKey,
            child: _AchievementsStatistics(),
          ),
          SliverToBoxAdapter(
            child: _StepsStatistics(),
          ),
          SliverToBoxAdapter(
            child: _MyGoalsStatistics(),
          ),
          SliverToBoxAdapter(
            child: _GratefulTimerStatistics(),
          ),
          SliverToBoxAdapter(
            child: _WheelBalanceStatistics(),
          ),
        ],
      ),
    );
  }`

And my question is: what is a good way to scroll parent widget from child?

I know easy way is to use Scrollable.ensureVisible(dataKey.currentContext!); but it works only inside scrollable parent widget. Thanks!

3
  • actually the parent will be auto scrollable when child doesnt fit on viewport Commented Feb 2, 2023 at 21:59
  • Yes, but I would like to auto scroll to custom position, for example, after resumed back from another page Commented Feb 3, 2023 at 7:55
  • try to pass ScrollController using calback method Commented Feb 3, 2023 at 8:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.