115 lines
3.0 KiB
Dart
115 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:food_hub_app/utils/index.dart';
|
|
import 'package:table_calendar/table_calendar.dart';
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
|
|
class RecipeCalendar extends StatefulWidget {
|
|
const RecipeCalendar({super.key});
|
|
|
|
@override
|
|
State<RecipeCalendar> createState() => _RecipeCalendarState();
|
|
}
|
|
|
|
class _RecipeCalendarState extends State<RecipeCalendar> {
|
|
DateTime _selectedDay = DateTime.now();
|
|
DateTime _focusedDay = DateTime.now();
|
|
|
|
|
|
|
|
TableCalendar recipeCalendar() {
|
|
return TableCalendar(
|
|
locale: 'zh_CN',
|
|
headerStyle: const HeaderStyle(
|
|
formatButtonVisible: false,
|
|
titleCentered: true,
|
|
),
|
|
firstDay: DateTime.utc(2010, 1, 1),
|
|
lastDay: DateTime.utc(2100, 12, 31),
|
|
focusedDay: _focusedDay,
|
|
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
|
onDaySelected: (selectedDay, focusedDay) {
|
|
if (!isSameDay(_selectedDay, selectedDay)) {
|
|
setState(() {
|
|
_selectedDay = selectedDay;
|
|
_focusedDay = focusedDay;
|
|
});
|
|
}
|
|
},
|
|
onPageChanged: (focusedDay) {
|
|
print("cxx");
|
|
_focusedDay = focusedDay;
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget dailyItem() {
|
|
return Card(
|
|
elevation: 0,
|
|
color: Colors.white,
|
|
child: Padding(
|
|
padding: EdgeInsets.all(5),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(formatDateTime(_selectedDay, 'MM月dd日 EEEE')),
|
|
recipeRecordItem(),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget recipeRecordItem() {
|
|
return Card(
|
|
elevation: 0,
|
|
color: Colors.limeAccent.shade100,
|
|
child: Padding(
|
|
padding: EdgeInsets.all(10),
|
|
child: Row(
|
|
children: [
|
|
TDAvatar(
|
|
size: TDAvatarSize.medium,
|
|
type: TDAvatarType.customText,
|
|
text: 'A',
|
|
),
|
|
SizedBox(width: 10),
|
|
Expanded(
|
|
// 使用Expanded让文本区域占据剩余空间
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"青椒土豆丝",
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
SizedBox(height: 5),
|
|
Text("家常菜", style: TextStyle(color: Colors.grey)),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(width: 10),
|
|
TDButton(
|
|
icon: TDIcons.arrow_right,
|
|
type: TDButtonType.fill,
|
|
shape: TDButtonShape.circle,
|
|
theme: TDButtonTheme.primary,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
Card(elevation: 0, color: Colors.white, child: recipeCalendar()),
|
|
const SizedBox(height: 10),
|
|
dailyItem(),
|
|
],
|
|
);
|
|
}
|
|
}
|