skip to Main Content

This is how I am creating a notification using Awesome Notifications in flutter

AwesomeNotifications().createNotification(
            content: NotificationContent(
                id: 1,
                channelKey: 'basic_channel',
                title: "You spent some money?",
                body:
                    "We think, ₹ ${jsonObject['amount']} that was ${jsonObject['type']} to ${jsonObject['vendor']} belongs to this category: ${jsonObject['category']}",
                actionType: ActionType.Default),
            actionButtons: [
              NotificationActionButton(
                key: 'Approve',
                label: 'Approve',
              ),
              NotificationActionButton(
                key: 'Edit',
                label: 'Edit',
              )
            ],
          );

I want to add different functionalities to Approve and Edit options. What is the exact syntax to do that?

2

Answers


  1. try {
          var response = await http.get(Uri.parse(url));
          if (Platform.isAndroid) {
            await Permission.storage.request();
          }
          var status = await Permission.storage.status;
          if (!status.isGranted) {
            await Permission.storage.request();
          }
          if (response.statusCode == 200) {
            String fileName = 'certificate_$certificateNumber.pdf';
            const downloadsFolderPath = '/storage/emulated/0/Download/';
            Directory dir = Directory(downloadsFolderPath);
            File file = File('${dir.path}/$fileName');
            OpenFile.open(file.path);
        
            AwesomeNotifications().createNotification(
              actionButtons: [
                NotificationActionButton(
                  key: 'OPEN',
                  label: 'Open',
                ),
              ],
              content: NotificationContent(
                payload: {'PDF_Downloader': dir.path, 'file': fileName},
                id: 1,
                channelKey: "PDF_Downloader",
                title: "Certificate Downloaded",
                body: "PDF has been downloaded successfully in Download Folder",
              ),
            );
        
            await file.writeAsBytes(response.bodyBytes);
            String date = DateTime.now().toString();
            setState(() {
              verificationDate = date;
            });
    

    This is a example of Downloading a PDF file and showing a notification to PDF Downloaded successfully and give option to open it
    So, Ive Passed Payload to Notification

    In your case You have to give a Channle Key and You have to create a funtion for your specific functionality and replace in place of enter code heredir.path

    I hope it will work.

    Login or Signup to reply.
  2. Since you have the keys you can use this

    AwesomeNotifications().actionStream.listen((receivedAction) {
        if (receivedAction.buttonKey == 'Approve') {
          handleApproveAction();
        } else if (receivedAction.buttonKey == 'Edit') {
          handleEditAction();
        }
      });
    

    You will then need to create these 2 functions with your desired functionalities, if the functionalities are very similar you could create only 1 function and send the receivedAction.buttonKey as a parameter.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search