bloc_riverpod 0.0.2 icon indicating copy to clipboard operation
bloc_riverpod: ^0.0.2 copied to clipboard

BlocProvider implementation with riverpod as alternative to provider.

BlocProvider - Bloc Riverpod #

It's similar to ChangeNotifierProvider but with bloc instead of ChangeNotifier.

import 'package:flutter/material.dart';
import 'package:bloc_riverpod/bloc_riverpod.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class CounterCubit extends Cubit<int> {
  CounterCubit(int state) : super(state);

  void increment() => emit(state + 1);
}

final counterProvider = BlocProvider((ref) => CounterCubit(0));

class HomePage extends ConsumerWidget {
  @override
  Widget build(BuildContext context, ScopedReader watch) {
    // Rebuilds the widget if the cubit/bloc's state changes.
    final counterCubit = watch(counterProvider);
    return Scaffold(
      body: Center(
        child: Text(
          '${counterCubit.state}',
          style: Theme.of(context).textTheme.headline4,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: counterCubit.increment,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
3
likes
130
pub points
35%
popularity

Publisher

unverified uploader

BlocProvider implementation with riverpod as alternative to provider.

Homepage

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

bloc, meta, riverpod

More

Packages that depend on bloc_riverpod