feat:增加变化提醒功能
This commit is contained in:
@@ -14,7 +14,7 @@ void main() async {
|
|||||||
Hive.registerAdapter(HealthRecordAdapter());
|
Hive.registerAdapter(HealthRecordAdapter());
|
||||||
|
|
||||||
final healthsBox = await Hive.openBox<HealthRecord>('healths');
|
final healthsBox = await Hive.openBox<HealthRecord>('healths');
|
||||||
// healthsBox.clear();
|
healthsBox.clear();
|
||||||
// await Hive.deleteBoxFromDisk('healths');
|
// await Hive.deleteBoxFromDisk('healths');
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
|
|||||||
@@ -67,13 +67,14 @@ class HealthRecord extends HiveObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum RecordType {
|
enum RecordType {
|
||||||
weight('体重', FontAwesomeIcons.weightScale, Color(0xFFF59E0B)),
|
weight('体重', FontAwesomeIcons.weightScale, Color(0xFFF59E0B), 'Kg'),
|
||||||
sport('运动', FontAwesomeIcons.personRunning, Color(0xFF38BDF8)),
|
sport('运动', FontAwesomeIcons.personRunning, Color(0xFF38BDF8), '分钟'),
|
||||||
sleep('睡眠', FontAwesomeIcons.moon, Color(0xFF10B981));
|
sleep('睡眠', FontAwesomeIcons.moon, Color(0xFF10B981), '小时');
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final Color color;
|
final Color color;
|
||||||
|
final String unit;
|
||||||
|
|
||||||
const RecordType(this.title, this.icon, this.color);
|
const RecordType(this.title, this.icon, this.color, this.unit);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:fitnote/layout/app_navbar.dart';
|
import 'package:fitnote/layout/app_navbar.dart';
|
||||||
|
import 'package:fitnote/models/health.dart';
|
||||||
import 'package:fitnote/models/menu.dart';
|
import 'package:fitnote/models/menu.dart';
|
||||||
import 'package:fitnote/provider/health_provider.dart';
|
import 'package:fitnote/provider/health_provider.dart';
|
||||||
import 'package:fitnote/service/health_service.dart';
|
import 'package:fitnote/service/health_service.dart';
|
||||||
@@ -65,7 +66,9 @@ class _HomePageState extends State<HomePage> {
|
|||||||
final HealthService service = HealthService();
|
final HealthService service = HealthService();
|
||||||
final provider = context.read<HealthProvider>();
|
final provider = context.read<HealthProvider>();
|
||||||
provider.updateSelectDate(DateTime.now());
|
provider.updateSelectDate(DateTime.now());
|
||||||
provider.updateRecord(service.getRecordByDate(provider.selectedDate));
|
HealthRecord record = service.getRecordByDate(provider.selectedDate);
|
||||||
|
provider.updateRecord(record);
|
||||||
|
provider.initForm(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onTapNavbarItem(int index) {
|
void _onTapNavbarItem(int index) {
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ class HealthProvider with ChangeNotifier {
|
|||||||
num avgSleep = 0;
|
num avgSleep = 0;
|
||||||
|
|
||||||
void initForm(HealthRecord record) {
|
void initForm(HealthRecord record) {
|
||||||
formItem = record;
|
formItem = record.copyWith();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateRecord(HealthRecord record) {
|
void updateRecord(HealthRecord record) {
|
||||||
currentRecord = record;
|
currentRecord = record.copyWith();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,18 @@ class HealthService {
|
|||||||
return box.values.toList();
|
return box.values.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<HealthRecord> getAllRecordsOrderByDate() {
|
||||||
|
final records = getAllRecords();
|
||||||
|
|
||||||
|
records.sort((a, b) {
|
||||||
|
final dateA = DateTime.parse(a.date);
|
||||||
|
final dateB = DateTime.parse(b.date);
|
||||||
|
return dateB.compareTo(dateA);
|
||||||
|
});
|
||||||
|
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
|
||||||
HealthRecord getRecordByDate(DateTime date) {
|
HealthRecord getRecordByDate(DateTime date) {
|
||||||
final record = box.values.toList().firstWhere(
|
final record = box.values.toList().firstWhere(
|
||||||
(item) => item.date == formatDate(date),
|
(item) => item.date == formatDate(date),
|
||||||
@@ -30,6 +42,7 @@ class HealthService {
|
|||||||
return record.copyWith();
|
return record.copyWith();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取总运动时长
|
||||||
num getTotalSport() {
|
num getTotalSport() {
|
||||||
int year = DateTime.now().year;
|
int year = DateTime.now().year;
|
||||||
int month = DateTime.now().month;
|
int month = DateTime.now().month;
|
||||||
@@ -48,6 +61,7 @@ class HealthService {
|
|||||||
return totalDuration;
|
return totalDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取平均睡眠
|
||||||
num getAvgSleep() {
|
num getAvgSleep() {
|
||||||
int year = DateTime.now().year;
|
int year = DateTime.now().year;
|
||||||
int month = DateTime.now().month;
|
int month = DateTime.now().month;
|
||||||
@@ -61,7 +75,7 @@ class HealthService {
|
|||||||
final recordDate = DateTime.parse(record.date);
|
final recordDate = DateTime.parse(record.date);
|
||||||
if (recordDate.year == year && recordDate.month == month) {
|
if (recordDate.year == year && recordDate.month == month) {
|
||||||
total++;
|
total++;
|
||||||
totalDuration += calSleepMinuteDuration(startTime, endTime);
|
totalDuration += calSleepMinDuration(startTime, endTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,14 +87,9 @@ class HealthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取最新体重
|
||||||
num getLatestWeight() {
|
num getLatestWeight() {
|
||||||
final records = getAllRecords();
|
final records = getAllRecordsOrderByDate();
|
||||||
|
|
||||||
records.sort((a, b) {
|
|
||||||
final dateA = DateTime.parse(a.date);
|
|
||||||
final dateB = DateTime.parse(b.date);
|
|
||||||
return dateB.compareTo(dateA);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (final record in records) {
|
for (final record in records) {
|
||||||
if (record.weight != 0) {
|
if (record.weight != 0) {
|
||||||
@@ -91,10 +100,68 @@ class HealthService {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取上次体重
|
||||||
|
num getLastWeight(String date) {
|
||||||
|
final records = getAllRecordsOrderByDate();
|
||||||
|
|
||||||
|
final targetIndex = records.indexWhere((record) => record.date == date);
|
||||||
|
if (targetIndex == -1) return 0;
|
||||||
|
|
||||||
|
// 从目标日期往前找(更早的日期)
|
||||||
|
for (int i = targetIndex + 1; i < records.length; i++) {
|
||||||
|
final record = records[i];
|
||||||
|
if (record.weight != 0) {
|
||||||
|
return record.weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取上次运动时长
|
||||||
|
num getLastSport(String date) {
|
||||||
|
final records = getAllRecordsOrderByDate();
|
||||||
|
|
||||||
|
final targetIndex = records.indexWhere((record) => record.date == date);
|
||||||
|
if (targetIndex == -1) return 0;
|
||||||
|
|
||||||
|
// 从目标日期往前找(更早的日期)
|
||||||
|
for (int i = targetIndex + 1; i < records.length; i++) {
|
||||||
|
final record = records[i];
|
||||||
|
if (record.sportDuration != 0) {
|
||||||
|
return record.sportDuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取上次睡眠时长
|
||||||
|
num getLastSleep(String date) {
|
||||||
|
final records = getAllRecordsOrderByDate();
|
||||||
|
|
||||||
|
final targetIndex = records.indexWhere((record) => record.date == date);
|
||||||
|
if (targetIndex == -1) return 0;
|
||||||
|
|
||||||
|
// 从目标日期往前找(更早的日期)
|
||||||
|
for (int i = targetIndex + 1; i < records.length; i++) {
|
||||||
|
final record = records[i];
|
||||||
|
final startTime = record.sleepStartTime;
|
||||||
|
final endTime = record.sleepEndTime;
|
||||||
|
if (startTime.isNotEmpty && endTime.isNotEmpty) {
|
||||||
|
return calSleepMinDuration(startTime, endTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Future<bool> updateRecord(HealthRecord record) async {
|
Future<bool> updateRecord(HealthRecord record) async {
|
||||||
try {
|
try {
|
||||||
final existingRecords = box.values.toList();
|
final existingRecords = box.values.toList();
|
||||||
final index = existingRecords.indexWhere((item) => item.date == record.date);
|
final index = existingRecords.indexWhere(
|
||||||
|
(item) => item.date == record.date,
|
||||||
|
);
|
||||||
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
await box.add(record);
|
await box.add(record);
|
||||||
@@ -102,7 +169,7 @@ class HealthService {
|
|||||||
final key = box.keyAt(index);
|
final key = box.keyAt(index);
|
||||||
await box.put(key, record);
|
await box.put(key, record);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Update record error: $e');
|
print('Update record error: $e');
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ String formatTime(TimeOfDay time) {
|
|||||||
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||||
}
|
}
|
||||||
|
|
||||||
int calSleepMinuteDuration(String startTime, String endTime) {
|
int calSleepMinDuration(String startTime, String endTime) {
|
||||||
final start = parseTime(startTime);
|
final start = parseTime(startTime);
|
||||||
final end = parseTime(endTime);
|
final end = parseTime(endTime);
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ int calSleepMinuteDuration(String startTime, String endTime) {
|
|||||||
// 计算睡眠时长
|
// 计算睡眠时长
|
||||||
String calSleepDuration(String startTime, String endTime) {
|
String calSleepDuration(String startTime, String endTime) {
|
||||||
try {
|
try {
|
||||||
int durationMinutes = calSleepMinuteDuration(startTime, endTime);
|
int durationMinutes = calSleepMinDuration(startTime, endTime);
|
||||||
int hours = durationMinutes ~/ 60;
|
int hours = durationMinutes ~/ 60;
|
||||||
int minutes = durationMinutes % 60;
|
int minutes = durationMinutes % 60;
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ String calSleepDuration(String startTime, String endTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double roundNum(double value) {
|
double roundNum(num value) {
|
||||||
return double.parse(value.toStringAsFixed(2));
|
return double.parse(value.toStringAsFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +87,9 @@ String formatContent(HealthRecord record, RecordType type) {
|
|||||||
late String title;
|
late String title;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordType.weight:
|
case RecordType.weight:
|
||||||
title = "${record.weight} kg";
|
title = "${record.weight} ${type.unit}";
|
||||||
case RecordType.sport:
|
case RecordType.sport:
|
||||||
title = "${record.sportProject} · ${record.sportDuration} 分钟";
|
title = "${record.sportProject} · ${record.sportDuration} ${type.unit}";
|
||||||
case RecordType.sleep:
|
case RecordType.sleep:
|
||||||
final startTime = record.sleepStartTime;
|
final startTime = record.sleepStartTime;
|
||||||
final endTime = record.sleepEndTime;
|
final endTime = record.sleepEndTime;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import 'package:fitnote/utils/record_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:getwidget/getwidget.dart';
|
||||||
|
|
||||||
Widget buildCardTitle({
|
Widget buildCardTitle({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
@@ -45,3 +47,40 @@ BoxDecoration buildBoxDecoration(BuildContext context) {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget buildProgressItem({
|
||||||
|
required String title,
|
||||||
|
required String current,
|
||||||
|
required String target,
|
||||||
|
required String unit,
|
||||||
|
required double progress,
|
||||||
|
required Color color,
|
||||||
|
}) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(title),
|
||||||
|
Text(
|
||||||
|
'$current/$target $unit',
|
||||||
|
style: TextStyle(fontWeight: FontWeight.w500, color: color),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
GFProgressBar(
|
||||||
|
animation: true,
|
||||||
|
lineHeight: 20,
|
||||||
|
percentage: progress,
|
||||||
|
progressBarColor: color,
|
||||||
|
child: Text(
|
||||||
|
'${roundNum(progress * 100)}%',
|
||||||
|
textAlign: TextAlign.end,
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import 'package:fitnote/widget/record/common.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_common/widget/common_widget.dart';
|
import 'package:flutter_common/widget/common_widget.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:getwidget/getwidget.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class GoalProgress extends StatefulWidget {
|
class GoalProgress extends StatefulWidget {
|
||||||
@@ -48,11 +47,11 @@ class _GoalProgressState extends State<GoalProgress> {
|
|||||||
icon: FontAwesomeIcons.trophy,
|
icon: FontAwesomeIcons.trophy,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 28),
|
const SizedBox(height: 28),
|
||||||
_buildProgressItem(
|
buildProgressItem(
|
||||||
title: '目标体重',
|
title: '目标体重',
|
||||||
current: provider.latestWeight.toString(),
|
current: provider.latestWeight.toString(),
|
||||||
target: AppConfig.goalWeight.toString(),
|
target: AppConfig.goalWeight.toString(),
|
||||||
unit: 'kg',
|
unit: RecordType.weight.unit,
|
||||||
progress: calWeightProgress(
|
progress: calWeightProgress(
|
||||||
provider.latestWeight,
|
provider.latestWeight,
|
||||||
AppConfig.goalWeight,
|
AppConfig.goalWeight,
|
||||||
@@ -61,22 +60,22 @@ class _GoalProgressState extends State<GoalProgress> {
|
|||||||
color: RecordType.weight.color,
|
color: RecordType.weight.color,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 28),
|
const SizedBox(height: 28),
|
||||||
_buildProgressItem(
|
buildProgressItem(
|
||||||
title: '运动总时长',
|
title: '运动总时长',
|
||||||
current: provider.totalSpot.toString(),
|
current: provider.totalSpot.toString(),
|
||||||
target: AppConfig.goalTotalSpot.toString(),
|
target: AppConfig.goalTotalSpot.toString(),
|
||||||
unit: '分钟',
|
unit: RecordType.sport.unit,
|
||||||
progress: formatProgress(
|
progress: formatProgress(
|
||||||
provider.totalSpot / AppConfig.goalTotalSpot,
|
provider.totalSpot / AppConfig.goalTotalSpot,
|
||||||
),
|
),
|
||||||
color: RecordType.sport.color,
|
color: RecordType.sport.color,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 28),
|
const SizedBox(height: 28),
|
||||||
_buildProgressItem(
|
buildProgressItem(
|
||||||
title: '日均睡眠',
|
title: '日均睡眠',
|
||||||
current: provider.avgSleep.toString(),
|
current: provider.avgSleep.toString(),
|
||||||
target: AppConfig.goalAvgSleep.toString(),
|
target: AppConfig.goalAvgSleep.toString(),
|
||||||
unit: '小时',
|
unit: RecordType.sleep.unit,
|
||||||
progress: formatProgress(
|
progress: formatProgress(
|
||||||
provider.avgSleep / AppConfig.goalAvgSleep,
|
provider.avgSleep / AppConfig.goalAvgSleep,
|
||||||
),
|
),
|
||||||
@@ -86,41 +85,4 @@ class _GoalProgressState extends State<GoalProgress> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProgressItem({
|
|
||||||
required String title,
|
|
||||||
required String current,
|
|
||||||
required String target,
|
|
||||||
required String unit,
|
|
||||||
required double progress,
|
|
||||||
required Color color,
|
|
||||||
}) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(title),
|
|
||||||
Text(
|
|
||||||
'$current/$target $unit',
|
|
||||||
style: TextStyle(fontWeight: FontWeight.w500, color: color),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
GFProgressBar(
|
|
||||||
animation: true,
|
|
||||||
lineHeight: 20,
|
|
||||||
percentage: progress,
|
|
||||||
progressBarColor: color,
|
|
||||||
child: Text(
|
|
||||||
'${roundNum(progress * 100)}%',
|
|
||||||
textAlign: TextAlign.end,
|
|
||||||
style: TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:fitnote/models/health.dart';
|
||||||
import 'package:fitnote/provider/health_provider.dart';
|
import 'package:fitnote/provider/health_provider.dart';
|
||||||
import 'package:fitnote/service/health_service.dart';
|
import 'package:fitnote/service/health_service.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -32,7 +33,9 @@ class _RecordCalendarState extends State<RecordCalendar> {
|
|||||||
onDaySelected: (selectedDay, focusedDay) {
|
onDaySelected: (selectedDay, focusedDay) {
|
||||||
if (!isSameDay(provider.selectedDate, selectedDay)) {
|
if (!isSameDay(provider.selectedDate, selectedDay)) {
|
||||||
provider.updateSelectDate(selectedDay);
|
provider.updateSelectDate(selectedDay);
|
||||||
provider.updateRecord(service.getRecordByDate(provider.selectedDate));
|
HealthRecord record = service.getRecordByDate(provider.selectedDate);
|
||||||
|
provider.updateRecord(record);
|
||||||
|
provider.initForm(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -108,6 +108,12 @@ class _RecordDailyState extends State<RecordDaily> {
|
|||||||
_buildRecordTitle(type),
|
_buildRecordTitle(type),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
_buildRecordContent(provider.currentRecord, type),
|
_buildRecordContent(provider.currentRecord, type),
|
||||||
|
if (checkHasRecordValue(provider.currentRecord, type))
|
||||||
|
_buildRecordTip(
|
||||||
|
provider.currentRecord,
|
||||||
|
provider.selectedDate,
|
||||||
|
type,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
trailing: GestureDetector(
|
trailing: GestureDetector(
|
||||||
@@ -279,4 +285,49 @@ class _RecordDailyState extends State<RecordDaily> {
|
|||||||
|
|
||||||
return Text(formatContent(record, type), style: TextStyle(fontSize: 14));
|
return Text(formatContent(record, type), style: TextStyle(fontSize: 14));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildRecordTip(HealthRecord record, DateTime date, RecordType type) {
|
||||||
|
late num lastValue = 0;
|
||||||
|
late String change = '';
|
||||||
|
switch (type) {
|
||||||
|
case RecordType.weight:
|
||||||
|
lastValue = service.getLastWeight(formatDate(date));
|
||||||
|
break;
|
||||||
|
case RecordType.sport:
|
||||||
|
lastValue = service.getLastSport(formatDate(date));
|
||||||
|
break;
|
||||||
|
case RecordType.sleep:
|
||||||
|
lastValue = service.getLastSleep(formatDate(date));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastValue == 0) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case RecordType.weight:
|
||||||
|
num difference = record.weight - lastValue;
|
||||||
|
String formattedDiff = NumberFormat('+0.00;-0.00').format(difference);
|
||||||
|
change = '较上次 $formattedDiff ${type.unit}';
|
||||||
|
break;
|
||||||
|
case RecordType.sport:
|
||||||
|
num difference = record.sportDuration - lastValue;
|
||||||
|
String formattedDiff = NumberFormat('+0;-0').format(difference);
|
||||||
|
change = '较上次 $formattedDiff ${type.unit}';
|
||||||
|
break;
|
||||||
|
case RecordType.sleep:
|
||||||
|
String startTime = record.sleepStartTime;
|
||||||
|
String endTime = record.sleepEndTime;
|
||||||
|
num difference = calSleepMinDuration(startTime, endTime) - lastValue;
|
||||||
|
String formattedDiff = NumberFormat('+0.00;-0.00').format(difference / 60);
|
||||||
|
change = '较上次 $formattedDiff ${type.unit}';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Text(
|
||||||
|
change,
|
||||||
|
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user