xxxxxxxxxx
import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
@override
void initState() {
super.initState();
_configureFirebaseMessaging();
}
void _configureFirebaseMessaging() {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('onMessage: $message');
// Handle the received notification while the app is in the foreground
},
onLaunch: (Map<String, dynamic> message) async {
print('onLaunch: $message');
// Handle the received notification when the app is completely closed
},
onResume: (Map<String, dynamic> message) async {
print('onResume: $message');
// Handle the received notification when the app is in the background
},
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Flutter Push Notifications'),
),
body: Center(
child: Text(
'Implement push notifications with AWS services in Flutter',
style: TextStyle(fontSize: 20),
),
),
),
);
}
}
void main() {
runApp(MyApp());
}
xxxxxxxxxx
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="When Coin"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_stat_ic_notification" />
xxxxxxxxxx
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>
</application>
</manifest>