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

vessel for Flutter

example/vessel_flutter_example.dart

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

final provider = ValueNotifierProvider((read) => ValueNotifier(0));

void main() {
  return runApp(
    ProviderScope(
      child: provider.Builder(
        builder: (_, value, __) => Text("$value"),
      ),
    ),
  );
}

class ValueNotifierProvider<T> extends Provider<ValueNotifier<T>> {
  ValueNotifierProvider(
    ProviderCreate<ValueNotifier<T>> create, {
    String? debugName,
  }) : super(
          create,
          dispose: (vn) => vn.dispose(),
          debugName: debugName,
        );

  // ignore: non_constant_identifier_names
  Widget Builder({
    required ValueWidgetBuilder<T> builder,
    Widget? child,
  }) =>
      _ValueNotifierProviderBuilder(
        provider: this,
        builder: builder,
      );
}

class _ValueNotifierProviderBuilder<T> extends StatelessWidget {
  final ValueNotifierProvider<T> provider;
  final ValueWidgetBuilder<T> builder;
  final Widget? child;

  const _ValueNotifierProviderBuilder({
    super.key,
    required this.builder,
    required this.provider,
    this.child,
  });

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder(
      valueListenable: provider.of(context),
      builder: builder,
      child: child,
    );
  }
}
0
likes
140
pub points
0%
popularity

Publisher

unverified uploader

vessel for Flutter

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, flutter, meta, vessel

More

Packages that depend on vessel_flutter