lemon_watch 1.1.2 copy "lemon_watch: ^1.1.2" to clipboard
lemon_watch: ^1.1.2 copied to clipboard

Simplifies streams and observers

Getting Started #

Lemon watch is state management solution. The example below is an implementation of the default flutter counter app using lemon watch.

Example #

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:lemon_watch/src.dart';

// add lemon_watch: ^1.1.0 dependency to pubspec.yaml

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

class MyApp extends StatelessWidget {
  final count = Watch(0, clamp: (int value) => min(value, 10));

  MyApp({super.key}) {
    count.onChanged(onCountChanged);
  }

  void onCountChanged(int value){
     print("onCountChanged($value)");
  }

  @override
  Widget build(BuildContext context) => MaterialApp(
      title: 'Lemon Watch Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Lemon Watch Demo'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:'
              ),
              WatchBuilder(count, (countValue) => Text(
                '$countValue',
                style: Theme.of(context).textTheme.headlineMedium,
              )),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => count.value++,
          tooltip: 'Increment',
          child: const Icon(Icons.add),
        ), // This trailing comma makes auto-formatting nicer for build methods.
      ),
    );
}
0
likes
100
pub points
48%
popularity

Publisher

unverified uploader

Simplifies streams and observers

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on lemon_watch