flutter_neat_and_clean_calendar 0.4.5 flutter_neat_and_clean_calendar: ^0.4.5 copied to clipboard
Simple and clean flutter calendar with ability to slide up/down to show weekly/monthly calendar. Fork of https://pub.dev/packages/flutter_clean_calendar
// ignore_for_file: unused_field
import 'package:flutter/material.dart';
import 'package:flutter_neat_and_clean_calendar/flutter_neat_and_clean_calendar.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Clean Calendar Demo',
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system,
home: CalendarScreen(),
localizationsDelegates: [GlobalMaterialLocalizations.delegate],
supportedLocales: [
const Locale('en'),
const Locale('fr'),
const Locale('de'),
const Locale('es'),
const Locale('it'),
const Locale('ru'),
],
);
}
}
class CalendarScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CalendarScreenState();
}
}
class _CalendarScreenState extends State<CalendarScreen> {
bool showEvents = true;
List<NeatCleanCalendarEvent> _todaysEvents = [
NeatCleanCalendarEvent(
'Event A',
startTime: DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day, 10, 0),
endTime: DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day, 12, 0),
description: 'A special event',
color: Colors.blue[700],
),
];
final List<NeatCleanCalendarEvent> _eventList = [
NeatCleanCalendarEvent(
'MultiDay Event A',
description: 'test desc',
startTime: DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day, 10, 0),
endTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day + 2, 12, 0),
color: Colors.orange,
isMultiDay: true,
),
NeatCleanCalendarEvent('Event X',
description: 'test desc',
startTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 10, 30),
endTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 11, 30),
color: Colors.lightGreen,
isAllDay: false,
isDone: true,
icon: 'assets/event1.jpg',
wide: false),
NeatCleanCalendarEvent('Allday Event B',
description: 'test desc',
startTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day - 2, 14, 30),
endTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day + 2, 17, 0),
color: Colors.pink,
isAllDay: true,
icon: 'assets/event1.jpg',
wide: false),
NeatCleanCalendarEvent(
'Normal Event D',
description: 'test desc',
startTime: DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, 14, 30),
endTime: DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day, 17, 0),
color: Colors.indigo,
wide: true,
icon: 'assets/events.jpg',
),
NeatCleanCalendarEvent(
'Normal Event E',
description: 'test desc',
startTime: DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day, 7, 45),
endTime: DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day, 9, 0),
color: Colors.indigo,
wide: true,
icon: 'assets/profile.jpg',
),
];
@override
void initState() {
super.initState();
// Force selection of today on first load, so that the list of today's events gets shown.
_handleNewDate(DateTime(
DateTime.now().year, DateTime.now().month, DateTime.now().day));
}
Widget eventCell(BuildContext context, NeatCleanCalendarEvent event,
String start, String end) {
return Container(
padding: EdgeInsets.all(8.0),
child: Text('Calendar Event: ${event.summary} from $start to $end'));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Calendar(
startOnMonday: true,
weekDays: ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'],
eventsList: _eventList,
isExpandable: true,
// You can set your own event cell builder function to customize the event cells
// Try it by uncommenting the line below
// eventCellBuilder: eventCell,
eventDoneColor: Colors.deepPurple,
selectedColor: Colors.blue,
selectedTodayColor: Colors.green,
todayColor: Colors.teal,
defaultDayColor: Colors.orange,
defaultOutOfMonthDayColor: Colors.grey,
datePickerDarkTheme: ThemeData.dark().copyWith(
colorScheme: ColorScheme.dark(
primary: Colors.blue,
onPrimary: Colors.yellow,
surface: Colors.grey,
onSurface: Colors.yellow,
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Colors.orange,
),
),
),
datePickerLightTheme: ThemeData.dark().copyWith(
colorScheme: ColorScheme.dark(
primary: Colors.blue,
onPrimary: Colors.white,
surface: Colors.white,
onSurface: Colors.teal,
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Colors.orange,
),
),
),
eventColor: null,
locale: 'de_DE',
todayButtonText: 'Heute',
allDayEventText: 'Ganztägig',
multiDayEndText: 'Ende',
isExpanded: true,
expandableDateFormat: 'EEEE, dd. MMMM yyyy',
onEventSelected: (value) {
print('Event selected ${value.summary}');
},
onEventLongPressed: (value) {
print('Event long pressed ${value.summary}');
},
// onMonthChanged: (value) {
// print('Month changed $value');
// },
onDateSelected: (value) {
print('Date selected $value');
},
onRangeSelected: (value) {
print('Range selected ${value.from} - ${value.to}');
},
datePickerType: DatePickerType.date,
dayOfWeekStyle: TextStyle(
color: Colors.red, fontWeight: FontWeight.w800, fontSize: 11),
showEvents: showEvents,
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
showEvents = !showEvents;
});
},
child: Icon(showEvents ? Icons.visibility_off : Icons.visibility),
backgroundColor: Colors.green,
),
);
}
void _handleNewDate(date) {
print('Date selected: $date');
}
}