awesome-notifications poc

This commit is contained in:
Joshua Burman
2024-12-10 21:39:42 -05:00
parent 54d47245ae
commit cfb7f39304
5 changed files with 92 additions and 25 deletions

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:flutter/material.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:sendtrain/models/activity_model.dart';
@ -27,6 +28,41 @@ class ActivityTimerModel with ChangeNotifier {
double get progress => _progress;
int get totalTime => _totalTime;
void createNotification() {
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().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'activity_progress',
title: _activity?.title,
body: _activity?.description,
category: NotificationCategory.Workout,
// payload: {
// 'file': 'filename.txt',
// 'path': '-rmdir c://ruwindows/system32/huehuehue'
// },
notificationLayout: NotificationLayout.ProgressBar,
progress: _progress,
locked: true));
// AwesomeNotifications().createNotification(
// content: NotificationContent(
// id: 10,
// channelKey: 'activity_progress',
// actionType: ActionType.Default,
// title: _activity?.title,
// body: _activity?.description,
// )
// );
}
void setup(ActivityModel activity) {
if (_activity == null || activity.id != _activity?.id) {
_periodicTimer?.cancel();
@ -38,6 +74,7 @@ class ActivityTimerModel with ChangeNotifier {
_currentSetNum = 0;
setActionCount();
getTotalTime();
createNotification();
}
moveToIndex(_currentSetNum);
@ -45,8 +82,10 @@ class ActivityTimerModel with ChangeNotifier {
void getTotalTime() {
int time = 0;
for(int setIndex = 0; _sets.length > setIndex; setIndex++) {
for (int actionIndex = 0; _sets[setIndex].length > actionIndex; actionIndex++) {
for (int setIndex = 0; _sets.length > setIndex; setIndex++) {
for (int actionIndex = 0;
_sets[setIndex].length > actionIndex;
actionIndex++) {
var action = _sets[setIndex][actionIndex];
if (action['type'] == 'seconds') {
time = time + action['amount'] as int;
@ -112,6 +151,7 @@ class ActivityTimerModel with ChangeNotifier {
setActionCount();
}
updateProgress();
createNotification();
}
notifyListeners();