31 lines
826 B
Dart
31 lines
826 B
Dart
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
|
// 初始化通知
|
|
Future<void> _initNotify() async {
|
|
final notify = FlutterLocalNotificationsPlugin();
|
|
await notify.initialize(
|
|
const InitializationSettings(
|
|
windows: WindowsInitializationSettings(
|
|
appName: 'TaskHub',
|
|
appUserModelId: 'com.cxx.task',
|
|
guid: 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
|
|
iconPath: 'assets/icons/task.png'
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 发送通知
|
|
Future<void> _showNotify(String title, String text) async {
|
|
final notify = FlutterLocalNotificationsPlugin();
|
|
final id = DateTime.now().millisecondsSinceEpoch.remainder(10000);
|
|
|
|
await notify.show(
|
|
id,
|
|
title,
|
|
text,
|
|
const NotificationDetails(
|
|
windows: WindowsNotificationDetails(),
|
|
),
|
|
);
|
|
} |