simple_state 1.0.0 copy "simple_state: ^1.0.0" to clipboard
simple_state: ^1.0.0 copied to clipboard

outdated

SimpleState is a library that makes it easy to connect your application's reactive data to the user interface.

example/main.dart

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

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

  @override
  State<StatefulWidget> createState() => _ExampleViewState();
}

class _ExampleViewState extends State<ExampleView> {
  final counter = ObservableList<int>([]);

  late final Reaction _whenReaction;

  Future<void> _asyncWhen() => Reaction.asyncWhen(
        listenables: [counter],
        condition: () => counter.length == 5,
        reaction: counter.clear,
      );

  @override
  void initState() {
    _whenReaction = Reaction.when(
      listenables: [counter],
      condition: () => counter.length == 2,
      reaction: _asyncWhen,
    );

    super.initState();
  }

  @override
  void dispose() {
    _whenReaction.removeListeners();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Observer(
          listenables: [counter],
          builder: (_) => Text(
            counter.toString(),
            style: const TextStyle(fontSize: 36, fontWeight: FontWeight.bold),
          ),
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      floatingActionButton: FloatingActionButton.extended(
        icon: const Icon(Icons.add),
        label: const Text('Increment'),
        onPressed: () => counter.add(counter.length + 1),
      ),
    );
  }
}
4
likes
0
pub points
0%
popularity

Publisher

verified publisherbroject.ru

SimpleState is a library that makes it easy to connect your application's reactive data to the user interface.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on simple_state