diff --git a/lib/activity_feed.dart b/lib/activity_feed.dart index 26cce3e..f2d89d3 100644 --- a/lib/activity_feed.dart +++ b/lib/activity_feed.dart @@ -9,9 +9,11 @@ class ActivityFeedPage extends StatefulWidget { _ActivityFeedPageState createState() => new _ActivityFeedPageState(); } -class _ActivityFeedPageState extends State { +class _ActivityFeedPageState extends State with AutomaticKeepAliveClientMixin { @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 { } return items; } + + // ensures state is kept when switching pages + @override + bool get wantKeepAlive => true; + } class ActivityFeedItem extends StatelessWidget { diff --git a/lib/feed.dart b/lib/feed.dart index 3e5140e..a405289 100644 --- a/lib/feed.dart +++ b/lib/feed.dart @@ -11,7 +11,7 @@ class Feed extends StatefulWidget { _Feed createState() => new _Feed(); } -class _Feed extends State { +class _Feed extends State with AutomaticKeepAliveClientMixin { List feedData; @override @@ -34,6 +34,8 @@ class _Feed extends State { @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 { return listOfPosts; } + + // ensures state is kept when switching pages + @override + bool get wantKeepAlive => true; } diff --git a/lib/profile_page.dart b/lib/profile_page.dart index 1f85266..6fef9db 100644 --- a/lib/profile_page.dart +++ b/lib/profile_page.dart @@ -13,7 +13,7 @@ class ProfilePage extends StatefulWidget { _ProfilePage createState() => new _ProfilePage(this.userId); } -class _ProfilePage extends State { +class _ProfilePage extends State with AutomaticKeepAliveClientMixin { final String profileId; String currentUserId = googleSignIn.currentUser.id; String view = "grid"; // default view @@ -124,6 +124,8 @@ class _ProfilePage extends State { @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 { return count; } + + // ensures state is kept when switching pages + @override + bool get wantKeepAlive => true; } class ImageTile extends StatelessWidget {