@@ -67,6 +67,18 @@ class MyTaskHandler extends TaskHandler {
6767 void onNotificationButtonPressed (String id) {
6868 print ('onNotificationButtonPressed: $id ' );
6969 }
70+
71+ // Called when the notification itself is pressed.
72+ @override
73+ void onNotificationPressed () {
74+ print ('onNotificationPressed' );
75+ }
76+
77+ // Called when the notification itself is dismissed.
78+ @override
79+ void onNotificationDismissed () {
80+ print ('onNotificationDismissed' );
81+ }
7082}
7183
7284class ExampleApp extends StatelessWidget {
@@ -77,6 +89,7 @@ class ExampleApp extends StatelessWidget {
7789 return MaterialApp (
7890 routes: {
7991 '/' : (context) => const ExamplePage (),
92+ '/second' : (context) => const SecondPage (),
8093 },
8194 initialRoute: '/' ,
8295 );
@@ -162,6 +175,7 @@ class _ExamplePageState extends State<ExamplePage> {
162175 notificationButtons: [
163176 const NotificationButton (id: 'btn_hello' , text: 'hello' ),
164177 ],
178+ notificationInitialRoute: '/second' ,
165179 callback: startCallback,
166180 );
167181 }
@@ -210,31 +224,23 @@ class _ExamplePageState extends State<ExamplePage> {
210224 // This widget must be declared above the [Scaffold] widget.
211225 return WithForegroundTask (
212226 child: Scaffold (
213- appBar: _buildAppBar (),
214- body: _buildContent (),
215- ),
216- );
217- }
218-
219- AppBar _buildAppBar () {
220- return AppBar (
221- title: const Text ('Flutter Foreground Task' ),
222- centerTitle: true ,
223- );
224- }
225-
226- Widget _buildContent () {
227- return SafeArea (
228- child: Column (
229- children: [
230- Expanded (child: _buildCommunicationText ()),
231- _buildServiceControlButtons (),
232- ],
227+ appBar: AppBar (
228+ title: const Text ('Flutter Foreground Task' ),
229+ centerTitle: true ,
230+ ),
231+ body: SafeArea (
232+ child: Column (
233+ children: [
234+ Expanded (child: _buildCommunicationDataText ()),
235+ _buildServiceControlButtons (),
236+ ],
237+ ),
238+ ),
233239 ),
234240 );
235241 }
236242
237- Widget _buildCommunicationText () {
243+ Widget _buildCommunicationDataText () {
238244 return ValueListenableBuilder (
239245 valueListenable: _taskDataListenable,
240246 builder: (context, data, _) {
@@ -272,3 +278,23 @@ class _ExamplePageState extends State<ExamplePage> {
272278 );
273279 }
274280}
281+
282+ class SecondPage extends StatelessWidget {
283+ const SecondPage ({super .key});
284+
285+ @override
286+ Widget build (BuildContext context) {
287+ return Scaffold (
288+ appBar: AppBar (
289+ title: const Text ('Second Page' ),
290+ centerTitle: true ,
291+ ),
292+ body: Center (
293+ child: ElevatedButton (
294+ onPressed: Navigator .of (context).pop,
295+ child: const Text ('pop this page' ),
296+ ),
297+ ),
298+ );
299+ }
300+ }
0 commit comments