Skip to content
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

Removed feed wrapper #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions lib/feeds/feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Feed extends StatefulWidget {

final IndexedFeedBuilder? indexedBuilder;

///defines the height to offset the body
///defines the height to offset the body, for external footers
final double? footerHeight;

///Determines if the the feed should initially load, defaulted to true
Expand All @@ -56,12 +56,15 @@ class Feed extends StatefulWidget {
/// Loading widget
final Widget? loading;

/// Header widget
final Widget? header;

/// Footer widget
final Widget? footer;

///Retrieves the item id, used to ensure the prevention of duplicate additions
final RetrievalFunction? getItemID;

///The optional function used to wrap the list view
final WidgetWrapper? wrapper;

/// Items that will be pinned to the top of the list on init
final List<dynamic>? pinnedItems;

Expand All @@ -71,10 +74,6 @@ class Feed extends StatefulWidget {
/// The amount of items that are rendered at once
final int? renderCount;

/// Determines if the place holder should be used when the feed is empty
/// Defaulted to true
final bool usePlaceholder;

/// Physics
final ScrollPhysics? physics;

Expand All @@ -91,16 +90,16 @@ class Feed extends StatefulWidget {
this.footerHeight,
this.placeholder,
this.loading,
this.header,
this.footer,
this.disableScroll,
this.getItemID,
this.wrapper,
this.scrollController,
this.compact = false,
this.initiallyLoad = true,
this.pinnedItems,
this.reverse = false,
this.renderCount,
this.usePlaceholder = true,
this.usePrimaryScrollController = false,
this.physics
}) : super(key: key);
Expand Down Expand Up @@ -342,13 +341,6 @@ class _FeedState extends State<Feed> {
widget.controller?._update();
}

Widget wrapperBuilder({required BuildContext context, required Widget child, dynamic item}){
if(widget.wrapper != null){
return widget.wrapper!(context, child, item);
}
return child;
}

///Keeps track of the added items are removes them from future loads
void addItem(dynamic item){

Expand All @@ -369,7 +361,7 @@ class _FeedState extends State<Feed> {
Widget _buildFeed(bool loadMore, int size) {
Widget view = SizedBox();

if (size == 0 && !loadMore && widget.usePlaceholder) {
if (size == 0 && !loadMore) {
if(widget.placeholder != null){
//No items placeholder
view = widget.placeholder!;
Expand All @@ -387,10 +379,11 @@ class _FeedState extends State<Feed> {
gridDelegate: widget.controller?.getGridDelegate(),
disableScroll: widget.disableScroll == null ? false : widget.disableScroll,
footerHeight: widget.footerHeight == null ? 0 : widget.footerHeight,
wrapper: widget.wrapper,
onLoad: _loadMore,
footer: widget.footer,
header: widget.header,
builder: (context, i, items){
if (i == items.length) {
if (i == items.length + 1) {
return loadMore ? load : SizedBox.shrink();
}
return widget.indexedBuilder?.call(items, i) ?? widget.childBuilder!(items[i], items.length - 1 == i);
Expand Down
132 changes: 73 additions & 59 deletions lib/feeds/feed_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class FeedListView extends StatefulWidget {
final double? footerHeight;

///Loading widget
final Widget? loading;
final Widget? header;

///The optional function used to wrap the list view
final WidgetWrapper? wrapper;
///Loading widget
final Widget? footer;

///If defined builds this feed in grid mode
final FeedGridViewDelegate? gridDelegate;
Expand All @@ -65,7 +65,7 @@ class FeedListView extends StatefulWidget {
/// Physics
final ScrollPhysics? physics;

const FeedListView({
const FeedListView({
Key? key,
this.usePrimaryScrollController = false,
this.disableScroll = false,
Expand All @@ -75,8 +75,8 @@ class FeedListView extends StatefulWidget {
required this.builder,
required this.controller,
this.footerHeight,
this.wrapper,
this.loading,
this.header,
this.footer,
this.gridDelegate,
this.physics
}) : super(key: key);
Expand All @@ -89,65 +89,91 @@ class _FeedListViewState extends State<FeedListView> {

ScrollController get scrollController => widget.controller;

Widget get loading => widget.loading == null ? Container() : widget.loading!;

Widget wrapperBuilder({required BuildContext context, required Widget child, required dynamic item}){
if(widget.wrapper != null){
return widget.wrapper!(context, child, item);
}
return child;
}
Widget get header => widget.header ?? SizedBox.shrink();
Widget get footer => widget.footer ?? SizedBox.shrink();

Widget listBuilder(BuildContext context, List items){

///Simple List
late Widget list;
final scrollPhysics = widget.physics != null ? widget.physics : widget.disableScroll == true ? NeverScrollableScrollPhysics() : BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics());
final controller = widget.usePrimaryScrollController ? null : scrollController;
final footerHeightAdjustment = Container(
height: widget.footerHeight ?? 0,
);

if(items.isEmpty){
list = SizedBox.shrink();
return SizedBox.shrink();
}
else if(widget.gridDelegate != null){
//Grid list
list = StaggeredGridView.countBuilder(
reverse: widget.reverse,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
addRepaintBoundaries: true,
crossAxisCount: widget.gridDelegate!.crossAxisCount,
mainAxisSpacing: widget.gridDelegate!.mainAxisSpacing,
crossAxisSpacing: widget.gridDelegate!.crossAxisSpacing,
padding: widget.gridDelegate!.padding,
itemCount: items.length + 1,
itemBuilder: (context, i) => widget.builder(context, i, items),
staggeredTileBuilder: (index) => StaggeredTile.fit(1),
Widget list = Column(
children: [

header,

StaggeredGridView.countBuilder(
reverse: widget.reverse,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
addRepaintBoundaries: true,
crossAxisCount: widget.gridDelegate!.crossAxisCount,
mainAxisSpacing: widget.gridDelegate!.mainAxisSpacing,
crossAxisSpacing: widget.gridDelegate!.crossAxisSpacing,
padding: widget.gridDelegate!.padding,
itemCount: items.length + 1,
itemBuilder: (context, i) => widget.builder(context, i, items),
staggeredTileBuilder: (index) => StaggeredTile.fit(1),
),

footer,

footerHeightAdjustment
],
);

if(widget.compact){
return list;
}
else{
return SingleChildScrollView(
reverse: widget.reverse,
physics: scrollPhysics,
controller: controller,
child: list,
);
}
}
else{
list = ListView.builder(
return ListView.builder(
controller: controller,
reverse: widget.reverse,
padding: EdgeInsets.zero,
shrinkWrap: true,
addRepaintBoundaries: true,
physics: NeverScrollableScrollPhysics(),
itemCount: items.length + 1,
itemBuilder: (context, i) => widget.builder(context, i, items),
physics: widget.compact ? NeverScrollableScrollPhysics() : scrollPhysics,
itemCount: items.length + 3,
itemBuilder: (context, i){
if(i == 0){
return header;
}
else if(i == items.length){
//footer
return Column(
mainAxisSize: MainAxisSize.min,
children: [
footer,
footerHeightAdjustment
],
);
}
else{
//items
return widget.builder(context, i - 1, items);
}
},
);
}


return Column(
children: [
wrapperBuilder(
context: context,
child: list,
item: items.isEmpty ? null : items[0]
),

Container(
height: widget.footerHeight ?? 0,
)
],
);
}


Expand All @@ -164,21 +190,9 @@ class _FeedListViewState extends State<FeedListView> {
distinct: true,
converter: (store) => store.state.items,
builder: (context, items) {

late Widget list = listBuilder(context, items);

if(!widget.compact){
list = SingleChildScrollView(
reverse: widget.reverse,
physics: widget.physics != null ? widget.physics : widget.disableScroll == true ? NeverScrollableScrollPhysics() : BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
controller: widget.usePrimaryScrollController ? null : scrollController,
child: list,
);
}

return Container(
height: widget.compact ? null : MediaQuery.of(context).size.height,
child: list,
child: listBuilder(context, items),
);
}
),
Expand Down
30 changes: 20 additions & 10 deletions lib/feeds/sliding_sheet_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class SlidingSheetFeed extends StatelessWidget {
/// Loading widget
final Widget? loading;

/// Loading widget
final Widget? header;

/// Loading widget
final Widget? footer;

///Retrieves the item id, used to ensure the prevention of duplicate additions
final RetrievalFunction? getItemID;

///The optional function used to wrap the list view
final WidgetWrapper? wrapper;

/// Items that will be pinned to the top of the list on init
final List<dynamic>? pinnedItems;

Expand Down Expand Up @@ -92,8 +95,9 @@ class SlidingSheetFeed extends StatelessWidget {
this.disableScroll,
this.placeholder,
this.loading,
this.header,
this.footer,
this.getItemID,
this.wrapper,
this.pinnedItems,
this.sheetController,
this.staticSheet = false,
Expand Down Expand Up @@ -138,8 +142,9 @@ class SlidingSheetFeed extends StatelessWidget {
disableScroll: disableScroll,
placeholder: placeholder,
loading: loading,
feedHeader: header,
feedFooter: footer,
getItemID: getItemID,
wrapper: wrapper,
pinnedItems: pinnedItems,
header: headerBuilder,
staticScrollModifier: staticScrollModifier
Expand Down Expand Up @@ -175,19 +180,24 @@ class PerceiveSlidableSingleFeedDelegate extends ScrollablePerceiveSlidableDeleg
/// Loading widget
final Widget? loading;

/// Loading widget
final Widget? feedHeader;

/// Loading widget
final Widget? feedFooter;

///Retrieves the item id, used to ensure the prevention of duplicate additions
final RetrievalFunction? getItemID;

///The optional function used to wrap the list view
final WidgetWrapper? wrapper;

/// Items that will be pinned to the top of the list on init
final List<dynamic>? pinnedItems;

final Widget Function(BuildContext context, dynamic pageObj, Widget spacer, double borderRadius)? header;

PerceiveSlidableSingleFeedDelegate({
required this.loader,
required this.feedHeader,
required this.feedFooter,
required this.controller,
required this.footerHeight,
required this.lengthFactor,
Expand All @@ -198,7 +208,6 @@ class PerceiveSlidableSingleFeedDelegate extends ScrollablePerceiveSlidableDeleg
required this.placeholder,
required this.loading,
required this.getItemID,
required this.wrapper,
required this.pinnedItems,
required this.header,
double staticScrollModifier = 0.0
Expand All @@ -216,6 +225,8 @@ class PerceiveSlidableSingleFeedDelegate extends ScrollablePerceiveSlidableDeleg
footerHeight: (this.footerHeight ?? 0) + footerHeight,
scrollController: scrollController,
loader: loader,
header: feedHeader,
footer: feedFooter,
controller: controller,
lengthFactor: lengthFactor,
initialLength: initialLength,
Expand All @@ -225,7 +236,6 @@ class PerceiveSlidableSingleFeedDelegate extends ScrollablePerceiveSlidableDeleg
placeholder: placeholder?.call(context, state?.extent ?? initialExtent),
loading: loading,
getItemID: getItemID,
wrapper: wrapper,
pinnedItems: pinnedItems,
);
}
Expand Down
Loading