Closed Renatinaveen closed 4 years ago
Hi @Renatinaveen thanks for this issue. Is it possible to show me a visual issue? it will help to fix this issue
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)
@omishah what if we try with page controller?
Since this seems to not be a package error, I'm closing it for now.
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.