Flutter 向用户推送通知
Flutter Push Notification to user
我正在开发一个订购产品的客户端应用程序,我想 push notification
为特定用户在他的订单被接受和交货到达他时,我是 flutter 的新手,我不知道如何开始.
实现它并获得良好性能的正确方法是什么,我不知道从哪里开始?
您应该尝试阅读此软件包的文档,也许这会对您有所帮助。
Local Push Notifications
它将您要发送给本地用户的通知存储在他们的 phone 上,并在计时器上或在您触发某些操作时发送。您必须在 main.dart
的主函数中初始化包。我已经用闹钟应用试过这个包,它工作正常。
非常感谢@GrandMagus的帮助,这就是我的问题的解决方案
class _MyAppState extends State<MyApp> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Timer timer;
@override
void initState() {
super.initState();
var initializationSettingsAndroid =
AndroidInitializationSettings('flutter_devs');
var initializationSettingsIOs = IOSInitializationSettings();
var initSetttings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOs);
flutterLocalNotificationsPlugin.initialize(initSetttings,
onSelectNotification: onSelectNotification);
timer=Timer.periodic(Duration(seconds: 15), (Timer t) => showNotification());
}
@override
void dispose() {
timer?.cancel();
super.dispose();
}
Future onSelectNotification(String payload) {
Navigator.of(context).push(MaterialPageRoute(builder: (_) {
return MyApp();
}));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
backgroundColor: Colors.red,
title: new Text('Flutter notification demo'),
),
);
}
我正在开发一个订购产品的客户端应用程序,我想 push notification
为特定用户在他的订单被接受和交货到达他时,我是 flutter 的新手,我不知道如何开始.
实现它并获得良好性能的正确方法是什么,我不知道从哪里开始?
您应该尝试阅读此软件包的文档,也许这会对您有所帮助。
Local Push Notifications
它将您要发送给本地用户的通知存储在他们的 phone 上,并在计时器上或在您触发某些操作时发送。您必须在 main.dart
的主函数中初始化包。我已经用闹钟应用试过这个包,它工作正常。
非常感谢@GrandMagus的帮助,这就是我的问题的解决方案
class _MyAppState extends State<MyApp> {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Timer timer;
@override
void initState() {
super.initState();
var initializationSettingsAndroid =
AndroidInitializationSettings('flutter_devs');
var initializationSettingsIOs = IOSInitializationSettings();
var initSetttings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOs);
flutterLocalNotificationsPlugin.initialize(initSetttings,
onSelectNotification: onSelectNotification);
timer=Timer.periodic(Duration(seconds: 15), (Timer t) => showNotification());
}
@override
void dispose() {
timer?.cancel();
super.dispose();
}
Future onSelectNotification(String payload) {
Navigator.of(context).push(MaterialPageRoute(builder: (_) {
return MyApp();
}));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
backgroundColor: Colors.red,
title: new Text('Flutter notification demo'),
),
);
}