Skip to content

Instantly share code, notes, and snippets.

@horgag1
Created May 25, 2019 12:34
Show Gist options
  • Save horgag1/7caba37e7fd1725c4f7c8930896893cd to your computer and use it in GitHub Desktop.
Save horgag1/7caba37e7fd1725c4f7c8930896893cd to your computer and use it in GitHub Desktop.
calendar carousel
import 'package:flutter/material.dart';
import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart';
import 'package:flutter_calendar_carousel/classes/event.dart';
import 'package:flutter_calendar_carousel/classes/event_list.dart';
class CalendarPage2 extends StatefulWidget {
@override
_CalendarPage2State createState() => new _CalendarPage2State();
}
List<DateTime> presentDates;
class _CalendarPage2State extends State<CalendarPage2> {
static Widget _presentIcon(String day) => Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(1000),
),
),
child: Center(
child: Text(
day,
style: TextStyle(
color: Colors.black,
),
),
),
);
EventList<Event> _markedDateMap = new EventList<Event>(
events: {},
);
CalendarCarousel _calendarCarousel;
double cHeight;
@override
Widget build(BuildContext context) {
cHeight = MediaQuery.of(context).size.height;
_calendarCarousel = CalendarCarousel<Event>(
height: cHeight * 0.70,
weekendTextStyle: TextStyle(
color: Colors.red,
),
todayButtonColor: Colors.blue[200],
markedDatesMap: _markedDateMap,
markedDateShowIcon: true,
//markedDateIconMaxShown: 1,
markedDateMoreShowTotal:
null, // null for not showing hidden events indicator
markedDateIconBuilder: (event) {
return event.icon;
},
);
return new Scaffold(
appBar: new AppBar(
title: new Text("Calender"),
),
body: _calendarCarousel,
);
}
Widget markerRepresent(Color color, String data) {
return new ListTile(
leading: new CircleAvatar(
backgroundColor: color,
radius: cHeight * 0.022,
),
title: new Text(
data,
),
);
}
@override
void initState() {
super.initState();
presentDates = [
DateTime(2019, 5, 28
)];
for (int i = 0; i < presentDates.length; i++) {
print('££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££££');
_markedDateMap.add(
presentDates[i],
new Event(
date: presentDates[i],
title: 'Event 5',
icon: _presentIcon(
presentDates[i].day.toString(),
),
),
);
print(presentDates);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment