tabs now keep state after switching pages, improves overall ux

This commit is contained in:
Matthew
2019-04-01 23:32:12 -04:00
parent cac7738d99
commit f0c56f680a
3 changed files with 22 additions and 3 deletions

View File

@ -9,9 +9,11 @@ class ActivityFeedPage extends StatefulWidget {
_ActivityFeedPageState createState() => new _ActivityFeedPageState();
}
class _ActivityFeedPageState extends State<ActivityFeedPage> {
class _ActivityFeedPageState extends State<ActivityFeedPage> with AutomaticKeepAliveClientMixin<ActivityFeedPage> {
@override
Widget build(BuildContext context) {
super.build(context); // reloads state when opened again
return new Scaffold(
appBar: new AppBar(
title: new Text(
@ -55,6 +57,11 @@ class _ActivityFeedPageState extends State<ActivityFeedPage> {
}
return items;
}
// ensures state is kept when switching pages
@override
bool get wantKeepAlive => true;
}
class ActivityFeedItem extends StatelessWidget {

View File

@ -11,7 +11,7 @@ class Feed extends StatefulWidget {
_Feed createState() => new _Feed();
}
class _Feed extends State<Feed> {
class _Feed extends State<Feed> with AutomaticKeepAliveClientMixin<Feed> {
List<ImagePost> feedData;
@override
@ -34,6 +34,8 @@ class _Feed extends State<Feed> {
@override
Widget build(BuildContext context) {
super.build(context); // reloads state when opened again
return new Scaffold(
appBar: new AppBar(
title: const Text('Fluttergram',
@ -118,4 +120,8 @@ class _Feed extends State<Feed> {
return listOfPosts;
}
// ensures state is kept when switching pages
@override
bool get wantKeepAlive => true;
}

View File

@ -13,7 +13,7 @@ class ProfilePage extends StatefulWidget {
_ProfilePage createState() => new _ProfilePage(this.userId);
}
class _ProfilePage extends State<ProfilePage> {
class _ProfilePage extends State<ProfilePage> with AutomaticKeepAliveClientMixin<ProfilePage> {
final String profileId;
String currentUserId = googleSignIn.currentUser.id;
String view = "grid"; // default view
@ -124,6 +124,8 @@ class _ProfilePage extends State<ProfilePage> {
@override
Widget build(BuildContext context) {
super.build(context); // reloads state when opened again
Column buildStatColumn(String label, int number) {
return new Column(
mainAxisSize: MainAxisSize.min,
@ -400,6 +402,10 @@ class _ProfilePage extends State<ProfilePage> {
return count;
}
// ensures state is kept when switching pages
@override
bool get wantKeepAlive => true;
}
class ImageTile extends StatelessWidget {