with_value 0.0.4 copy "with_value: ^0.0.4" to clipboard
with_value: ^0.0.4 copied to clipboard

Simple InheritedWidget Wrapper.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return WithValue<String>(
      value: 'Hello, World!',
      child: MaterialApp(
        title: 'WithValue Example',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return WithValueUpdate(
      notifier: Incrementer(),
      child: Builder(builder: (context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('WithValue Example'),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  WithValue.of<String>(context),
                ),
                Text(
                  WithValueUpdate.of<Incrementer>(context).value.toString(),
                ),
                const SizedBox(height: 16),
                ElevatedButton(
                  onPressed: () {
                    WithValueUpdate.of<Incrementer>(context).increment();
                  },
                  child: const Text('Increment'),
                ),
                const SizedBox(height: 16),
                ElevatedButton(
                  onPressed: () {
                    WithValueUpdate.of<Incrementer>(context).decrement();
                  },
                  child: const Text('Increment Async'),
                ),
              ],
            ),
          ),
        );
      }),
    );
  }
}

class Incrementer with ChangeNotifier {
  int _value = 0;
  int get value => _value;

  void increment() {
    _value++;
    notifyListeners();
  }

  void decrement() {
    _value--;
    notifyListeners();
  }
}
1
likes
150
points
36
downloads

Publisher

unverified uploader

Weekly Downloads

Simple InheritedWidget Wrapper.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, flutter

More

Packages that depend on with_value