easy_notifications 1.2.5
easy_notifications: ^1.2.5 copied to clipboard
A Flutter plugin for handling local notifications with enhanced security and privacy features. Supports Android, iOS and Web platforms with rich customization options.
import 'package:flutter/material.dart';
import 'package:easy_notifications/easy_notifications.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyNotifications.init();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Easy Notifications Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
final hasPermission = await EasyNotifications.askPermission();
if (hasPermission) {
await EasyNotifications.showMessage(
title: 'Test Notification',
body: 'This is a test notification',
);
}
},
child: const Text('Show Notification'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
final scheduledDate = DateTime.now().add(
const Duration(seconds: 5),
);
await EasyNotifications.scheduleMessage(
title: 'Scheduled Notification',
body: 'This notification was scheduled 5 seconds ago',
scheduledDate: scheduledDate,
);
},
child: const Text('Schedule Notification (5s)'),
),
],
),
),
),
);
}
}