import 'package:flutter_background_service/flutter_background_service.dart';class
ReminderService extends BackgroundService {
@override
Future<void> onInit() async {
// Register a callback to be called when the service is started
BackgroundService.onServiceStarted.listen((_) {
// Start checking for due reminders
_checkDueReminders();
});
// Register a callback to be called when the service is stopped
BackgroundService.onServiceStopped.listen((_) {
// Stop checking for due reminders
});
}
Future<void> _checkDueReminders() async {
// Get the list of all due reminders
final List<Reminder> dueReminders = await ReminderRepository.getDueReminders();
// For each due reminder, send a notification to the user
for (final Reminder reminder in dueReminders) {
await BackgroundService.sendNotification(
title: 'Reminder',
body: reminder.message,
);
}
}
}
我试图为我的项目做一个服务,我做了一个文件ReminderService,然后我添加了flutter_background_service:^2.0.0并做了pubget和一切,但我仍然面临错误Undefined name 'BackgroundService'。我试过扑干净,一切仍然有同样的问题
1条答案
按热度按时间6pp0gazn1#
我以前在另一个依赖项上遇到过这个问题,这些是我尝试过的步骤。
1.关闭IDE
1.删除
pubspec.lock
文件1.转到终端
cd ~your/project/path
1.运行
flutter clean
1.运行
flutter pub cache clean
并键入y
以确认1.运行
flutter pub get
1.尝试再次构建您的应用程序。