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

outdated

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

example/lib/main.dart

import 'dart:math';

import 'package:katana_listenables_annotation/katana_listenables_annotation.dart';

import 'package:flutter/material.dart';

part 'main.listenable.dart';

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

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(
    name: TextEditingController(text: "before click"),
  );
  @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.name.text),
            onTap: () {
              listenable.name.text = "after click";
            },
          ),
          ListTile(
            title: Text(listenable.value?.value ?? ""),
            onTap: () {
              listenable.value?.value = Random().nextInt(100).toString();
            },
          )
        ],
      ),
    );
  }
}
1
likes
0
pub points
7%
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

License

unknown (license)

Dependencies

flutter, katana, katana_listenables_annotation

More

Packages that depend on katana_listenables