windows_notification 0.0.1 copy "windows_notification: ^0.0.1" to clipboard
windows_notification: ^0.0.1 copied to clipboard

outdated

flutter windows notification.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:windows_notification/notification_message.dart';
import 'package:windows_notification/windows_notification.dart';

void main() {
  runApp(MaterialApp(
    home: const MyApp(),
    color: Colors.red,
    themeMode: ThemeMode.light,
    theme: ThemeData(
        backgroundColor: Colors.red,
        primaryColor: Colors.red,
        primarySwatch: Colors.red),
  ));
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _winNotifyPlugin = WindowsNotification(applicationId: "ASGHAR ONLINE");

  @override
  void initState() {
    _winNotifyPlugin.initNotificationCallBack((data, s, d) {});
    super.initState();
  }

  sendWithPluginTemplate() {
    NotificationMessage message = NotificationMessage.fromPluginTemplate(
      "test1",
      "TEXT",
      "TEXT",
    );
    _winNotifyPlugin.showNotificationPluginTemplate(message);
  }

  sendMyOwnTemplate() {
    // image tag src must be set
    const String template = """
<toast activationType="protocol">
  <visual>
    <binding template="ToastGeneric">
      <text>Weather app</text>
      <text>Expect rain today.</text>
      <group>
        <subgroup hint-weight="1" hint-textStacking="center">
          <text hint-align="center" hint-style="header">15°</text>
          <text hint-align="center" hint-style="SubtitleSubtle">Rainy</text>
        </subgroup>
        <subgroup hint-weight="1">
          <text hint-align="center">Mon</text>
          <image src="C:/Users/HP/Desktop/wallet_images/sun.jpg" hint-removeMargin="true" />
          <text hint-align="center">15°</text>
        </subgroup>
        <subgroup hint-weight="1">
          <text hint-align="center">Tue</text>
          <image src="C:/Users/HP/Desktop/wallet_images/sun.jpg" hint-removeMargin="true" />
          <text hint-align="center">17°</text>
        </subgroup>
        <subgroup hint-weight="1">
          <text hint-align="center">Wed</text>
          <image src="C:/Users/HP/Desktop/wallet_images/w.jpg" hint-removeMargin="true" />
          <text hint-align="center">21°</text>
        </subgroup>
      </group>
    </binding>
  </visual>
</toast>
""";
    NotificationMessage message =
        NotificationMessage.fromCustomTemplate("test1", group: "jj");
    _winNotifyPlugin.showNotificationCustomTemplate(message, template);
    // _winNotifyPlugin.removeNotificationGroup("jafa222r");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Theme.of(context).backgroundColor,
        floatingActionButton: FloatingActionButton.extended(
            onPressed: () {}, label: const Icon(Icons.send)),
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SizedBox(
          width: MediaQuery.of(context).size.width,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                  onPressed: () {
                    sendMyOwnTemplate();
                  },
                  child: const Text("Send custom notification")),
              const SizedBox(
                height: 15,
              ),
              ElevatedButton(
                  onPressed: () {
                    sendWithPluginTemplate();
                  },
                  child: const Text("Send plugin notification")),
              const SizedBox(
                height: 15,
              ),
              ElevatedButton(
                  onPressed: () {
                    _winNotifyPlugin.clearNotificationHistory();
                  },
                  child: const Text("Clear action center notification")),
              const SizedBox(
                height: 15,
              ),
              ElevatedButton(
                  onPressed: () {
                    _winNotifyPlugin.removeNotificationGroup("jj");
                  },
                  child: const Text("Clear group notification")),
              const SizedBox(
                height: 15,
              ),
              ElevatedButton(
                  onPressed: () {
                    _winNotifyPlugin.removeNotificationId("test1", "jj");
                  },
                  child: const Text("Remove single notification")),
            ],
          ),
        ),
      ),
    );
  }
}