import 'dart:isolate'; import 'dart:ui';
import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart';
import 'NotificationController.dart';
// kaynak : https://pub.dev/packages/awesome_notifications void main() { WidgetsFlutterBinding.ensureInitialized();
AwesomeNotifications().isNotificationAllowed().then((isAllowed) { if (!isAllowed) { // This is just a basic example. For real apps, you must show some // friendly dialog box before call the request method. // This is very important to not harm the user experience AwesomeNotifications().requestPermissionToSendNotifications(); } });
AwesomeNotifications().initialize('resource://drawable/ic_launcher', [ // notification icon NotificationChannel( channelGroupKey: 'basic_test', channelKey: 'basic', channelName: 'Basic notifications', channelDescription: 'Notification channel for basic tests', channelShowBadge: true, importance: NotificationImportance.High, enableVibration: true, ), ]);
runApp(MyApp()); }
class MyApp extends StatelessWidget { MyApp({super.key});
@override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } }
class MyHomePage extends StatefulWidget { MyHomePage({super.key});
@override State<MyHomePage> createState() => _MyHomePageState(); }
class _MyHomePageState extends State<MyHomePage> { @override void initState() { // TODO: implement initState super.initState();
AwesomeNotifications().setListeners( onActionReceivedMethod: (ReceivedAction receivedAction) { print("buradayim!!");
if (receivedAction?.buttonKeyPressed == 'Yenile') { print("Yeniledim...!!"); sendNoti("Rambo 2"); }
return NotificationController.onActionReceivedMethod(receivedAction); }, ); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("LOCAL NOTİ"), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: () { sendNoti("Rambo 1"); }, child: Text("BAŞLAT")), ], ), ), ); }
void sendNoti(String text) { AwesomeNotifications().createNotification( content: NotificationContent( //simgple notification id: 123, channelKey: 'basic', //set configuration wuth key "basic" title: text, body: 'This simple notification with action buttons in Flutter App', payload: {"name": "FlutterCampus"}, autoDismissible: false,
locked: true, // hiç kapanmaması için ), actionButtons: [ NotificationActionButton( key: "Yenile", label: "Yenile", autoDismissible: false, isDangerousOption: true, actionType: ActionType.Default), // KeepOnTop NotificationActionButton( key: "Kapat", label: "Kapat", autoDismissible: false, isDangerousOption: true, actionType: ActionType.DismissAction), ], // schedule: NotificationCalendar( // second: 3, // dakikada 1 demek // repeats: true, // ), ); } }
|