Skip to content

Instantly share code, notes, and snippets.

@huxaiphaer
Created May 5, 2020 07:14
Show Gist options
  • Save huxaiphaer/553bfd68f8a60b9e876599d96bc83a1e to your computer and use it in GitHub Desktop.
Save huxaiphaer/553bfd68f8a60b9e876599d96bc83a1e to your computer and use it in GitHub Desktop.
class Home extends StatefulWidget {
@override
_Home createState() => _Home();
}
class _Home extends State<Home> {
Color primary = const Color(0xFF292B2C);
List<Widget> pageList = List<Widget>();
int _selectedPage = 0;
double previousScrollOffset = 50.0;
ScrollController _controller;
@override
void initState() {
// TODO: implement initState
super.initState();
_controller = ScrollController( initialScrollOffset: previousScrollOffset);
_controller.addListener(() {
if (_controller.position.atEdge) {
if (_controller.position.pixels == 0) {
// you are at the top
print('You are at the top');
} else {
//bottom
// previousScrollOffset = _controller.offset;
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CustomSwipeDownPage()),
);
}
}
});
}
@override
void dispose() {
// TODO: implement dispose
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
pageList.add(_firstPage(_controller));
pageList.add(Container());
pageList.add(Container());
pageList.add(Container());
pageList.add(ProfilePage());
return Scaffold(
body: IndexedStack(
index: _selectedPage,
children: pageList,
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.white),
title: Text(''),
),
BottomNavigationBarItem(
icon: Icon(Icons.bookmark, color: Colors.white),
title: Text(''),
),
BottomNavigationBarItem(
icon: Icon(Icons.search, color: Colors.white),
title: Text(''),
),
BottomNavigationBarItem(
icon: Icon(Icons.notifications, color: Colors.white),
title: Text(''),
),
BottomNavigationBarItem(
icon: Icon(Icons.person, color: Colors.white),
title: Text(''),
),
],
currentIndex: _selectedPage,
onTap: (int index) {
setState(() {
_selectedPage = index;
});
},
selectedItemColor: Colors.amber[800],
backgroundColor: primary,
),
);
}
Widget _firstPage(ScrollController scrollController) {
return Container(
child: ListView(
controller: scrollController,
children: <Widget>[
TopStory(),
Container(
child: CardSlider(),
color: Colors.grey[900],
),
Material(child: MoreCategoriesPage()),
],
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment