Flutter桌面软件开发中实现本地通知

Flutter桌面软件开发中实现本地通知可以使用local_notifier ,local_notifier这个插件允许 Flutter 桌面 应用显示本地通知。

381633085.bmp

Flutter桌面软件开发中实现本地通知 第一步安装依赖

dependencies:
  local_notifier: ^0.1.5

Flutter桌面软件开发中实现本地通知 第二步配置插件

1、main方法配置

void main() async{
  runApp(const MyApp());
  //配置异步通知
  await localNotifier.setup(
    appName: 'IT营',
    // 参数 shortcutPolicy 仅适用于 Windows
    shortcutPolicy: ShortcutPolicy.requireCreate,
  );
}

2、用到的地方弹窗

LocalNotification notification = LocalNotification(
                    title: "local_notifier_example",
                    body: "hello flutter!",
);
Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ElevatedButton(
                onPressed: () {
                  //通知完结

                  LocalNotification notification = LocalNotification(
                    title: "local_notifier_example",
                    body: "hello flutter!",
                  );

                  notification.onShow = () {
                    print('onShow ${notification.identifier}');
                  };
                  notification.onClose = (closeReason) {
                    // 只支持在windows,其他平台 closeReason 始终为 unknown。
                    switch (closeReason) {
                      case LocalNotificationCloseReason.userCanceled:
                        // do something
                        break;
                      case LocalNotificationCloseReason.timedOut:
                        // do something
                        break;
                      default:
                    }
                    print('onClose  - $closeReason');
                  };
                  notification.onClick = () {
                    print('onClick ${notification.identifier}');
                  };
                  notification?.onClickAction = (actionIndex) {
                    print(
                        'onClickAction ${notification?.identifier} - $actionIndex');
                  };
                  notification.show();
                },
                child: Text("显示notification"))
          ],
        ),
      ),
    );
  }

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-09 07:28:08       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-09 07:28:08       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-09 07:28:08       82 阅读
  4. Python语言-面向对象

    2024-01-09 07:28:08       91 阅读

热门阅读

  1. 实验五:动态路由配置

    2024-01-09 07:28:08       52 阅读
  2. 实验四:静态路由配置

    2024-01-09 07:28:08       52 阅读
  3. 传统图像处理学习笔记更新中

    2024-01-09 07:28:08       55 阅读
  4. 正则表达式

    2024-01-09 07:28:08       53 阅读
  5. css——box-shadow阴影效果

    2024-01-09 07:28:08       53 阅读
  6. 开源软件运维安全防护的六个手段

    2024-01-09 07:28:08       60 阅读
  7. redis原子命令和 lua 脚本解决并发问题

    2024-01-09 07:28:08       61 阅读
  8. qt day1

    qt day1

    2024-01-09 07:28:08      65 阅读
  9. 游戏辅助从0到1-C++调用游戏Lua脚本实现辅助

    2024-01-09 07:28:08       73 阅读
  10. spark读sqlserver出现的异常

    2024-01-09 07:28:08       65 阅读