39 lines
774 B
Dart
39 lines
774 B
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
class AppAlert {
|
|
final String id;
|
|
final String title;
|
|
final String body;
|
|
final DateTime timestamp;
|
|
|
|
AppAlert({
|
|
required this.id,
|
|
required this.title,
|
|
required this.body,
|
|
required this.timestamp,
|
|
});
|
|
}
|
|
|
|
class AlertsNotifier extends Notifier<List<AppAlert>> {
|
|
@override
|
|
List<AppAlert> build() => [];
|
|
|
|
void addAlert(String title, String body) {
|
|
state = [
|
|
AppAlert(
|
|
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
|
title: title,
|
|
body: body,
|
|
timestamp: DateTime.now(),
|
|
),
|
|
...state,
|
|
];
|
|
}
|
|
|
|
void clearAll() => state = [];
|
|
}
|
|
|
|
final alertsProvider = NotifierProvider<AlertsNotifier, List<AppAlert>>(
|
|
AlertsNotifier.new,
|
|
);
|