hooked_bloc 1.5.0 copy "hooked_bloc: ^1.5.0" to clipboard
hooked_bloc: ^1.5.0 copied to clipboard

Flutter package that simplifies injection and usage of Bloc/Cubit.

example/lib/main.dart

import 'package:example/di/injector.dart';
import 'package:example/page/home_page.dart';
import 'package:flutter/material.dart';
import 'package:hooked_bloc/hooked_bloc.dart';

void main() async {
  // With GetIt or Injectable
  await configureDependencies();

  runApp(
    HookedBlocConfigProvider(
      injector: () => getIt.get,
      builderCondition: (state) => state != null, // Global build condition
      listenerCondition: (state) => state != null, // Global listen condition
      child: const MyApp(),
    ),
  );
}

// Quickstart example counter page
// Remember to inherit from HookWidget
// class MyApp extends HookWidget {
//   const MyApp({Key? key}) : super(key: key);
//
//   @override
//   Widget build(BuildContext context) {
//     // At start obtain a cubit instance
//     final cubit = useBloc<CounterCubit>();
//     // Then observe state's updates
//     //`buildWhen` param will override builderCondition locally
//     final state = useBlocBuilder(cubit, buildWhen: (state) => state <= 10);
//     // Create a listener for the side-effect
//     useBlocListener(cubit, (cubit, value, context) {
//       print("Button clicked");
//     });
//
//     // Build widget's tree without BlocProvider
//     return MaterialApp(
//       home: Scaffold(
//         floatingActionButton: FloatingActionButton(
//           onPressed: () => cubit.increment(), // Access cubit in tree
//           child: const Icon(Icons.add),
//         ),
//         // Consume state without BlocBuilder
//         body: Center(child: Text("The button has been pressed $state times")),
//       ),
//     );
//   }
// }

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

  final appName = "Hooked Bloc";

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: appName,
      theme: ThemeData(primarySwatch: Colors.blue),
      home: HomePage(title: appName),
    );
  }
}
80
likes
130
pub points
87%
popularity

Publisher

verified publisheriteo.com

Flutter package that simplifies injection and usage of Bloc/Cubit.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (LICENSE)

Dependencies

bloc, flutter, flutter_bloc, flutter_hooks, meta, provider

More

Packages that depend on hooked_bloc