diff --git a/examples/mirai_gallery/lib/app/home/bloc/home_event.dart b/examples/mirai_gallery/lib/app/home/bloc/home_event.dart deleted file mode 100644 index 2a561cb1..00000000 --- a/examples/mirai_gallery/lib/app/home/bloc/home_event.dart +++ /dev/null @@ -1,17 +0,0 @@ -part of 'home_bloc.dart'; - -@immutable -sealed class HomeEvent { - const HomeEvent(); -} - -// Event used to perform the initializations of the HomeBloc -class _Initialize extends HomeEvent { - const _Initialize(); -} - -class UserInputEvent extends HomeEvent { - final String keyword; - - const UserInputEvent({required this.keyword}); -} diff --git a/examples/mirai_gallery/lib/app/home/bloc/home_bloc.dart b/examples/mirai_gallery/lib/app/home/cubit/home_cubit.dart similarity index 75% rename from examples/mirai_gallery/lib/app/home/bloc/home_bloc.dart rename to examples/mirai_gallery/lib/app/home/cubit/home_cubit.dart index b988fe9f..3e901c2e 100644 --- a/examples/mirai_gallery/lib/app/home/bloc/home_bloc.dart +++ b/examples/mirai_gallery/lib/app/home/cubit/home_cubit.dart @@ -4,23 +4,20 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -part 'home_event.dart'; part 'home_state.dart'; -class HomeBloc extends Bloc { +class HomeBloc extends Cubit { HomeBloc() : super(const HomeLoading()) { - on<_Initialize>(_onInitializeEvent); - on(_onUserInputEvent); controller = TextEditingController() ..addListener(_textEditingControllerListener); - add(const _Initialize()); + _initialize(); } late final TextEditingController controller; final List> _allItems = []; - void _onInitializeEvent(_Initialize event, Emitter emit) async { + void _initialize() async { final items = await _loadAndParseJsonFromAsset(); if (items.isNotEmpty) { _allItems.addAll(items); @@ -28,11 +25,11 @@ class HomeBloc extends Bloc { emit(HomeLoaded(items: items)); } - void _onUserInputEvent(UserInputEvent event, Emitter emit) { - if (event.keyword.isNotEmpty) { + void _onUserInput({required String keyword}) { + if (keyword.isNotEmpty) { List> matchedItems = []; - final String keyword = event.keyword.toLowerCase(); + keyword = keyword.toLowerCase(); for (final Map item in _allItems) { var text = item["title"]?["data"]; if (text != null && text is String) { @@ -60,9 +57,9 @@ class HomeBloc extends Bloc { } } - // Add `UserInputEvent` with the latest keyword + // Listen to text editing controller for the latest keyword void _textEditingControllerListener() { - add(UserInputEvent(keyword: controller.text)); + _onUserInput(keyword: controller.text); } @override diff --git a/examples/mirai_gallery/lib/app/home/bloc/home_state.dart b/examples/mirai_gallery/lib/app/home/cubit/home_state.dart similarity index 91% rename from examples/mirai_gallery/lib/app/home/bloc/home_state.dart rename to examples/mirai_gallery/lib/app/home/cubit/home_state.dart index 9b4b4978..a0cfc1e0 100644 --- a/examples/mirai_gallery/lib/app/home/bloc/home_state.dart +++ b/examples/mirai_gallery/lib/app/home/cubit/home_state.dart @@ -1,4 +1,4 @@ -part of 'home_bloc.dart'; +part of 'home_cubit.dart'; @immutable sealed class HomeState { diff --git a/examples/mirai_gallery/lib/app/home/home_screen.dart b/examples/mirai_gallery/lib/app/home/home_screen.dart index 1f1e5e7a..98bd3396 100644 --- a/examples/mirai_gallery/lib/app/home/home_screen.dart +++ b/examples/mirai_gallery/lib/app/home/home_screen.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:mirai/mirai.dart'; -import 'bloc/home_bloc.dart'; +import 'cubit/home_cubit.dart'; class HomeScreen extends StatelessWidget { const HomeScreen({super.key});