tasteful 0.0.1 copy "tasteful: ^0.0.1" to clipboard
tasteful: ^0.0.1 copied to clipboard

a different take on stateful widgets.

package:tasteful #

This Flutter package provides a new kind of stateful widget, TastefulWidget. It solves a subset of problems that the StatefulWidget a little more elegantly:

  • TastefulWidget does not require a second State class. Instead it can operate on an already existing class that can represent your widget's state.
  • Unlike State your state class can (and generally should) be immutable.

Example #

The following example implements the classic counter widget. It uses data provided with the widget (greeting) as well as state (counter represented by int) to build a UI.

class Counter extends TastefulWidget<int> {
  Counter(this.greeting);

  final String greeting;

  int createInitialState() => 0;

  @override
  Widget build(TastefulBuildContext context) {
    return Column(children: [
      Text('$greeting, ${context.state}!'),
      GestureDetector(
        onTap: () {
          context.state = context.state + 1;
        },
        child: Text('Increment'),
      ),
    ]);
  }
}

When to use TastefulWidget #

  • When you prefer your state objects to be immutable and that's sufficient to express you app's UI logic.
  • When a class already exists that fully represents your widget's state, and creating a second wrapper class would be wasteful.

TastefulWidget is not a StatefulWidget replacement #

StatefulWidget supports more complex scenarios via a richer lifecycle API, such as didChangeDependencies, didUpdateWidget, and dispose.

0
likes
15
pub points
0%
popularity

Publisher

unverified uploader

a different take on stateful widgets.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on tasteful