witt 0.6.0 copy "witt: ^0.6.0" to clipboard
witt: ^0.6.0 copied to clipboard

Simple state management powered by ValueNotifier with service locator.

example/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Example App",
      home: WServiceBuilder(
        serviceBuilder: (context) {
          WService.addSingleton(() => CounterController());
        },
        child: const HomePage(),
      ),
    );
  }
}

class CounterController {
  final counter = ValueNotifier(0);

  void incrementCounter() {
    counter.value++;
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // Get CounterController instance from service locator.
    final counterC = WService.get<CounterController>();
    return Scaffold(
      appBar: AppBar(title: const Text("Counter App")),
      body: Center(
        // Listen to ValueNotifier.
        child: WListener(
          notifier: counterC.counter,
          builder: (context) => Text(counterC.counter.value.toString()),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        // Increment the counter.
        onPressed: counterC.incrementCounter,
        child: const Icon(Icons.add),
      ),
    );
  }
}
1
likes
0
pub points
37%
popularity

Publisher

unverified uploader

Simple state management powered by ValueNotifier with service locator.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

collection, flutter

More

Packages that depend on witt