mirror of
https://github.com/mdanics/fluttergram.git
synced 2025-08-06 13:19:53 +08:00
tabs now keep state after switching pages, improves overall ux
This commit is contained in:
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user