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();
|
_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 {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
Reference in New Issue
Block a user