feat:更新日历组件
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
|
||||
class RecipeCalendar extends StatelessWidget {
|
||||
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();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
@@ -12,11 +22,36 @@ class RecipeCalendar extends StatelessWidget {
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.utc(2010, 10, 16),
|
||||
lastDay: DateTime.utc(2030, 3, 14),
|
||||
focusedDay: DateTime.now(),
|
||||
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;
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// 显示选中的日期
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'选中的日期: ${_selectedDay.year}-${_selectedDay.month}-${_selectedDay.day}',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import 'package:custom_sliding_segmented_control/custom_sliding_segmented_control.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
|
||||
class RecipeSegment extends StatelessWidget {
|
||||
final ViewType selectedViewType;
|
||||
final Function(ViewType) onViewTypeChanged;
|
||||
|
||||
const RecipeSegment({super.key, required this.selectedViewType, required this.onViewTypeChanged});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomSlidingSegmentedControl<int>(
|
||||
initialValue: 1,
|
||||
children: {
|
||||
1: SizedBox(
|
||||
width: 50,
|
||||
child: Text('菜谱', textAlign: TextAlign.center),
|
||||
),
|
||||
2: SizedBox(
|
||||
width: 50,
|
||||
child: Text('日历', textAlign: TextAlign.center),
|
||||
),
|
||||
3: SizedBox(
|
||||
width: 50,
|
||||
child: Text('时间轴', textAlign: TextAlign.center),
|
||||
),
|
||||
},
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.lightBackgroundGray,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
thumbDecoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeInToLinear,
|
||||
onValueChanged: (value) {
|
||||
onViewTypeChanged(ViewType.values[value - 1]);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user