feat:更新UI布局
This commit is contained in:
8
lib/config/app_config.dart
Normal file
8
lib/config/app_config.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
class AppConfig {
|
||||
static const int initWeight = 72;
|
||||
static const int goalWeight = 70;
|
||||
static const int goalTotalSpot = 600;
|
||||
static const int goalAvgSleep = 8;
|
||||
|
||||
static const List<String> sportProjectList = ['羽毛球', '乒乓球', '跑步'];
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:fitnote/provider/health_provider.dart';
|
||||
import 'package:fitnote/service/health_service.dart';
|
||||
import 'package:fitnote/widget/record/record_calendar.dart';
|
||||
import 'package:fitnote/widget/record/record_daily.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class HistoryPage extends StatefulWidget {
|
||||
const HistoryPage({super.key});
|
||||
@@ -16,36 +14,13 @@ class HistoryPage extends StatefulWidget {
|
||||
class _HistoryPageState extends State<HistoryPage> {
|
||||
final HealthService service = HealthService();
|
||||
|
||||
TableCalendar _calendar() {
|
||||
final provider = context.watch<HealthProvider>();
|
||||
|
||||
return TableCalendar(
|
||||
locale: 'zh_CN',
|
||||
headerStyle: const HeaderStyle(
|
||||
headerPadding: EdgeInsets.symmetric(vertical: 0),
|
||||
formatButtonVisible: false,
|
||||
titleCentered: true,
|
||||
),
|
||||
firstDay: DateTime.utc(2010, 1, 1),
|
||||
lastDay: DateTime.utc(2100, 12, 31),
|
||||
focusedDay: provider.selectedDate,
|
||||
selectedDayPredicate: (day) => isSameDay(provider.selectedDate, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
if (!isSameDay(provider.selectedDate, selectedDay)) {
|
||||
provider.updateSelectDate(selectedDay);
|
||||
provider.updateRecord(service.getRecordByDate(provider.selectedDate));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
CommonCard(child: _calendar()),
|
||||
const SizedBox(height: 24),
|
||||
CommonCard(child: RecordCalendar()),
|
||||
const SizedBox(height: 10),
|
||||
RecordDaily(),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'package:fitnote/widget/record/goal_progress.dart';
|
||||
import 'package:fitnote/widget/record/record_daily.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class RecordPage extends StatefulWidget {
|
||||
const RecordPage({super.key});
|
||||
@@ -12,98 +10,14 @@ class RecordPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RecordPageState extends State<RecordPage> {
|
||||
// 格式化当前日期
|
||||
String _formatCurrentDate() {
|
||||
final now = DateTime.now();
|
||||
// 格式:2025年11月28日,周五
|
||||
return "${DateFormat('yyyy年MM月dd日').format(now)},${_getWeekday(now.weekday)}";
|
||||
}
|
||||
|
||||
// 数字星期转中文
|
||||
String _getWeekday(int weekday) {
|
||||
const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||
return weekdays[weekday - 1];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [GoalProgress(), const SizedBox(height: 24), RecordDaily()],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 顶部导航栏
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
color: Colors.white,
|
||||
// boxShadow: const [
|
||||
// BoxShadow(
|
||||
// color: Color(0x0A000000),
|
||||
// blurRadius: 4,
|
||||
// offset: Offset(0, 2),
|
||||
// ),
|
||||
// ],
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'早上好,用户',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1E293B),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'今天是 ${_formatCurrentDate()}',
|
||||
style: const TextStyle(fontSize: 12, color: Color(0xFF64748B)),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
// 通知按钮
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF1F5F9),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Icon(
|
||||
FontAwesomeIcons.bell,
|
||||
color: const Color(0xFF64748B),
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
// 用户头像
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFE0F2FE), // 主色浅背景
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'U',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF38BDF8),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
GoalProgress(),
|
||||
const SizedBox(height: 10),
|
||||
RecordDaily(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -82,3 +82,26 @@ double formatProgress(double value) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
String formatContent(HealthRecord record, RecordType type) {
|
||||
late String title;
|
||||
switch (type) {
|
||||
case RecordType.weight:
|
||||
title = "${record.weight} kg";
|
||||
case RecordType.sport:
|
||||
title = "${record.sportProject} · ${record.sportDuration} 分钟";
|
||||
case RecordType.sleep:
|
||||
final startTime = record.sleepStartTime;
|
||||
final endTime = record.sleepEndTime;
|
||||
if (startTime.isNotEmpty && endTime.isNotEmpty) {
|
||||
final duration = calSleepDuration(startTime, endTime);
|
||||
title = "入睡 $startTime · 起床 $endTime \n${duration}";
|
||||
} else if (startTime.isNotEmpty) {
|
||||
title = "入睡 $startTime";
|
||||
} else if (endTime.isNotEmpty) {
|
||||
title = "起床 $endTime";
|
||||
}
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fitnote/config/app_config.dart';
|
||||
import 'package:fitnote/models/health.dart';
|
||||
import 'package:fitnote/provider/health_provider.dart';
|
||||
import 'package:fitnote/service/health_service.dart';
|
||||
@@ -19,11 +20,6 @@ class GoalProgress extends StatefulWidget {
|
||||
class _GoalProgressState extends State<GoalProgress> {
|
||||
final HealthService service = HealthService();
|
||||
|
||||
final int initWeight = 72;
|
||||
final int goalWeight = 70;
|
||||
final int goalTotalSpot = 600;
|
||||
final int goalAvgSleep = 8;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -55,27 +51,35 @@ class _GoalProgressState extends State<GoalProgress> {
|
||||
_buildProgressItem(
|
||||
title: '目标体重',
|
||||
current: provider.latestWeight.toString(),
|
||||
target: goalWeight.toString(),
|
||||
target: AppConfig.goalWeight.toString(),
|
||||
unit: 'kg',
|
||||
progress: calWeightProgress(provider.latestWeight, goalWeight, initWeight),
|
||||
progress: calWeightProgress(
|
||||
provider.latestWeight,
|
||||
AppConfig.goalWeight,
|
||||
AppConfig.initWeight,
|
||||
),
|
||||
color: RecordType.weight.color,
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
_buildProgressItem(
|
||||
title: '运动总时长',
|
||||
current: provider.totalSpot.toString(),
|
||||
target: goalTotalSpot.toString(),
|
||||
target: AppConfig.goalTotalSpot.toString(),
|
||||
unit: '分钟',
|
||||
progress: formatProgress(provider.totalSpot / goalTotalSpot),
|
||||
progress: formatProgress(
|
||||
provider.totalSpot / AppConfig.goalTotalSpot,
|
||||
),
|
||||
color: RecordType.sport.color,
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
_buildProgressItem(
|
||||
title: '日均睡眠',
|
||||
current: provider.avgSleep.toString(),
|
||||
target: goalAvgSleep.toString(),
|
||||
target: AppConfig.goalAvgSleep.toString(),
|
||||
unit: '小时',
|
||||
progress: formatProgress(provider.avgSleep / goalAvgSleep),
|
||||
progress: formatProgress(
|
||||
provider.avgSleep / AppConfig.goalAvgSleep,
|
||||
),
|
||||
color: RecordType.sleep.color,
|
||||
),
|
||||
],
|
||||
@@ -111,7 +115,7 @@ class _GoalProgressState extends State<GoalProgress> {
|
||||
percentage: progress,
|
||||
progressBarColor: color,
|
||||
child: Text(
|
||||
'${progress * 100}%',
|
||||
'${roundNum(progress * 100)}%',
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
|
||||
40
lib/widget/record/record_calendar.dart
Normal file
40
lib/widget/record/record_calendar.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:fitnote/provider/health_provider.dart';
|
||||
import 'package:fitnote/service/health_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class RecordCalendar extends StatefulWidget {
|
||||
const RecordCalendar({super.key});
|
||||
|
||||
@override
|
||||
State<RecordCalendar> createState() => _RecordCalendarState();
|
||||
}
|
||||
|
||||
class _RecordCalendarState extends State<RecordCalendar> {
|
||||
final HealthService service = HealthService();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<HealthProvider>();
|
||||
|
||||
return TableCalendar(
|
||||
locale: 'zh_CN',
|
||||
headerStyle: const HeaderStyle(
|
||||
headerPadding: EdgeInsets.symmetric(vertical: 0),
|
||||
formatButtonVisible: false,
|
||||
titleCentered: true,
|
||||
),
|
||||
firstDay: DateTime.utc(2010, 1, 1),
|
||||
lastDay: DateTime.utc(2100, 12, 31),
|
||||
focusedDay: provider.selectedDate,
|
||||
selectedDayPredicate: (day) => isSameDay(provider.selectedDate, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
if (!isSameDay(provider.selectedDate, selectedDay)) {
|
||||
provider.updateSelectDate(selectedDay);
|
||||
provider.updateRecord(service.getRecordByDate(provider.selectedDate));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fitnote/config/app_config.dart';
|
||||
import 'package:fitnote/models/health.dart';
|
||||
import 'package:fitnote/provider/health_provider.dart';
|
||||
import 'package:fitnote/service/health_service.dart';
|
||||
@@ -61,16 +62,12 @@ class _RecordDailyState extends State<RecordDaily> {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF1F5F9),
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Text(
|
||||
DateFormat('MM月dd日').format(provider.selectedDate),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF64748B),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -108,14 +105,7 @@ class _RecordDailyState extends State<RecordDaily> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
type.title,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: type.color,
|
||||
),
|
||||
),
|
||||
_buildRecordTitle(type),
|
||||
const SizedBox(height: 4),
|
||||
_buildRecordContent(provider.currentRecord, type),
|
||||
],
|
||||
@@ -174,7 +164,7 @@ class _RecordDailyState extends State<RecordDaily> {
|
||||
provider.updateWeight(70);
|
||||
break;
|
||||
case RecordType.sport:
|
||||
provider.updateSportProject('跑步');
|
||||
provider.updateSportProject(AppConfig.sportProjectList[0]);
|
||||
provider.updateSportDuration(30);
|
||||
break;
|
||||
case RecordType.sleep:
|
||||
@@ -184,10 +174,11 @@ class _RecordDailyState extends State<RecordDaily> {
|
||||
}
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => Dialog(
|
||||
showDialog(context: context, builder: (context) => _buildDialog(type));
|
||||
}
|
||||
|
||||
Widget _buildDialog(RecordType type) {
|
||||
return Dialog(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Column(
|
||||
@@ -195,7 +186,6 @@ class _RecordDailyState extends State<RecordDaily> {
|
||||
children: [RecordForm(type: type), _buildDialogButton()],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -210,7 +200,7 @@ class _RecordDailyState extends State<RecordDaily> {
|
||||
Navigator.of(context).pop();
|
||||
_resetRecord();
|
||||
},
|
||||
color: colors.secondary,
|
||||
color: Colors.grey,
|
||||
text: "取消",
|
||||
),
|
||||
),
|
||||
@@ -261,48 +251,32 @@ class _RecordDailyState extends State<RecordDaily> {
|
||||
);
|
||||
|
||||
await service.updateRecord(newRecord);
|
||||
|
||||
provider.updateRecord(service.getRecordByDate(provider.selectedDate));
|
||||
|
||||
_refreshGoalProcess(provider);
|
||||
}
|
||||
|
||||
void _refreshGoalProcess(HealthProvider provider) {
|
||||
provider.updateLatestWeight(service.getLatestWeight());
|
||||
provider.updateTotalSpot(service.getTotalSport());
|
||||
provider.updateAvgSleep(service.getAvgSleep());
|
||||
}
|
||||
|
||||
Widget _buildRecordTitle(RecordType type) {
|
||||
return Text(
|
||||
type.title,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, color: type.color),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRecordContent(HealthRecord record, RecordType type) {
|
||||
if (!checkHasRecordValue(record, type)) {
|
||||
return Text(
|
||||
"尚未记录今日数据,点击添加",
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
|
||||
);
|
||||
}
|
||||
|
||||
late String title;
|
||||
switch (type) {
|
||||
case RecordType.weight:
|
||||
title = "${record.weight} kg";
|
||||
case RecordType.sport:
|
||||
title = "${record.sportProject} · ${record.sportDuration}分钟";
|
||||
case RecordType.sleep:
|
||||
final startTime = record.sleepStartTime;
|
||||
final endTime = record.sleepEndTime;
|
||||
if (startTime.isNotEmpty && endTime.isNotEmpty) {
|
||||
final duration = calSleepDuration(startTime, endTime);
|
||||
title = "入睡 $startTime · 起床 $endTime · ${duration}";
|
||||
} else if (startTime.isNotEmpty) {
|
||||
title = "入睡 $startTime";
|
||||
} else if (endTime.isNotEmpty) {
|
||||
title = "起床 $endTime";
|
||||
}
|
||||
}
|
||||
|
||||
return Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
);
|
||||
return Text(formatContent(record, type), style: TextStyle(fontSize: 14));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:fitnote/config/app_config.dart';
|
||||
import 'package:fitnote/models/health.dart';
|
||||
import 'package:fitnote/provider/health_provider.dart';
|
||||
import 'package:fitnote/service/health_service.dart';
|
||||
@@ -109,7 +110,7 @@ class _RecordFormState extends State<RecordForm> {
|
||||
SizedBox(width: 10),
|
||||
DropdownSelect(
|
||||
value: provider.formItem.sportProject,
|
||||
items: ['羽毛球', '乒乓球', '篮球', '跑步'],
|
||||
items: AppConfig.sportProjectList,
|
||||
onChanged: (value) => provider.updateSportProject(value!),
|
||||
),
|
||||
],
|
||||
|
||||
68
lib/widget/record/welcome.dart
Normal file
68
lib/widget/record/welcome.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:fitnote/provider/health_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class Welcome extends StatefulWidget {
|
||||
const Welcome({super.key});
|
||||
|
||||
@override
|
||||
State<Welcome> createState() => _WelcomeState();
|
||||
}
|
||||
|
||||
class _WelcomeState extends State<Welcome> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
String _formatCurrentDate() {
|
||||
final now = DateTime.now();
|
||||
return "${DateFormat('yyyy年MM月dd日').format(now)} ${_getWeekday(now.weekday)}";
|
||||
}
|
||||
|
||||
// 数字星期转中文
|
||||
String _getWeekday(int weekday) {
|
||||
const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||
return weekdays[weekday - 1];
|
||||
}
|
||||
|
||||
String getGreeting() {
|
||||
int hour = DateTime.now().hour;
|
||||
|
||||
if (hour >= 5 && hour < 12) {
|
||||
return '早上好';
|
||||
} else if (hour >= 12 && hour < 18) {
|
||||
return '下午好';
|
||||
} else {
|
||||
return '晚上好';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CommonCard(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
getGreeting(),
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'今天是 ${_formatCurrentDate()}',
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user