mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-26 21:50:48 +08:00
61 lines
1.6 KiB
Dart
61 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:table_calendar/table_calendar.dart';
|
|
|
|
class Calendar extends ConsumerStatefulWidget {
|
|
@override
|
|
ConsumerState<ConsumerStatefulWidget> createState() {
|
|
return _CalendarSate();
|
|
}
|
|
}
|
|
|
|
class _CalendarSate extends ConsumerState<Calendar> {
|
|
DateTime? _selectedDay;
|
|
DateTime _focusedDay = DateTime.now();
|
|
CalendarFormat _calendarFormat = CalendarFormat.month;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TableCalendar(
|
|
locale: "zh_CN",
|
|
firstDay: DateTime.utc(2010, 10, 16),
|
|
lastDay: DateTime.utc(2030, 3, 14),
|
|
focusedDay: _focusedDay,
|
|
selectedDayPredicate: (day) {
|
|
return isSameDay(_selectedDay, day);
|
|
},
|
|
onDaySelected: (selectedDay, focusedDay) {
|
|
setState(() {
|
|
_selectedDay = selectedDay;
|
|
_focusedDay = focusedDay; // update `_focusedDay` here as well
|
|
});
|
|
},
|
|
calendarFormat: _calendarFormat,
|
|
onFormatChanged: (format) {
|
|
setState(() {
|
|
_calendarFormat = format;
|
|
});
|
|
},
|
|
|
|
//locale: "zh_CN",
|
|
//eventLoader: (day) {},
|
|
);
|
|
}
|
|
}
|
|
|
|
showCalendar(BuildContext context) {
|
|
return showDialog<void>(
|
|
context: context,
|
|
barrierDismissible: true,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
//title: Text("资源"),
|
|
content: SizedBox(
|
|
width: MediaQuery.of(context).size.width * 0.7,
|
|
height: MediaQuery.of(context).size.height * 0.6,
|
|
child: Calendar()),
|
|
);
|
|
},
|
|
);
|
|
}
|