simple_local_notifications 0.0.2 copy "simple_local_notifications: ^0.0.2" to clipboard
simple_local_notifications: ^0.0.2 copied to clipboard

PlatformAndroid

A simple, no nonsense local notifications plugin for Flutter.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:permission_handler/permission_handler.dart';
import 'package:simple_local_notifications/models/notification.dart';
import 'package:simple_local_notifications/simple_local_notifications.dart';

void main() {
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  final _simpleLocalNotificationsPlugin = SimpleLocalNotifications();

  @override
  void initState() {
    super.initState();
    initApplication();
  }

  Future<void> initApplication() async {
    try {
      await _simpleLocalNotificationsPlugin.createNotificationChannel(
          channelId: "simple_local_notifications_channel_priority",
          channelName: "simple_local_notifications_priority",
          priority: SLNotificationPriority.high);
    } catch (e) {
      print(e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              TextButton(
                onPressed: () async {
                  await Permission.notification.request();
                  await _simpleLocalNotificationsPlugin
                      .sendNotification(SLNotification(
                    title: "Hello world",
                    content: "from a flutter plugin",
                    iconPath: "assets/icons/icon.png",
                  ));
                },
                child: const Text("Send notification"),
              ),
              TextButton(
                onPressed: () async {
                  await Permission.notification.request();
                  await _simpleLocalNotificationsPlugin
                      .sendNotification(SLNotification(
                    title: "Hello world",
                    content: "from a flutter plugin",
                    iconPath: "assets/icons/icon.png",
                    channelId: "simple_local_notifications_channel_priority",
                    channelName: "simple_local_notifications_priority",
                    priority: SLNotificationPriority.high,
                  ));
                },
                child: const Text("Send HIGH notification"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
28
downloads

Publisher

verified publishermatteogassend.com

Weekly Downloads

A simple, no nonsense local notifications plugin for Flutter.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, protobuf

More

Packages that depend on simple_local_notifications