Skip to content

Commit f3b66e4

Browse files
committed
Example UI Updated
1 parent aa40d76 commit f3b66e4

File tree

1 file changed

+77
-23
lines changed

1 file changed

+77
-23
lines changed

example/lib/main.dart

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class MyApp extends StatefulWidget {
1818

1919
class _MyAppState extends State<MyApp> {
2020
StreamSubscription<NotificationEvent>? _subscription;
21-
final List<NotificationEvent> _log = [];
22-
bool started = false;
21+
final List<NotificationEvent> _notificationLogs = [];
22+
bool isListening = false;
2323

2424
Reflex reflex = Reflex(
2525
debug: true,
@@ -42,7 +42,7 @@ class _MyAppState extends State<MyApp> {
4242

4343
void onData(NotificationEvent event) {
4444
setState(() {
45-
_log.add(event);
45+
_notificationLogs.add(event);
4646
});
4747
debugPrint(event.toString());
4848
}
@@ -51,7 +51,7 @@ class _MyAppState extends State<MyApp> {
5151
try {
5252
_subscription = reflex.notificationStream!.listen(onData);
5353
setState(() {
54-
started = true;
54+
isListening = true;
5555
});
5656
} on ReflexException catch (exception) {
5757
debugPrint(exception.toString());
@@ -60,7 +60,7 @@ class _MyAppState extends State<MyApp> {
6060

6161
void stopListening() {
6262
_subscription?.cancel();
63-
setState(() => started = false);
63+
setState(() => isListening = false);
6464
}
6565

6666
@override
@@ -70,26 +70,80 @@ class _MyAppState extends State<MyApp> {
7070
appBar: AppBar(
7171
title: const Text('Reflex Example app'),
7272
),
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+
],
9179
),
9280
),
9381
);
9482
}
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+
}
95149
}

0 commit comments

Comments
 (0)