Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Bloc to v9.0.0 #86

Merged
merged 3 commits into from
Jan 22, 2025
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
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ analyzer:
body_might_complete_normally_nullable: ignore
depend_on_referenced_packages: ignore
no_leading_underscores_for_library_prefixes: ignore
use_build_context_synchronously: ignore
tomkad99 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void main() async {
// }

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

final appName = "Hooked Bloc";

Expand Down
4 changes: 2 additions & 2 deletions example/lib/page/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import 'use_bloc_page.dart';

class HomePage extends StatelessWidget {
const HomePage({
Key? key,
super.key,
required this.title,
}) : super(key: key);
});

final String title;

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/real_life_hook_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '../widget/clickable_item_list.dart';
import '../widget/item_detail.dart';

class RealLifeHookPage extends HookWidget {
const RealLifeHookPage({Key? key}) : super(key: key);
const RealLifeHookPage({super.key});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/real_life_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../widget/clickable_item_list.dart';
import '../widget/item_detail.dart';

class RealLifePage extends StatelessWidget {
const RealLifePage({Key? key}) : super(key: key);
const RealLifePage({super.key});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/use_action_listener_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../widget/message_bottom_sheet_content.dart';

// The page must inherit from HookWidget
class UseActionListenerPage extends HookWidget {
UseActionListenerPage({Key? key}) : super(key: key);
UseActionListenerPage({super.key});

final MessageActionCubit cubit = MessageActionCubit();

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/use_bloc_builder_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';

// The page must inherit from HookWidget
class UseBlocBuilderPage extends HookWidget {
UseBlocBuilderPage({Key? key}) : super(key: key);
UseBlocBuilderPage({super.key});

final CounterCubit cubit = CounterCubit("My cubit");

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/use_bloc_comparative_builder_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooked_bloc/hooked_bloc.dart';

class UseBlocComparativeBuilderPage extends HookWidget {
UseBlocComparativeBuilderPage({Key? key}) : super(key: key);
UseBlocComparativeBuilderPage({super.key});

final CounterCubit cubit = CounterCubit("My cubit");

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/use_bloc_comparative_listener_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:hooked_bloc/hooked_bloc.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class UseBlocComparativeListenerPage extends HookWidget {
UseBlocComparativeListenerPage({Key? key}) : super(key: key);
UseBlocComparativeListenerPage({super.key});

final EventCubit cubit = EventCubit();

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/use_bloc_listener_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:hooked_bloc/hooked_bloc.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class UseBlocListenerPage extends HookWidget {
UseBlocListenerPage({Key? key}) : super(key: key);
UseBlocListenerPage({super.key});

final EventCubit cubit = EventCubit();

Expand Down
2 changes: 1 addition & 1 deletion example/lib/page/use_bloc_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:hooked_bloc/hooked_bloc.dart';

// The page must inherit from HookWidget
class UseBlocPage extends HookWidget {
const UseBlocPage({Key? key}) : super(key: key);
const UseBlocPage({super.key});

@override
Widget build(BuildContext context) {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/widget/clickable_item_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'package:flutter/material.dart';

class ClickableItemList extends StatelessWidget {
const ClickableItemList({
Key? key,
super.key,
required this.itemCallback,
required this.data,
}) : super(key: key);
});

final Function(int) itemCallback;
final List<String> data;
Expand Down
4 changes: 2 additions & 2 deletions example/lib/widget/fab_actions_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'package:flutter/material.dart';

class FabActionsScaffold extends StatelessWidget {
const FabActionsScaffold({
Key? key,
super.key,
required this.title,
required this.count,
required this.incrementCallback,
required this.messageCallback,
}) : super(key: key);
});

final String title;
final int count;
Expand Down
4 changes: 2 additions & 2 deletions example/lib/widget/item_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'package:flutter/material.dart';

class ItemDetail extends StatelessWidget {
const ItemDetail({
Key? key,
super.key,
required this.index,
required this.onClose,
}) : super(key: key);
});

final int index;
final Function() onClose;
Expand Down
2 changes: 1 addition & 1 deletion example/lib/widget/message_bottom_sheet_content.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

class MessageBottomSheetContent extends StatelessWidget {
const MessageBottomSheetContent({Key? key, this.message}) : super(key: key);
const MessageBottomSheetContent({super.key, this.message});

final String? message;

Expand Down
14 changes: 8 additions & 6 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ dependencies:
sdk: flutter
hooked_bloc:
path: '../'
get_it: 7.2.0
injectable: 2.2.0
get_it: ^8.0.3
injectable: ^2.5.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.4
cupertino_icons: ^1.0.8

flutter_bloc: any
flutter_hooks: any
dev_dependencies:
flutter_test:
sdk: flutter
Expand All @@ -46,9 +48,9 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^2.0.1
injectable_generator: 2.3.0
build_runner: ^2.1.11
flutter_lints: ^5.0.0
injectable_generator: ^2.7.0
build_runner: ^2.4.14
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
2 changes: 1 addition & 1 deletion lib/hooked_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library hooked_bloc;
library;

export 'src/bloc_hook.dart';
export 'src/bloc_factory.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/src/bloc_action_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ void useActionListener<ACTION>(
useEffect(
() {
final subscription = actionMixin.actions.listen((action) {
if(actionWhen == null || actionWhen(actionMixin.previousAction, action)) {
if (actionWhen == null ||
actionWhen(actionMixin.previousAction, action)) {
onAction(action);
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bloc_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class BlocFactory<T extends BlocBase> {

typedef OnBlocCreated<F extends BlocFactory> = Function(F factory);

/// Creates BlocBase<T> class using provided factory.
/// Creates [BlocBase<T>] class using provided factory.
///
/// [useBlocFactory] will find [BlocFactory] class using injector provided by [BlocHookInjectionController] and then return [BlocBase] created by it.
/// If [BlocHookInjectionController] has no provided injectors, [useBlocFactory] will look into widget tree and try find [BlocFactory] using [Provider.of] method
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bloc_hook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooked_bloc/src/bloc_defaults.dart';
import 'package:hooked_bloc/src/config/hooked_bloc_config.dart';

/// Provides BlocBase<T> class.
/// Provides [BlocBase<T>] class.
///
/// [useBloc] will find and return [BlocBase] class using injector provided by [BlocHookInjectionController]
/// If [BlocHookInjectionController] has no provided injectors, [useBloc] will look into widget tree and try find BlocBase using [BlocProvider]
Expand Down
14 changes: 7 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_bloc: ^8.1.3
bloc: ^8.1.2
flutter_hooks: ^0.20.1
meta: ^1.10.0
provider: ^6.0.5
flutter_bloc: ^9.0.0
bloc: ^9.0.0
flutter_hooks: ^0.20.5
meta: ^1.15.0
provider: ^6.1.2

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.1
mocktail: ^1.0.2
flutter_lints: ^5.0.0
mocktail: ^1.0.4

flutter:
98 changes: 47 additions & 51 deletions test/bloc_action_listener_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,56 +90,52 @@ void main() {

testWidgets(
'when Cubit dispatch multiple times, actionWhen should be called only with 2 chars',
(tester) async {
int listenerCalls = 0;

Widget Function(BuildContext) builder(
ActionCubit<STATE, ACTION> cubit,
) {
return (context) {
useActionListener(
cubit,
(ACTION action) {
listenerCalls++;
},
actionWhen: (previousAction, action) => action.length == 2
);

return Container();
};
}

CounterActionCubit cubit = CounterActionCubit();

HookBuilder hookWidget = HookBuilder(builder: builder(cubit));

cubit.dispatchActionValue('1');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 0);

cubit.dispatchActionValue('11');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 1);

cubit.dispatchActionValue('2');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 1);

cubit.dispatchActionValue('22');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 2);

cubit.dispatchActionValue('333');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 2);

cubit.dispatchActionValue('4');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 2);

cubit.dispatchActionValue('55');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 3);
});
(tester) async {
int listenerCalls = 0;

Widget Function(BuildContext) builder(
ActionCubit<STATE, ACTION> cubit,
) {
return (context) {
useActionListener(cubit, (ACTION action) {
listenerCalls++;
}, actionWhen: (previousAction, action) => action.length == 2);

return Container();
};
}

CounterActionCubit cubit = CounterActionCubit();

HookBuilder hookWidget = HookBuilder(builder: builder(cubit));

cubit.dispatchActionValue('1');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 0);

cubit.dispatchActionValue('11');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 1);

cubit.dispatchActionValue('2');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 1);

cubit.dispatchActionValue('22');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 2);

cubit.dispatchActionValue('333');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 2);

cubit.dispatchActionValue('4');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 2);

cubit.dispatchActionValue('55');
await tester.pumpWidget(hookWidget);
expect(listenerCalls, 3);
});
});
}
Loading