katana_listenables 2.2.5 copy "katana_listenables: ^2.2.5" to clipboard
katana_listenables: ^2.2.5 copied to clipboard

The base part of the package that allows Listenable values to be grouped together and treated as a ChangeNotifier.

example/lib/main.dart

// Dart imports:
import 'dart:math';

// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:katana_listenables/katana_listenables.dart';

part 'main.listenable.dart';

@listenables
class ListenableValue with _$ListenableValue, ChangeNotifier {
  factory ListenableValue({
    required TextEditingController controller,
    ValueNotifier<String> value,
  }) = _ListenableValue;
  ListenableValue._();

  void get() {}
}

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: const ListenablePage(),
      title: "Flutter Demo",
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
    );
  }
}

class ListenablePage extends StatefulWidget {
  const ListenablePage({super.key});

  @override
  State<StatefulWidget> createState() => ListenablePageState();
}

class ListenablePageState extends State<ListenablePage> {
  final listenable = ListenableValue(
    controller: TextEditingController(text: "before click"),
    value: ValueNotifier("0"),
  );

  @override
  void initState() {
    super.initState();
    listenable.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Flutter Demo")),
      body: ListView(
        children: [
          ListTile(
            title: Text(listenable.controller.text),
            onTap: () {
              listenable.controller.text = "after click";
            },
          ),
          ListTile(
            title: Text(listenable.value?.value ?? ""),
            onTap: () {
              listenable.value?.value = Random().nextInt(100).toString();
            },
          )
        ],
      ),
    );
  }
}
1
likes
140
pub points
5%
popularity

Publisher

verified publishermathru.net

The base part of the package that allows Listenable values to be grouped together and treated as a ChangeNotifier.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, katana, katana_listenables_annotation

More

Packages that depend on katana_listenables