@@ -18,8 +18,8 @@ class MyApp extends StatefulWidget {
18
18
19
19
class _MyAppState extends State <MyApp > {
20
20
StreamSubscription <NotificationEvent >? _subscription;
21
- final List <NotificationEvent > _log = [];
22
- bool started = false ;
21
+ final List <NotificationEvent > _notificationLogs = [];
22
+ bool isListening = false ;
23
23
24
24
Reflex reflex = Reflex (
25
25
debug: true ,
@@ -42,7 +42,7 @@ class _MyAppState extends State<MyApp> {
42
42
43
43
void onData (NotificationEvent event) {
44
44
setState (() {
45
- _log .add (event);
45
+ _notificationLogs .add (event);
46
46
});
47
47
debugPrint (event.toString ());
48
48
}
@@ -51,7 +51,7 @@ class _MyAppState extends State<MyApp> {
51
51
try {
52
52
_subscription = reflex.notificationStream! .listen (onData);
53
53
setState (() {
54
- started = true ;
54
+ isListening = true ;
55
55
});
56
56
} on ReflexException catch (exception) {
57
57
debugPrint (exception.toString ());
@@ -60,7 +60,7 @@ class _MyAppState extends State<MyApp> {
60
60
61
61
void stopListening () {
62
62
_subscription? .cancel ();
63
- setState (() => started = false );
63
+ setState (() => isListening = false );
64
64
}
65
65
66
66
@override
@@ -70,26 +70,80 @@ class _MyAppState extends State<MyApp> {
70
70
appBar: AppBar (
71
71
title: const Text ('Reflex Example app' ),
72
72
),
73
- body: Center (
74
- child: ListView .builder (
75
- itemCount: _log.length,
76
- itemBuilder: (BuildContext context, int idx) {
77
- final entry = _log[idx];
78
- return ListTile (
79
- title: Text (entry.title ?? "" ),
80
- subtitle: Text (entry.message ?? "" ),
81
- trailing: Text (entry.packageName.toString ().split ('.' ).last),
82
- );
83
- },
84
- ),
85
- ),
86
- floatingActionButton: FloatingActionButton (
87
- onPressed: started ? stopListening : startListening,
88
- tooltip: 'Start/Stop listening' ,
89
- child:
90
- started ? const Icon (Icons .stop) : const Icon (Icons .play_arrow),
73
+ body: Column (
74
+ mainAxisAlignment: MainAxisAlignment .start,
75
+ children: [
76
+ notificationListener (),
77
+ autoReply (),
78
+ ],
91
79
),
92
80
),
93
81
);
94
82
}
83
+
84
+ Widget notificationListener () {
85
+ return SizedBox (
86
+ height: 400 ,
87
+ child: Column (
88
+ children: [
89
+ SizedBox (
90
+ height: 300 ,
91
+ child: ListView .builder (
92
+ itemCount: _notificationLogs.length,
93
+ itemBuilder: (BuildContext context, int index) {
94
+ final NotificationEvent element = _notificationLogs[index];
95
+ return ListTile (
96
+ title: Text (element.title ?? "" ),
97
+ subtitle: Text (element.message ?? "" ),
98
+ trailing: Text (
99
+ element.packageName.toString ().split ('.' ).last,
100
+ ),
101
+ );
102
+ },
103
+ ),
104
+ ),
105
+ Row (
106
+ mainAxisAlignment: MainAxisAlignment .spaceEvenly,
107
+ children: [
108
+ ElevatedButton .icon (
109
+ icon: isListening
110
+ ? const Icon (Icons .stop)
111
+ : const Icon (Icons .play_arrow),
112
+ label: const Text ("Reflex Notification Listener" ),
113
+ onPressed: () {
114
+ if (isListening) {
115
+ stopListening ();
116
+ } else {
117
+ startListening ();
118
+ }
119
+ },
120
+ ),
121
+ if (_notificationLogs.isNotEmpty)
122
+ ElevatedButton .icon (
123
+ style: ElevatedButton .styleFrom (
124
+ primary: Colors .red,
125
+ ),
126
+ icon: const Icon (Icons .clear),
127
+ label: const Text (
128
+ "Clear List" ,
129
+ style: TextStyle (
130
+ color: Colors .white,
131
+ ),
132
+ ),
133
+ onPressed: () {
134
+ setState (() {
135
+ _notificationLogs.clear ();
136
+ });
137
+ },
138
+ ),
139
+ ],
140
+ ),
141
+ ],
142
+ ),
143
+ );
144
+ }
145
+
146
+ Widget autoReply () {
147
+ return const Text ("AutoReply" );
148
+ }
95
149
}
0 commit comments