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

View File

@ -11,7 +11,7 @@ class Feed extends StatefulWidget {
_Feed createState() => new _Feed(); _Feed createState() => new _Feed();
} }
class _Feed extends State<Feed> { class _Feed extends State<Feed> with AutomaticKeepAliveClientMixin<Feed> {
List<ImagePost> feedData; List<ImagePost> feedData;
@override @override
@ -34,6 +34,8 @@ class _Feed extends State<Feed> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); // reloads state when opened again
return new Scaffold( return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: const Text('Fluttergram', title: const Text('Fluttergram',
@ -118,4 +120,8 @@ class _Feed extends State<Feed> {
return listOfPosts; 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); _ProfilePage createState() => new _ProfilePage(this.userId);
} }
class _ProfilePage extends State<ProfilePage> { class _ProfilePage extends State<ProfilePage> with AutomaticKeepAliveClientMixin<ProfilePage> {
final String profileId; final String profileId;
String currentUserId = googleSignIn.currentUser.id; String currentUserId = googleSignIn.currentUser.id;
String view = "grid"; // default view String view = "grid"; // default view
@ -124,6 +124,8 @@ class _ProfilePage extends State<ProfilePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); // reloads state when opened again
Column buildStatColumn(String label, int number) { Column buildStatColumn(String label, int number) {
return new Column( return new Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@ -400,6 +402,10 @@ class _ProfilePage extends State<ProfilePage> {
return count; return count;
} }
// ensures state is kept when switching pages
@override
bool get wantKeepAlive => true;
} }
class ImageTile extends StatelessWidget { class ImageTile extends StatelessWidget {