feat:增加刷新日程提醒功能
This commit is contained in:
@@ -2,7 +2,13 @@ import 'package:flisp_app/layout/app_body.dart';
|
||||
import 'package:flisp_app/layout/app_drawer.dart';
|
||||
import 'package:flisp_app/layout/app_floating_button.dart';
|
||||
import 'package:flisp_app/layout/app_navbar.dart';
|
||||
import 'package:flisp_app/models/calendar.dart';
|
||||
import 'package:flisp_app/models/todo.dart';
|
||||
import 'package:flisp_app/provider/app_provider.dart';
|
||||
import 'package:flisp_app/service/calendar_service.dart';
|
||||
import 'package:flisp_app/service/todo_service.dart';
|
||||
import 'package:flisp_app/utils/date_utils.dart';
|
||||
import 'package:flisp_app/utils/notify_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -15,11 +21,55 @@ class MainScreen extends StatefulWidget {
|
||||
|
||||
class _MainScreenState extends State<MainScreen> {
|
||||
final GlobalKey<AppBodyState> _appBodyKey = GlobalKey();
|
||||
final NotifyService notifyService = NotifyService();
|
||||
|
||||
void _onPressedFloatingButton(int index) {
|
||||
_appBodyKey.currentState?.showPageAddDialog(index);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
refreshScheduled();
|
||||
}
|
||||
|
||||
/// 重新刷新提醒 防止每次重启设备后提醒丢失的问题
|
||||
void refreshScheduled() async {
|
||||
await notifyService.cancelAllNotifications();
|
||||
|
||||
TodoService todoService = TodoService();
|
||||
final List<Todo> todoResult = todoService.getAllTodos(
|
||||
TodoSortMode.priority,
|
||||
);
|
||||
final List<Todo> todayTodos =
|
||||
todoResult.where((todo) => isToday(todo.scheduledTime)).toList();
|
||||
|
||||
for (Todo todo in todayTodos) {
|
||||
await notifyService.scheduleNotification(
|
||||
id: todo.id,
|
||||
title: '待办提醒',
|
||||
body: todo.title,
|
||||
scheduledTime: todo.scheduledTime!,
|
||||
);
|
||||
}
|
||||
|
||||
CalendarService calendarService = CalendarService();
|
||||
final List<Calendar> calendarResult = calendarService.getAllCalendars();
|
||||
final List<Calendar> todayCalendars =
|
||||
calendarResult
|
||||
.where((calendar) => isToday(calendar.scheduledTime))
|
||||
.toList();
|
||||
|
||||
for (Calendar calendar in todayCalendars) {
|
||||
await notifyService.scheduleNotification(
|
||||
id: calendar.id,
|
||||
title: '日程提醒',
|
||||
body: calendar.title,
|
||||
scheduledTime: calendar.scheduledTime!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:flisp_app/service/todo_service.dart';
|
||||
import 'package:flisp_app/widgets/chart.dart';
|
||||
import 'package:flisp_app/widgets/common.dart';
|
||||
import 'package:flisp_app/widgets/flisp_widget.dart';
|
||||
import 'package:flisp_app/widgets/stats.dart';
|
||||
import 'package:flisp_app/widgets/todo_widget.dart';
|
||||
import 'package:flisp_app/widgets/year_selector.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -124,7 +123,7 @@ class StatsPageState extends State<StatsPage> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(child: buildFlispStatsCard(allFlisps)),
|
||||
buildFlispStatsCard(allFlisps),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,3 +7,12 @@ String formatDate(DateTime date) {
|
||||
String formatTime(DateTime datetime) {
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
|
||||
}
|
||||
|
||||
bool isToday(DateTime? date) {
|
||||
if (date == null) return false;
|
||||
|
||||
final now = DateTime.now();
|
||||
return date.year == now.year &&
|
||||
date.month == now.month &&
|
||||
date.day == now.day;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:flisp_app/models/flisp.dart';
|
||||
import 'package:flisp_app/widgets/common.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:toggle_switch/toggle_switch.dart';
|
||||
|
||||
Widget buildFlispStatsCard(List<Flisp> flisps) {
|
||||
int totalCount = flisps.length;
|
||||
@@ -14,6 +13,7 @@ Widget buildFlispStatsCard(List<Flisp> flisps) {
|
||||
return BuildCard(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildStatItem('总计', totalCount, Colors.orange),
|
||||
_buildStatItem('生活', lifeCount, FlispTag.life.color),
|
||||
@@ -79,12 +79,14 @@ Widget buildFlispList({
|
||||
}
|
||||
|
||||
Widget _buildFlispContent(BuildContext context, Flisp flisp) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
text: flisp.content,
|
||||
style: TextStyle(
|
||||
fontFamily: 'CustomFont',
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
color: colors.onSurface,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -15,6 +15,7 @@ Widget buildTodoStatsCard(List<Todo> todos) {
|
||||
return BuildCard(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildStatItem('总计', totalCount, Colors.blue),
|
||||
_buildStatItem('待完成', activeCount, Colors.orange),
|
||||
|
||||
Reference in New Issue
Block a user