import 'package:flutter/material.dart';
import 'package:table_calendar/table_calendar.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
CalendarController _controller;
DateTime _selectedDate;
@override
void initState() {
super.initState();
_controller = CalendarController();
_selectedDate = DateTime.now();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Table Calendar Example'),
),
body: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TableCalendar(
calendarController: _controller,
events: _events,
startingDayOfWeek: StartingDayOfWeek.sunday,
calendarStyle: CalendarStyle(
selectedColor: Colors.deepOrange[400],
todayColor: Colors.deepOrange[200],
markersColor: Colors.deepPurple,
outsideDaysVisible: false,
),
headerStyle: HeaderStyle(
titleTextStyle: TextStyle(
color: Colors.orange,
fontSize: 18,
),
),
),
SizedBox(
height: 50.0,
),
Text(_selectedDate.toString()),
],
),
);
}
Map<DateTime, List<dynamic>> _events;
// Example events
void _generateExampleEvents() {
const int daysBefore = -30;
const int daysAfter = 30;
_events = {};
for (int i = 0; i < (daysBefore + daysAfter + 1); i++) {
final DateTime day = DateTime.now().add(Duration(days: i));
if (day.weekday == DateTime.saturday
评论已关闭