Skip to content

Commit

Permalink
Merge pull request #10 from The-Artista/9-fix-rebuild-on-argument-change
Browse files Browse the repository at this point in the history
9 fix rebuild on argument change
  • Loading branch information
ishafiul authored Feb 27, 2024
2 parents 936ea7a + 370d7f4 commit 756994c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Loadmore Data

[![Pub](https://img.shields.io/pub/v/loadmore_data.svg)](https://pub.dartlang.org/packages/loadmore_data)
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://opensource.org/licenses/MIT)
[![License](https://img.shields.io/badge/license-MIT-orange.svg)](https://github.com/ionicfirebaseapp/getwidget/blob/master/LICENSE)
[![License](https://img.shields.io/badge/license-MIT-orange.svg)](https://github.com/ionicfirebaseapp/getwidget/blob/master/LICENSE)

loadmore_data is a flutter package that can handel infinity scroll pagination

## Demo

![loadmore_data](https://www.ishaf.info/load_more.gif "loadmore_data demo")

![loadmore_data](https://pub-025eba96160d45eb8b4d209ff55bfdc6.r2.dev/load_more.gif "loadmore_data demo")

## Installation 💻

Expand All @@ -17,20 +17,20 @@ installed on your machine.**

Add `loadmore_data` to your `pubspec.yaml`:

```yaml
``` yaml
dependencies:
loadmore_data:
```
Install it:
```sh
``` sh
flutter packages get
```

## Example

```dart
``` dart
LoadMoreListData(
onInit: () async {
// call api for initial data and return list of data
Expand All @@ -57,17 +57,19 @@ LoadMoreListData(
},
),
```

## Parameters
| Parameter | Definition |

| Parameter | Definition |
|-----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`OnInit<T> onInit`| [onInit] is a required argument for the [LoadMoreListData] widget. It takes a function that will return [OnInit] . [OnInit] can be `FutureOr<Iterable<T>>` This function will call on `initState` of [LoadMoreListData]'s life cycle |
|`OnLoad<T> onLoad`| [onLoad] is a required argument for the [LoadMoreListData] widget. It takes a function that will return [OnLoad] . [OnLoad] can be `FutureOr<Iterable<T>>` This function will call when the user reached to the end of the list of data |
|`ItemBuilder<T> builder`| builder will [BuildContext] and `itemData` as a single item. and it will expect a widget that will represent a single item |
|`Widget? onInitialLoading`| [onInitialLoading] is a widget that will display until the initial data is loaded |
|`Widget? onLoadMoreLoading`| [onLoadMoreLoading] is a widget at end of the list that will display when waiting for a response on a pagination API request |
|`Widget? onNoData`| [onNoData] is a widget that will have no more data to display |
|`Widget? topWidget`| you can pass an additional widget that will display on top of the list |
|`Widget? bottomWidget`| you can pass an additional widget that will display on the bottom of the list |
|`int? initPage`| [initPage] will take a [int] value representing the initial circle of requests. by default its is `1` |
|`EdgeInsetsGeometry? padding`| padding for [LoadMoreListData] widget |
|`EdgeInsetsGeometry? itemPadding`| padding for [LoadMoreListData] widget's items |
| `OnInit<T> onInit` | [onInit] is a required argument for the [LoadMoreListData] widget. It takes a function that will return [OnInit] . [OnInit] can be `FutureOr<Iterable<T>>` This function will call on `initState` of [LoadMoreListData]'s life cycle |
| `OnLoad<T> onLoad` | [onLoad] is a required argument for the [LoadMoreListData] widget. It takes a function that will return [OnLoad] . [OnLoad] can be `FutureOr<Iterable<T>>` This function will call when the user reached to the end of the list of data |
| `ItemBuilder<T> builder` | builder will [BuildContext] and `itemData` as a single item. and it will expect a widget that will represent a single item |
| `Widget? onInitialLoading` | [onInitialLoading] is a widget that will display until the initial data is loaded |
| `Widget? onLoadMoreLoading` | [onLoadMoreLoading] is a widget at end of the list that will display when waiting for a response on a pagination API request |
| `Widget? onNoData` | [onNoData] is a widget that will have no more data to display |
| `Widget? topWidget` | you can pass an additional widget that will display on top of the list |
| `Widget? bottomWidget` | you can pass an additional widget that will display on the bottom of the list |
| `int? initPage` | [initPage] will take a [int] value representing the initial circle of requests. by default its is `1` |
| `EdgeInsetsGeometry? padding` | padding for [LoadMoreListData] widget |
| `EdgeInsetsGeometry? itemPadding` | padding for [LoadMoreListData] widget's items |
12 changes: 12 additions & 0 deletions lib/src/load_more_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ class _LoadMoreListDataState<T> extends State<LoadMoreListData<T>> {
super.dispose();
}

@override
void didUpdateWidget(covariant LoadMoreListData<T> oldWidget) {
if (oldWidget.onInit != widget.onInit) {
index = widget.initPage != null ? widget.initPage! + 1 : 2;
isInitData = false;
isNoData = false;
initData();
setState(() {});
}
super.didUpdateWidget(oldWidget);
}

@override
Widget build(BuildContext context) {
return ListView(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: loadmore_data
description: loadmore_data is a flutter package that can handel infinity scroll pagination
version: 0.0.1+3
version: 0.0.2
homepage: https://github.com/ishafiul/loadmore_data
repository: https://github.com/ishafiul/loadmore_data

Expand Down

0 comments on commit 756994c

Please sign in to comment.