Skip to content

Commit cbc86d7

Browse files
committed
✨ Added test util and bool typedef
1 parent 398b6cd commit cbc86d7

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

lib/common/type_defs.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Single bool function is clear enough.
2+
// ignore_for_file: avoid_positional_boolean_parameters
3+
4+
/// Single bool function is clear enough.
5+
typedef SingleBoolFunc = void Function(bool);

lib/dcc_toolkit.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ export 'common/extensions/color.dart';
55
export 'common/extensions/iterable.dart';
66
export 'common/extensions/text_theme.dart';
77
export 'common/result/result.dart';
8+
export 'common/type_defs.dart';
89
export 'logger/bolt_logger.dart';
910
export 'style/style.dart';
11+
export 'test_util/devices_sizes.dart';
12+
export 'test_util/presentation_event_catcher.dart';

lib/test_util/devices_sizes.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:flutter/material.dart';
2+
3+
/// Device sizes for testing.
4+
class DeviceSizes {
5+
/// iPhone 11 screen size.
6+
static const BoxConstraints iphone11 = BoxConstraints(minWidth: 414, maxWidth: 414, minHeight: 896, maxHeight: 896);
7+
8+
/// Create a square [BoxConstraints] with the given [size].
9+
static BoxConstraints square(double size) =>
10+
BoxConstraints(minWidth: size, maxWidth: size, minHeight: size, maxHeight: size);
11+
12+
/// Create [BoxConstraints] from the given [size].
13+
static BoxConstraints fromSize(Size size) =>
14+
BoxConstraints(minWidth: size.width, maxWidth: size.width, minHeight: size.height, maxHeight: size.height);
15+
}
16+
17+
/// Extension for [BoxConstraints] to copy the size.
18+
extension BoxConstraintsX on BoxConstraints {
19+
/// Copy the size of the [BoxConstraints] with the given [width] and [height].
20+
BoxConstraints copySize({double? width, double? height}) =>
21+
copyWith(minWidth: width, maxWidth: width, minHeight: height, maxHeight: height);
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:bloc_presentation/bloc_presentation.dart';
2+
3+
/// Catch events from a [BlocPresentationMixin] and add them to a list.
4+
C catchEventIn<C extends BlocPresentationMixin<S, E>, S, E>(C cubit, List<E> events) {
5+
cubit.presentation.listen(events.add);
6+
7+
return cubit;
8+
}

0 commit comments

Comments
 (0)