-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.dart
77 lines (66 loc) · 1.66 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'dart:math';
import 'package:katana_listenables/katana_listenables.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();
},
)
],
),
);
}
}