Skip to content

Commit

Permalink
Normalize keys parameter (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
n-bernat authored Dec 11, 2024
1 parent ab89c73 commit dc85e1e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/leancode_hooks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- **Breaking**: Replace all `keys` that were declared as [optional positional parameter](https://dart.dev/language/functions#optional-positional-parameters) with a [named parameter](https://dart.dev/language/functions#named-parameters) that defaults to `const List<Object?>[]`. Affected hooks: `useBloc`, `usePostFrameEffect`, `useTapGestureRecognizer`.
- Bump `leancode_lint` dev dependency to `12.0.0`.
- Bump `custom_lint` dev dependency to `0.6.4`.

Expand Down
4 changes: 2 additions & 2 deletions packages/leancode_hooks/lib/src/use_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:flutter_hooks/flutter_hooks.dart';
/// Provides a [Cubit] or a [Bloc] that is automatically disposed without having
/// to use BlocProvider.
B useBloc<B extends BlocBase<Object?>>(
B Function() create, [
B Function() create, {
List<Object?> keys = const [],
]) {
}) {
final bloc = useMemoized(create, keys);

useEffect(() => bloc.close, [bloc]);
Expand Down
7 changes: 5 additions & 2 deletions packages/leancode_hooks/lib/src/use_post_frame_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

/// Registers [effect] to be run in
/// WidgetsBinding.instance.addPostFrameCallback.
void usePostFrameEffect(VoidCallback effect, [List<Object?>? keys]) {
/// [WidgetsBinding.instance.addPostFrameCallback].
void usePostFrameEffect(
VoidCallback effect, {
List<Object?> keys = const [],
}) {
useEffect(
() {
WidgetsBinding.instance.addPostFrameCallback((_) => effect());
Expand Down
2 changes: 1 addition & 1 deletion packages/leancode_hooks/lib/src/use_stream_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void useStreamListener<T>(
Stream<T> stream,
ValueChanged<T> onData, {
Function? onError,
void Function()? onDone,
VoidCallback? onDone,
bool? cancelOnError,
List<Object?> keys = const [],
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export 'package:flutter/gestures.dart' show TapGestureRecognizer;

/// Creates a [TapGestureRecognizer] that will be disposed automatically.
TapGestureRecognizer useTapGestureRecognizer(
TapGestureRecognizer Function() builder, [
TapGestureRecognizer Function() builder, {
List<Object?> keys = const [],
]) {
}) {
final tapGestureRecognizer = useMemoized(builder, keys);

useEffect(() => tapGestureRecognizer.dispose, [tapGestureRecognizer]);
Expand Down
4 changes: 2 additions & 2 deletions packages/leancode_hooks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ description: >-
Hooks we often use, all gathered in one place.
environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.10.0 <4.0.0'
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.10.0 <4.0.0"

dependencies:
bloc: ^8.0.3
Expand Down

0 comments on commit dc85e1e

Please sign in to comment.