Skip to content

Commit

Permalink
....
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Dawood committed Nov 11, 2023
1 parent 4e303c2 commit c17d43c
Show file tree
Hide file tree
Showing 20 changed files with 264 additions and 239 deletions.
57 changes: 26 additions & 31 deletions docs/ar/ready_list.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,56 @@
# Complete list that

- Handle pull to refresh
- Infinite scroll
- Making grids


# usage


## First create controller

```dart
class ReadyListCubit extends Cubit<ReadyListState<FakeItem>> implements ReadyListController<FakeItem> {
ReadyListCubit() : super(const ReadyListState.firstState());
/// if you don't need to use loading features you can return null
/// ListLoadingHandler<FakeItem>? get handler =>null
class ReadyListCubit extends DefaultReadyRemoteCubit<FakeItem> {
ReadyListCubit() : super(ReadyListState.initial());
@override
ListLoadingHandler<FakeItem>? get handler => DefaultListLoadingHandler(
loadData: (skip, pageSize, cancelToken) async {
/// Fetch your data
},
controller: this,
);
Future<RemoteResult<FakeItem>> loadData(int skip, int? pageSize,
[ICancelToken? cancelToken]) async {
var list = await FakeRepo.asyncList(pageSize ?? 20);
return RemoteResult.success(list, 100);
}
}
```

# if you want to use your own class or change notifier

# Some times you need to use stage-management rather than bloc
# if so see this example of how to use ValueNotifier as statemangement
```dart
class ReadyListCubit extends ChangeNotifier implements ReadyRemoteController<FakeItem> {
ReadyListState<FakeItem> _state = ReadyListState<FakeItem>();
@override
ReadyListState<FakeItem> get state => _state;
final StreamController<ReadyListState<FakeItem>> _controller = StreamController<ReadyListState<FakeItem>>.broadcast();
@override
Stream<ReadyListState<FakeItem>> get stream => _controller.stream;
class OtherController<T> extends ValueNotifier<ReadyListState<FakeItem>> {
DefaultReadyListController controller =
DefaultReadyListController(ReadyListState.initial());
OtherController(ReadyListState<FakeItem> value) : super(value);
@override
void emit(ReadyListState<FakeItem> state) {
_state = state;
_controller.add(state);
void notifyListeners() {
controller.setState(value);
super.notifyListeners();
}
@override
Future<ReadyListState<FakeItem>> loadData({
ICancelToken? cancelToken,
required int skip,
required int pageSize,
}) async {
/// Fetch your data
void dispose() {
controller.close();
super.dispose();
}
}
```

## List

```dart
return ReadyList.list(
key: Key(DateTime.now().toIso8601String()),
Expand All @@ -81,6 +73,7 @@ return ReadyList.grid(
);
```


## Slivers

```dart
Expand All @@ -92,6 +85,7 @@ return ReadyList.slivers(
);
```


Property | Description | Nullable
-- | ------ | -
scrollController | List scroll controller | ✓
Expand All @@ -118,6 +112,7 @@ topLevelFooterSlivers | The first items in the list | ✓
topLevelHeaderSlivers | The last items in the list | ✓
pageSize | page size to be passed to controller loadData| ✓


# Global config

> you can config your all list with global config
Expand All @@ -127,4 +122,4 @@ ReadyListConfig(
showNoMoreText: false,
child: MaterialApp(),
)
```
```
4 changes: 4 additions & 0 deletions packages/ready_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@
## 2.0.0

* Use ready version 2.0.0

## 2.1.0

* Use ready version 2.1.0
4 changes: 2 additions & 2 deletions packages/ready_picker/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ready_picker
description: Pop up picker that uses ready controllers
version: 2.0.0
version: 2.1.0
homepage: https://github.com/mo-ah-dawood/ready

environment:
Expand All @@ -10,7 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
ready: ^2.0.0
ready: ^2.1.0

dev_dependencies:
flutter_test:
Expand Down
34 changes: 17 additions & 17 deletions packages/ready_validation/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.0"
clock:
dependency: transitive
description:
Expand All @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.17.2"
flutter:
dependency: transitive
description: flutter
Expand All @@ -46,14 +46,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.18.1"
js:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev"
source: hosted
version: "0.6.5"
lints:
dependency: transitive
description:
Expand All @@ -66,18 +58,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.9.1"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -122,6 +114,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=2.17.0-0 <3.0.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=1.17.0"
2 changes: 1 addition & 1 deletion packages/ready_validation/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.17.0 <4.0.0"

dependencies:
ready_validation:
Expand Down
4 changes: 4 additions & 0 deletions ready/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@

* Remove freezd and equatble instead

## 2.1.0

* Use bloc

37 changes: 22 additions & 15 deletions ready/example/lib/ready_grid.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:example/fake_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ready/ready.dart';

class ReadyGridExample extends StatelessWidget {
Expand Down Expand Up @@ -28,24 +27,13 @@ class ReadyGridExample extends StatelessWidget {
),
);
},
controller: ReadyListCubit(ReadyListState.intitial()),
controller: ReadyListCubit(),
);
}
}

abstract class BaseController<T, S extends ReadyListState<T>> extends Cubit<S>
implements ReadyListController<T, S> {
BaseController(S initialState) : super(initialState);
}

abstract class BaseController2<T> extends BaseController<T, ReadyListState<T>>
with ReadyListControllerCopyMixin {
BaseController2(ReadyListState<T> initialState) : super(initialState);
}

class ReadyListCubit extends BaseController2<FakeItem>
with ReadyRemoteControllerMixin {
ReadyListCubit(ReadyListState<FakeItem> initialState) : super(initialState);
class ReadyListCubit extends DefaultReadyRemoteController<FakeItem> {
ReadyListCubit() : super(ReadyListState.initial());

@override
Future<RemoteResult<FakeItem>> loadData(int skip, int? pageSize,
Expand All @@ -54,3 +42,22 @@ class ReadyListCubit extends BaseController2<FakeItem>
return RemoteResult.success(list, 100);
}
}

class OtherController<T> extends ValueNotifier<ReadyListState<FakeItem>> {
DefaultReadyListController controller =
DefaultReadyListController(ReadyListState.initial());

OtherController(ReadyListState<FakeItem> value) : super(value);

@override
void notifyListeners() {
controller.setState(value);
super.notifyListeners();
}

@override
void dispose() {
controller.close();
super.dispose();
}
}
25 changes: 3 additions & 22 deletions ready/example/lib/ready_list.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:example/fake_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ready/ready.dart';

class ReadyListExample extends StatelessWidget {
Expand All @@ -20,7 +19,7 @@ class ReadyListExample extends StatelessWidget {
buildItem: (FakeItem? item, int index) {
return _buildItem(item, index);
},
controller: ReadyListCubit(ReadyListState.intitial()),
controller: ReadyListCubit(ReadyListState.initial()),
);
}

Expand Down Expand Up @@ -55,31 +54,13 @@ class ReadyListExample extends StatelessWidget {
}
}

abstract class BaseController<T, S extends ReadyListState<T>> extends Cubit<S>
implements ReadyListController<T, S> {
BaseController(S initialState) : super(initialState);
}

abstract class BaseController2<T> extends BaseController<T, ReadyListState<T>>
with ReadyListControllerCopyMixin {
BaseController2(ReadyListState<T> initialState) : super(initialState);
}

class ReadyListCubit extends BaseController2<FakeItem>
with ReadyRemoteControllerMixin {
class ReadyListCubit extends DefaultReadyRemoteController<FakeItem> {
ReadyListCubit(ReadyListState<FakeItem> initialState) : super(initialState);

@override
Future<RemoteResult<FakeItem>> loadData(int skip, int? pageSize,
[ICancelToken? cancelToken]) async {
var list = await FakeRepo.asyncList(30, 0, const Duration(seconds: 3));
var list = await FakeRepo.asyncList(pageSize ?? 20);
return RemoteResult.success(list, 100);
}

@override
void onChange(Change<ReadyListState<FakeItem>> change) {
// print(change.currentState);
// print(change.nextState);
super.onChange(change);
}
}
18 changes: 3 additions & 15 deletions ready/example/lib/responsive.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:example/fake_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ready/ready.dart';

class ResponsiveList extends StatelessWidget {
final controller = ReadyListCubit(ReadyListState.intitial());
final controller = ReadyListCubit(ReadyListState.initial());
final bool sub;
ResponsiveList({
Key? key,
Expand Down Expand Up @@ -110,24 +109,13 @@ class ResponsiveList extends StatelessWidget {
}
}

abstract class BaseController<T, S extends ReadyListState<T>> extends Cubit<S>
implements ReadyListController<T, S> {
BaseController(S initialState) : super(initialState);
}

abstract class BaseController2<T> extends BaseController<T, ReadyListState<T>>
with ReadyListControllerCopyMixin {
BaseController2(ReadyListState<T> initialState) : super(initialState);
}

class ReadyListCubit extends BaseController2<FakeItem>
with ReadyRemoteControllerMixin {
class ReadyListCubit extends DefaultReadyRemoteController<FakeItem> {
ReadyListCubit(ReadyListState<FakeItem> initialState) : super(initialState);
int value = 1;
@override
Future<RemoteResult<FakeItem>> loadData(int skip, int? pageSize,
[ICancelToken? cancelToken]) async {
var list = await FakeRepo.asyncList(pageSize ?? 20, skip);
var list = await FakeRepo.asyncList(pageSize ?? 20);
return RemoteResult.success(list, 100);
}
}
2 changes: 1 addition & 1 deletion ready/lib/src/animated_items/animated_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class _AnimatedState extends State<Animated> with TickerProviderStateMixin {
.transform(t),
child: Transform(
transform: transform,
alignment:widget.alignment,
alignment: widget.alignment,
child: widget.builder(t),
),
);
Expand Down
Loading

0 comments on commit c17d43c

Please sign in to comment.