Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll Position #30

Closed
Renatinaveen opened this issue Oct 30, 2019 · 4 comments
Closed

Scroll Position #30

Renatinaveen opened this issue Oct 30, 2019 · 4 comments

Comments

@Renatinaveen
Copy link

The scroll position of one screen is getting reset after coming back from another.
ex: In HomePage i scrolled to bottom and went to another page then went to home page the scroll position is top. Any solution?

If i want to add newsfeed i need to maintain the scroll position it's necessary. Look into this.
Thanks.

@pedromassango
Copy link
Owner

Hi @Renatinaveen thanks for this issue. Is it possible to show me a visual issue? it will help to fix this issue

@omishah
Copy link

omishah commented Dec 13, 2019

The scroll position of one screen is getting reset after coming back from another.
ex: In HomePage i scrolled to bottom and went to another page then went to home page the scroll position is top. Any solution?

If i want to add newsfeed i need to maintain the scroll position it's necessary. Look into this.
Thanks.

The issue is not due to this package, it's by flutter framework.

If you want to keep the scroll state, implement Stack with Offstage.

Check below for a complete example:

import 'package:bottom_navy_bar/bottom_navy_bar.dart';
import 'package:flutter/material.dart';

class Demo extends StatefulWidget {

  @override
  _DemoState createState() => _DemoState();
}

class _DemoState extends State<Demo> {

  int _currentIndex = 0; // to keep the index of currently selected tab

  Stack _bodyWidgets() {
    return Stack( children: <Widget>[
      Offstage(
          offstage: _currentIndex != 0,
          child: TickerMode(enabled: _currentIndex == 0, child: _screen1Body())),
      Offstage(
        offstage: _currentIndex != 1,
        child: TickerMode(
          enabled: _currentIndex == 1,
          child: Text(("Screen 2"),
        ),
      )),
      Offstage(
        offstage: _currentIndex != 2,
        child: TickerMode(
          enabled: _currentIndex == 2,
          child: Text("Screen 3")),
        ),
    ]);
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
        appBar: AppBar(
          title: Text("DEMO"),
        ),
        body: _bodyWidgets(),
        bottomNavigationBar: BottomNavyBar(
            selectedIndex: _currentIndex,
            onItemSelected: (index) => _onTabTapped(index),
            showElevation: true,
            items: [
              BottomNavyBarItem(
                  icon: Icon(Icons.home),
                  title: Text('Screen1')),
              BottomNavyBarItem(
                  icon: Icon(Icons.photo),
                  title: Text('Screen2'),
              ),
              BottomNavyBarItem(
                  icon: Icon(Icons.notifications),
                  title: Text('Screen3'),
                 ),
             
            ]));
  }

  void _onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  _screen1Body() {
    return ListView.builder(
      itemCount: 100,
      itemBuilder: (context, i) {
        return Padding(padding: EdgeInsets.all(5), child: Text(i.toString()));
      },
    );
  }
}

**SCREENSHOT:** [https://i.stack.imgur.com/UNpku.gif](https://i.stack.imgur.com/UNpku.gif)
 

@djaygit
Copy link

djaygit commented Feb 24, 2020

@omishah what if we try with page controller?

@pedromassango pedromassango added bug Something isn't working and removed bug Something isn't working labels Feb 25, 2020
@pedromassango
Copy link
Owner

Since this seems to not be a package error, I'm closing it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants