flutter内置 图标网:
https://www.fluttericon.cn
极光推送 支持 Flutter3.0 的.
官网文档 https://github.com/jpush/jpush-flutter-plugin
- 添加插件:
$ flutter pub add jpush_flutter
- 配置 android\app\build.gradle
android: {
....
defaultConfig {
applicationId "替换成自己应用 ID"
...
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a',
}
manifestPlaceholders += [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
}
- 代码初始化
final JPush jpush = JPush();
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
String? platformVersion;
try {
jpush.addEventHandler(
onReceiveNotification: (Map<String, dynamic> message) async {
print("================");
print(message["title"]);
print(message["alert"]);
print(message["extras"]["cn.jpush.android.EXTRA"]);
print("================");
},
onOpenNotification: (Map<String, dynamic> message) async {
String? key = message["extras"]["cn.jpush.android.EXTRA"];
print(message["title"]);
print(message["alert"]);
print(message["extras"]["cn.jpush.android.EXTRA"]);
if (key!.isNotEmpty) {
Navigator.push(context,
MaterialPageRoute(builder: (context) => const HomePage()));
}
},
);
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
jpush.setup(
appKey: "xxxx",
channel: "theChannel",
production: false,
debug: true,
);
jpush.applyPushAuthority(
const NotificationSettingsIOS(sound: true, alert: true, badge: true));