Skip to content

Commit

Permalink
Release 4.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
a-abramov committed Aug 7, 2024
1 parent c6c2ed1 commit 5a0d2eb
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: flutter-actions/setup-flutter@v2
with:
channel: stable
version: 3.22.2
version: 3.24.0

- name: Install dependencies
run: flutter pub get
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: flutter-actions/setup-flutter@v2
with:
channel: stable
version: 3.22.2
version: 3.24.0

- name: Analyze
run: flutter analyze
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [4.6.0]

- Refactored LoadableList & PaginatedeLoadableList constructors signature
- BREAKING CHANGE: `items` replaced with `itemCount`. `itemBuilder` and `itemSeparator` now requires additional param `BuildContext` according to the `ListView.builder` constructor

## [4.5.0]

- Bump dependencies
Expand Down
30 changes: 15 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: async_redux
sha256: "7181cd00c0a798b21fae02650448a57498179ddcfa5fa9b25b0fef1a60bd07d7"
sha256: "592e4d11b618045ff9c45a1b3478f6b409695072ad98da2dc536b6571ddebdbe"
url: "https://pub.dev"
source: hosted
version: "23.0.2"
version: "23.1.1"
async_redux_core:
dependency: transitive
description:
Expand Down Expand Up @@ -223,7 +223,7 @@ packages:
path: ".."
relative: true
source: path
version: "4.5.0"
version: "4.6.0"
dbus:
dependency: transitive
description:
Expand Down Expand Up @@ -363,18 +363,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -403,18 +403,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.8.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.15.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -632,10 +632,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.7.2"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -664,10 +664,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
url: "https://pub.dev"
source: hosted
version: "14.2.1"
version: "14.2.4"
watcher:
dependency: transitive
description:
Expand Down
34 changes: 15 additions & 19 deletions lib/src/loadable/loadable_grid_view.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import 'package:dash_kit_core/dash_kit_core.dart';
import 'package:flutter/material.dart';

class LoadableGridView<T extends StoreListItem> extends StatefulWidget {
class LoadableGridView extends StatefulWidget {
const LoadableGridView({
required this.viewModel,
this.onChangeContentOffset,
this.scrollController,
super.key,
});

final LoadableGridViewModel<T> viewModel;
final LoadableGridViewModel viewModel;
final ScrollListener? onChangeContentOffset;
final ScrollController? scrollController;

@override
State<StatefulWidget> createState() {
return LoadableGridViewState<T>();
return LoadableGridViewState();
}
}

class LoadableGridViewState<T extends StoreListItem>
extends State<LoadableGridView> {
LoadableGridViewModel<T> get viewModel =>
widget.viewModel as LoadableGridViewModel<T>;
class LoadableGridViewState extends State<LoadableGridView> {
LoadableGridViewModel get viewModel => widget.viewModel;

@override
void initState() {
Expand Down Expand Up @@ -66,13 +64,13 @@ class LoadableGridViewState<T extends StoreListItem>
gridDelegate: viewModel.gridDelegate,
delegate: SliverChildBuilderDelegate(
buildListItem,
childCount: viewModel.itemsCount,
childCount: viewModel.itemCount,
),
),
),
SliverToBoxAdapter(
// ignore: avoid-returning-widgets
child: getLastItem(),
child: buildLastItem(),
),
],
),
Expand All @@ -85,11 +83,11 @@ class LoadableGridViewState<T extends StoreListItem>
);
}

Widget buildListItem(BuildContext _, int index) {
return viewModel.itemBuilder(index);
Widget buildListItem(BuildContext context, int index) {
return viewModel.itemBuilder(context, index);
}

Widget getLastItem() {
Widget buildLastItem() {
return const SizedBox.shrink();
}

Expand All @@ -101,10 +99,10 @@ class LoadableGridViewState<T extends StoreListItem>
false;
}

class LoadableGridViewModel<Item extends StoreListItem> {
class LoadableGridViewModel {
const LoadableGridViewModel({
required this.itemBuilder,
required this.items,
required this.itemCount,
required this.loadListRequestState,
required this.errorWidget,
required this.emptyStateWidget,
Expand All @@ -121,25 +119,23 @@ class LoadableGridViewModel<Item extends StoreListItem> {
final Key? key;
final Widget errorWidget;
final Widget emptyStateWidget;
final Widget Function(int) itemBuilder;
final IndexedWidgetBuilder itemBuilder;
final VoidCallback? loadList;
final EdgeInsets? padding;
final List<Item> items;
final int itemCount;
final OperationState loadListRequestState;
final OperationState? loadPageRequestState;
final SliverGridDelegate gridDelegate;
final ScrollPhysics? physics;
final Widget? header;
final bool shrinkWrap;

int get itemsCount => items.length;

PaginationState getPaginationState() {
if (loadListRequestState.isFailed) {
return PaginationState.error;
} else if (loadListRequestState.isInProgress) {
return PaginationState.loading;
} else if (loadListRequestState.isSucceed && items.isEmpty) {
} else if (loadListRequestState.isSucceed && itemCount == 0) {
return PaginationState.empty;
}

Expand Down
41 changes: 21 additions & 20 deletions lib/src/loadable/loadable_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import 'dart:math';

import 'package:dash_kit_core/src/loadable/pagination_state.dart';
import 'package:dash_kit_core/src/states/operation_state.dart';
import 'package:dash_kit_core/src/utils/store_list.dart';
import 'package:flutter/material.dart';

typedef ScrollListener = bool Function({
required double offset,
required double maxScrollExtent,
});

class LoadableListView<T extends StoreListItem> extends StatefulWidget {
class LoadableListView extends StatefulWidget {
const LoadableListView({
required this.viewModel,
this.scrollPhysics = const AlwaysScrollableScrollPhysics(),
Expand All @@ -24,7 +23,7 @@ class LoadableListView<T extends StoreListItem> extends StatefulWidget {
super.key,
});

final LoadableListViewModel<T> viewModel;
final LoadableListViewModel viewModel;
final ScrollPhysics scrollPhysics;
final ScrollListener? onChangeContentOffset;
final double? cacheExtent;
Expand All @@ -36,14 +35,12 @@ class LoadableListView<T extends StoreListItem> extends StatefulWidget {

@override
State<StatefulWidget> createState() {
return LoadableListViewState<T>();
return LoadableListViewState();
}
}

class LoadableListViewState<T extends StoreListItem>
extends State<LoadableListView> {
LoadableListViewModel<T> get viewModel =>
widget.viewModel as LoadableListViewModel<T>;
class LoadableListViewState extends State<LoadableListView> {
LoadableListViewModel get viewModel => widget.viewModel;

@override
void initState() {
Expand Down Expand Up @@ -114,11 +111,13 @@ class LoadableListViewState<T extends StoreListItem>
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
sliverDelegateBuilder,
childCount: _computeActualChildCount(viewModel.itemsCount),
childCount: _computeActualChildCount(viewModel.itemCount),
),
),
),
// ignore: avoid-returning-widgets
SliverToBoxAdapter(child: buildLastItem(state)),
// ignore: avoid-returning-widgets
if (viewModel.footer != null) buildFooter(),
];
}
Expand All @@ -138,11 +137,11 @@ class LoadableListViewState<T extends StoreListItem>
}

Widget buildListItem(int index) {
return viewModel.itemBuilder(index);
return viewModel.itemBuilder(context, index);
}

Widget buildSeparator(int index) {
return viewModel.itemSeparator(index);
return viewModel.separatorBuilder(context, index);
}

Widget buildFooter() {
Expand All @@ -159,16 +158,20 @@ class LoadableListViewState<T extends StoreListItem>
static int _computeActualChildCount(int itemCount) {
return max(0, itemCount * 2 - 1);
}

Widget buildLastItem(PaginationState state) {
return const SizedBox();
}
}

class LoadableListViewModel<Item extends StoreListItem> {
class LoadableListViewModel {
const LoadableListViewModel({
required this.items,
required this.itemCount,
required this.itemBuilder,
required this.emptyStateWidget,
required this.loadListRequestState,
required this.errorWidget,
required this.itemSeparator,
required this.separatorBuilder,
this.loadList,
this.padding,
this.sliverHeader,
Expand All @@ -177,9 +180,9 @@ class LoadableListViewModel<Item extends StoreListItem> {
this.key,
});

final List<Item> items;
final Widget Function(int) itemBuilder;
final Widget Function(int) itemSeparator;
final int itemCount;
final IndexedWidgetBuilder itemBuilder;
final IndexedWidgetBuilder separatorBuilder;
final Widget errorWidget;
final Widget emptyStateWidget;
final OperationState loadListRequestState;
Expand All @@ -190,8 +193,6 @@ class LoadableListViewModel<Item extends StoreListItem> {
final Widget? footer;
final Key? key;

int get itemsCount => items.length;

PaginationState getPaginationState() {
if (loadListRequestState.isFailed) {
return PaginationState.error;
Expand All @@ -202,7 +203,7 @@ class LoadableListViewModel<Item extends StoreListItem> {
}

if ((loadListRequestState.isSucceed || loadListRequestState.isRefreshing) &&
items.isEmpty) {
itemCount == 0) {
return PaginationState.empty;
}

Expand Down
Loading

0 comments on commit 5a0d2eb

Please sign in to comment.