-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DRAFT: Hide menus on scroll #257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import 'package:thunder/community/widgets/post_card_list.dart'; | |
import 'package:thunder/core/auth/bloc/auth_bloc.dart'; | ||
import 'package:thunder/shared/error_message.dart'; | ||
import 'package:thunder/shared/sort_picker.dart'; | ||
import 'dart:developer'; | ||
|
||
class CommunityPage extends StatefulWidget { | ||
final int? communityId; | ||
|
@@ -28,6 +29,22 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl | |
@override | ||
bool get wantKeepAlive => true; | ||
|
||
final GlobalKey<NestedScrollViewState> globalKey = GlobalKey(); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) { | ||
globalKey.currentState!.innerController.addListener(() { | ||
if (globalKey.currentState!.innerController.position.pixels >= globalKey.currentState!.innerController.position.maxScrollExtent * 0.7) { | ||
print('endScroll'); | ||
// How do we call this from here? | ||
// context.read<CommunityBloc>().add(GetCommunityPostsEvent(communityId: widget.communityId)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, we won't be able to call this function in the initState function since it has no access to the context. One "hacky" way to pass in the context is to allow CommunityPage to accept a BuildContext as one of its parameters and then use that context here. However, I'm not sure if that's the best way to go about it |
||
} | ||
}); | ||
}); | ||
} | ||
|
||
SortType? sortType; | ||
IconData? sortTypeIcon; | ||
String? sortTypeLabel; | ||
|
@@ -66,48 +83,61 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl | |
}, | ||
builder: (context, state) { | ||
return Scaffold( | ||
key: widget.scaffoldKey, | ||
appBar: AppBar( | ||
title: Text(getCommunityName(state)), | ||
centerTitle: false, | ||
toolbarHeight: 70.0, | ||
actions: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
if ((state.communityId != null || state.communityName != null) && isUserLoggedIn) | ||
IconButton( | ||
icon: Icon( | ||
(state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? Icons.library_add_check_outlined : Icons.library_add_check_rounded, | ||
semanticLabel: (state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? 'Subscribe' : 'Unsubscribe', | ||
), | ||
onPressed: () { | ||
HapticFeedback.mediumImpact(); | ||
context.read<CommunityBloc>().add( | ||
ChangeCommunitySubsciptionStatusEvent( | ||
communityId: state.communityId!, | ||
follow: (state.subscribedType == null) ? true : (state.subscribedType == SubscribedType.notSubscribed ? true : false), | ||
), | ||
); | ||
}, | ||
), | ||
IconButton( | ||
icon: const Icon(Icons.refresh_rounded, semanticLabel: 'Refresh'), | ||
onPressed: () { | ||
HapticFeedback.mediumImpact(); | ||
return context.read<CommunityBloc>().add(GetCommunityPostsEvent(reset: true, sortType: sortType, communityId: state.communityId)); | ||
}), | ||
IconButton( | ||
icon: Icon(sortTypeIcon, semanticLabel: 'Sort By'), | ||
tooltip: sortTypeLabel, | ||
onPressed: () { | ||
HapticFeedback.mediumImpact(); | ||
showSortBottomSheet(context, state); | ||
}), | ||
const SizedBox(width: 8.0), | ||
], | ||
) | ||
], | ||
// key: widget.scaffoldKey, | ||
body: NestedScrollView( | ||
key: globalKey, | ||
floatHeaderSlivers: true, | ||
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { | ||
return <Widget>[ | ||
SliverAppBar( | ||
title: Text(getCommunityName(state)), | ||
pinned: false, | ||
floating: true, | ||
snap: false, | ||
forceElevated: innerBoxIsScrolled, | ||
centerTitle: false, | ||
toolbarHeight: 70.0, | ||
actions: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
if ((state.communityId != null || state.communityName != null) && isUserLoggedIn) | ||
IconButton( | ||
icon: Icon( | ||
(state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? Icons.library_add_check_outlined : Icons.library_add_check_rounded, | ||
semanticLabel: (state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? 'Subscribe' : 'Unsubscribe', | ||
), | ||
onPressed: () { | ||
HapticFeedback.mediumImpact(); | ||
context.read<CommunityBloc>().add( | ||
ChangeCommunitySubsciptionStatusEvent( | ||
communityId: state.communityId!, | ||
follow: (state.subscribedType == null) ? true : (state.subscribedType == SubscribedType.notSubscribed ? true : false), | ||
), | ||
); | ||
}, | ||
), | ||
IconButton( | ||
icon: const Icon(Icons.refresh_rounded, semanticLabel: 'Refresh'), | ||
onPressed: () { | ||
HapticFeedback.mediumImpact(); | ||
return context.read<CommunityBloc>().add(GetCommunityPostsEvent(reset: true, sortType: sortType, communityId: state.communityId)); | ||
}), | ||
IconButton( | ||
icon: Icon(sortTypeIcon, semanticLabel: 'Sort By'), | ||
tooltip: sortTypeLabel, | ||
onPressed: () { | ||
HapticFeedback.mediumImpact(); | ||
showSortBottomSheet(context, state); | ||
}), | ||
const SizedBox(width: 8.0), | ||
], | ||
) | ||
], | ||
), | ||
]; | ||
}, | ||
body: SafeArea(child: _getBody(context, state)), | ||
), | ||
drawer: (widget.communityId != null || widget.communityName != null) ? null : const CommunityDrawer(), | ||
floatingActionButton: ((state.communityId != null || widget.communityName != null) && isUserLoggedIn) | ||
|
@@ -132,7 +162,6 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl | |
), | ||
) | ||
: null, | ||
body: SafeArea(child: _getBody(context, state)), | ||
); | ||
}, | ||
), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a function which requires this package? This seems oddly specific