bloc_effects 0.2.1 copy "bloc_effects: ^0.2.1" to clipboard
bloc_effects: ^0.2.1 copied to clipboard

outdated

Cubit and Bloc abstractions and Flutter Widget that make it easy to add UI Effects to the BLoC state management.

example/lib/main.dart

import 'package:bloc_effects/bloc_effects.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

abstract class DemoEffect {}

class ShowBottomSheet implements DemoEffect {
  const ShowBottomSheet();
}

class DemoCubit extends CubitWithEffects<void, DemoEffect> {
  DemoCubit() : super(null);

  void onButtonPressed() => useEffect(const ShowBottomSheet());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late DemoCubit _demoCubit;

  @override
  void initState() {
    super.initState();
    _demoCubit = DemoCubit();
  }

  @override
  void dispose() {
    _demoCubit.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: BlocEffectListener<DemoCubit, DemoEffect, void>(
          effector: _demoCubit,
          listener: (context, effect, state) {
            if (effect is ShowBottomSheet) {
              showBottomSheet<void>(
                context: context,
                builder: (c) => Material(
                  child: Container(
                    color: Colors.black12,
                    height: 150,
                  ),
                ),
              );
            }
          },
          child: Center(
            child: ElevatedButton(
              onPressed: _demoCubit.onButtonPressed,
              child: const Icon(Icons.upload),
            ),
          ),
        ),
      ),
    );
  }
}
14
likes
0
pub points
79%
popularity

Publisher

verified publisherdarttech.dev

Cubit and Bloc abstractions and Flutter Widget that make it easy to add UI Effects to the BLoC state management.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_bloc

More

Packages that depend on bloc_effects