Skip to content
Merged
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
4 changes: 4 additions & 0 deletions packages/leancode_cubit_utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0

* **BREAKING CHANGE**: Rename `builder` parameter to `onSuccess` in `RequestCubitBuilder`

## 0.3.2

* Upgrade `bloc` to ^9.0.0
Expand Down
4 changes: 2 additions & 2 deletions packages/leancode_cubit_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ If you call `refresh()` on `ArgsRequestCubit` it will perform a request with the
- `WidgetBuilder? onInitial` - use it to show a widget before invoking the request for the first time,
- `WidgetBuilder? onLoading` - use it to show a loader widget while the request is being performed,
- `WidgetBuilder? onError` - use it to show error widget when processing the request fails,
- `RequestWidgetBuilder<TOut> builder` - use it to build a page when the data is successfully loaded.
- `RequestWidgetBuilder<TOut> onSuccess` - use it to build a page when the data is successfully loaded.

Other than builders, you also need to provide the cubit based on which the `RequestCubitBuilder` will be rebuilt. And you can also pass `onErrorCallback` which allows you to pass a callback to error widget builder. You may want to use it to implement retry button.

Expand All @@ -122,7 +122,7 @@ RequestCubitBuilder(
),
),
onErrorCallback: context.read<ProjectDetailsCubit>().run,
builder: (context, data) {
onSuccess: (context, data) {
return ListView.builder(
itemCount: data.assignments.length,
itemBuilder: (context, index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RequestPage extends StatelessWidget {
Center(
child: RequestCubitBuilder(
cubit: context.read<UserRequestCubit>(),
builder: (context, data) =>
onSuccess: (context, data) =>
Text('${data.name} ${data.surname}'),
),
),
Expand Down
18 changes: 9 additions & 9 deletions packages/leancode_cubit_utils/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ packages:
dependency: "direct main"
description:
name: async
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
url: "https://pub.dev"
source: hosted
version: "2.12.0"
version: "2.13.0"
bloc:
dependency: transitive
description:
Expand Down Expand Up @@ -69,10 +69,10 @@ packages:
dependency: transitive
description:
name: fake_async
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
url: "https://pub.dev"
source: hosted
version: "1.3.2"
version: "1.3.3"
faker:
dependency: "direct main"
description:
Expand Down Expand Up @@ -135,10 +135,10 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
url: "https://pub.dev"
source: hosted
version: "10.0.8"
version: "10.0.9"
leak_tracker_flutter_testing:
dependency: transitive
description:
Expand All @@ -161,7 +161,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.2"
version: "0.4.0"
leancode_hooks:
dependency: "direct main"
description:
Expand Down Expand Up @@ -315,10 +315,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
url: "https://pub.dev"
source: hosted
version: "14.3.1"
version: "15.0.0"
web:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ typedef RequestErrorBuilder<TError> = Widget Function(
/// A widget that builds itself based on the latest request state.
class RequestCubitBuilder<TOut, TError> extends StatelessWidget {
/// Creates a new [RequestCubitBuilder] with the given [cubit] and
/// [builder].
/// [onSuccess].
const RequestCubitBuilder({
super.key,
required this.cubit,
required this.builder,
required this.onSuccess,
this.onInitial,
this.onLoading,
this.onEmpty,
Expand All @@ -35,7 +35,7 @@ class RequestCubitBuilder<TOut, TError> extends StatelessWidget {
final BaseRequestCubit<dynamic, dynamic, TOut, TError> cubit;

/// The builder that creates a widget when data successfully loaded.
final RequestWidgetBuilder<TOut> builder;
final RequestWidgetBuilder<TOut> onSuccess;

/// The builder that creates a widget when state is initial.
final WidgetBuilder? onInitial;
Expand Down Expand Up @@ -66,9 +66,9 @@ class RequestCubitBuilder<TOut, TError> extends StatelessWidget {
config.onLoading(context),
RequestLoadingState() =>
onLoading?.call(context) ?? config.onLoading(context),
RequestSuccessState(:final data) => builder(context, data),
RequestSuccessState(:final data) => onSuccess(context, data),
RequestRefreshState(:final data) => data != null
? builder(context, data)
? onSuccess(context, data)
: onLoading?.call(context) ?? config.onLoading(context),
RequestEmptyState() => onEmpty?.call(context) ??
config.onEmpty?.call(context) ??
Expand Down
2 changes: 1 addition & 1 deletion packages/leancode_cubit_utils/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: leancode_cubit_utils
description: A collection of cubits and widgets that facilitate the creation of repetitive pages, eliminating boilerplate.
version: 0.3.2
version: 0.4.0
repository: https://github.com/leancodepl/leancode_cubit_utils

environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void main() {
TestPage(
child: RequestCubitBuilder(
cubit: queryCubit,
builder: (context, data) => Text(data),
onSuccess: (context, data) => Text(data),
),
),
);
Expand All @@ -83,7 +83,7 @@ void main() {
TestPage(
child: RequestCubitBuilder(
cubit: queryCubit,
builder: (context, data) => Text(data),
onSuccess: (context, data) => Text(data),
),
),
);
Expand All @@ -106,7 +106,7 @@ void main() {
cubit: queryCubit,
onLoading: (context) => const Text('Custom loading...'),
onError: (context, error, retry) => const Text('Custom error!'),
builder: (context, data) => Text(data),
onSuccess: (context, data) => Text(data),
),
),
);
Expand All @@ -127,7 +127,7 @@ void main() {
TestPage(
child: RequestCubitBuilder(
cubit: queryCubit,
builder: (context, data) => Text('Success, data: $data'),
onSuccess: (context, data) => Text('Success, data: $data'),
),
),
);
Expand All @@ -145,7 +145,7 @@ void main() {
TestPage(
child: RequestCubitBuilder(
cubit: queryCubit,
builder: (context, data) => Text('Success, data: $data'),
onSuccess: (context, data) => Text('Success, data: $data'),
),
),
);
Expand Down
4 changes: 4 additions & 0 deletions packages/leancode_cubit_utils_cqrs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0

* Update `leancode_cubit_utils` dependency to `^0.4.0` (includes breaking change: `builder` parameter renamed to `onSuccess` in `RequestCubitBuilder`)

## 0.3.1

* Upgrade `bloc` to ^9.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class QueryHookPage extends HookWidget {
Center(
child: RequestCubitBuilder(
cubit: userCubit,
builder: (context, data) => Text('${data.name} ${data.surname}'),
onSuccess: (context, data) =>
Text('${data.name} ${data.surname}'),
),
),
const SizedBox(height: 16),
Expand Down Expand Up @@ -87,7 +88,7 @@ class QueryPage extends StatelessWidget {
Center(
child: RequestCubitBuilder(
cubit: context.read<UserQueryCubit>(),
builder: (context, data) =>
onSuccess: (context, data) =>
Text('${data.name} ${data.surname}'),
),
),
Expand Down
Loading
Loading