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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.0.15
* Added `FutureOr<T?>` to `showNativeDialog` as return type;

## 0.0.14
* Added Pagination
* Added RefreshStreamMixin
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.13"
version: "0.0.14"
equatable:
dependency: transitive
description:
Expand Down
5 changes: 1 addition & 4 deletions lib/dcc_toolkit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ export 'common/mixins/refresh_stream_mixin.dart';
export 'common/result/result.dart';
export 'common/type_defs.dart';
export 'logger/bolt_logger.dart';
export 'pagination/paginated_scroll_view.dart';
export 'pagination/pagination_interface.dart';
export 'pagination/pagination_mixin.dart';
export 'pagination/pagination_state.dart';
export 'pagination/paginated.dart';
export 'style/style.dart';
export 'test_util/devices_sizes.dart';
export 'test_util/presentation_event_catcher.dart';
Expand Down
4 changes: 4 additions & 0 deletions lib/pagination/paginated.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'package:dcc_toolkit/pagination/paginated_scroll_view.dart';
export 'package:dcc_toolkit/pagination/pagination_interface.dart';
export 'package:dcc_toolkit/pagination/pagination_mixin.dart';
export 'package:dcc_toolkit/pagination/pagination_state.dart';
2 changes: 1 addition & 1 deletion lib/pagination/pagination_state.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// State for pagination.
class PaginationState<T> {
/// Creates a new [PaginationState] with the given values.
PaginationState({
const PaginationState({
this.items = const [],
this.currentPage = 1,
this.lastPage = 1,
Expand Down
26 changes: 14 additions & 12 deletions lib/ui/native_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,14 +17,14 @@ import 'package:flutter/material.dart';
/// ],
/// );
/// ```
void showNativeDialog(
Future<T?> showNativeDialog<T>(
BuildContext context, {
required String title,
required List<DialogAction> actions,
required List<DialogAction<T>> actions,
required String content,
}) {
if (defaultTargetPlatform == TargetPlatform.iOS) {
showCupertinoDialog<void>(
return showCupertinoDialog<T>(
context: context,
builder:
(dialogContext) => CupertinoAlertDialog(
Expand All @@ -32,9 +34,9 @@ void showNativeDialog(
actions
.map(
(action) => CupertinoDialogAction(
onPressed: () {
action.onTap();
Navigator.of(dialogContext).pop();
onPressed: () async {
final result = await action.onTap();
if (dialogContext.mounted) Navigator.of(dialogContext).pop(result);
},
isDestructiveAction: action.isDestructiveAction,
child: Text(action.text),
Expand All @@ -44,7 +46,7 @@ void showNativeDialog(
),
);
} else {
showDialog<void>(
return showDialog<T?>(
context: context,
builder:
(dialogContext) => AlertDialog(
Expand All @@ -54,9 +56,9 @@ void showNativeDialog(
actions
.map(
(action) => TextButton(
onPressed: () {
action.onTap();
Navigator.of(dialogContext).pop();
onPressed: () async {
final result = await action.onTap();
if (dialogContext.mounted) Navigator.of(dialogContext).pop(result);
},
child: Text(action.text),
),
Expand All @@ -68,15 +70,15 @@ void showNativeDialog(
}

/// A dialog action which is used to show the actions of a native dialog. Tapping a action will also close the dialog.
class DialogAction {
class DialogAction<T> {
/// Creates a [DialogAction].
const DialogAction({required this.text, required this.onTap, this.isDestructiveAction = false});

/// The text of the action.
final String text;

/// The callback that is called when the action is tapped.
final VoidCallback onTap;
final FutureOr<T?> Function() onTap;

/// Whether the action is a destructive action. This is only used on iOS.
final bool isDestructiveAction;
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: dcc_toolkit
description: "Internal toolkit package used by the DCC team."
version: 0.0.14
version: 0.0.15
homepage: https://dutchcodingcompany.com
repository: https://github.com/DutchCodingCompany/dcc_toolkit

Expand Down
8 changes: 4 additions & 4 deletions test/pagination/pagination_mixin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
});

test('loadNextPage emits new state with next page items when current page is less than last page', () async {
final paginationState = PaginationState<int>(items: [1, 2, 3], currentPage: 1, lastPage: 3);
const paginationState = PaginationState<int>(items: [1, 2, 3], currentPage: 1, lastPage: 3);
cubit.emit(_TestState(paginationState));

final nextPaginationStates = <PaginationState<int>?>[];
Expand All @@ -47,7 +47,7 @@ void main() {
});

test('loadNextPage does not emit new state when current page is equal to last page', () async {
final paginationState = PaginationState<int>(items: [1, 2, 3], currentPage: 3, lastPage: 3);
const paginationState = PaginationState<int>(items: [1, 2, 3], currentPage: 3, lastPage: 3);
cubit.emit(_TestState(paginationState));

final nextPaginationStates = <PaginationState<int>?>[];
Expand All @@ -57,7 +57,7 @@ void main() {
});

test('loadNextPage does not emit new state when next page items are empty', () async {
final paginationState = PaginationState<int>(items: [1, 2, 3], currentPage: 1, lastPage: 3);
const paginationState = PaginationState<int>(items: [1, 2, 3], currentPage: 1, lastPage: 3);
cubit
..emit(_TestState(paginationState))
..returnPages = [];
Expand Down Expand Up @@ -88,7 +88,7 @@ class _TestState implements PaginationInterface<int> {
}

class _TestCubit extends Cubit<_TestState> with PaginationMixin<int, _TestState> {
_TestCubit() : super(_TestState(PaginationState()));
_TestCubit() : super(_TestState(const PaginationState()));

List<int> returnPages = [1, 2, 3];

Expand Down