flutter_cubit 0.1.1 icon indicating copy to clipboard operation
flutter_cubit: ^0.1.1 copied to clipboard

discontinued

A Flutter library built to expose widgets that integrate with cubits. Built to work with the cubit and bloc state management packages.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:cubit/cubit.dart';
import 'package:flutter_cubit/flutter_cubit.dart';

void main() => runApp(CubitCounter());

/// A [StatelessWidget] which uses:
/// * [cubit](https://pub.flutter-io.cn/packages/cubit)
/// * [flutter_cubit](https://pub.flutter-io.cn/packages/flutter_cubit)
/// to manage the state of a counter.
class CubitCounter extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: CubitProvider(
        create: (_) => CounterCubit(),
        child: CounterPage(),
      ),
    );
  }
}

/// A [StatelessWidget] which demonstrates
/// how to consume and interact with a [CounterCubit].
class CounterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Cubit Counter')),
      body: CubitBuilder<CounterCubit, int>(
        builder: (_, count) {
          return Center(
            child: Text('$count', style: Theme.of(context).textTheme.headline1),
          );
        },
      ),
      floatingActionButton: Column(
        crossAxisAlignment: CrossAxisAlignment.end,
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 4.0),
            child: FloatingActionButton(
              child: const Icon(Icons.add),
              onPressed: context.cubit<CounterCubit>().increment,
            ),
          ),
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 4.0),
            child: FloatingActionButton(
              child: const Icon(Icons.remove),
              onPressed: context.cubit<CounterCubit>().decrement,
            ),
          ),
        ],
      ),
    );
  }
}

/// {@template counter_cubit}
/// A simple [Cubit] which manages an `int` as its state
/// and exposes two public methods to [increment] and [decrement]
/// the value of the state.
/// {@endtemplate}
class CounterCubit extends Cubit<int> {
  /// {@macro counter_cubit}
  CounterCubit() : super(0);

  /// Increments the [Cubit] state by 1.
  void increment() => emit(state + 1);

  /// Decrements the [Cubit] state by 1.
  void decrement() => emit(state - 1);

  @override
  void onTransition(Transition<int> transition) {
    /// Log all state changes (transitions).
    print(transition);
    super.onTransition(transition);
  }
}
43
likes
0
pub points
82%
popularity

Publisher

verified publisher iconbloc-dev.com

A Flutter library built to expose widgets that integrate with cubits. Built to work with the cubit and bloc state management packages.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

Icon for licenses.unknown (LICENSE)

Dependencies

cubit, flutter, provider

More

Packages that depend on flutter_cubit