Skip to content

Instantly share code, notes, and snippets.

@inan-mahmud
Created November 4, 2019 10:27
Show Gist options
  • Save inan-mahmud/dffdc894281dbf9fc4946a511cbb8713 to your computer and use it in GitHub Desktop.
Save inan-mahmud/dffdc894281dbf9fc4946a511cbb8713 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter_calendar_carousel/classes/event.dart';
import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart';
import 'package:hub_food_park/utils/constants.dart';
import 'package:intl/intl.dart';
class FirstScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _FirstScreeState();
}
}
class _FirstScreeState extends State<FirstScreen> {
DateTime _currentDate = DateTime(2019, 2, 3);
String _currentMonth = '';
String monthHeader = '';
CalendarCarousel _calendarCarousel, _calendarCarouselNoHeader;
List<String> monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
@override
Widget build(BuildContext context) {
monthHeader = monthNames[DateTime.now().month - 1] +
' ' +
DateTime.now().year.toString();
_calendarCarousel = CalendarCarousel<Event>(
todayBorderColor: kbottomContainerColor,
onDayPressed: (DateTime date, List<Event> events) {
this.setState(() => _currentDate = date);
events.forEach((event) => print(event.title));
},
/* rightButtonIcon: FlatButton.icon(
onPressed: () {
setState(() {
_currentDate = _currentDate.add(Duration(days: 30));
_currentMonth = DateFormat.yMMM().format(_currentDate);
monthHeader = _currentMonth;
});
},
icon: Icon(
Icons.chevron_right,
color: kbottomContainerColor,
),
label: Text(""),
),
leftButtonIcon: FlatButton.icon(
onPressed: () {
setState(() {
_currentDate = _currentDate.subtract(Duration(days: 30));
_currentMonth = DateFormat.yMMM().format(_currentDate);
monthHeader = _currentMonth;
});
},
icon: Icon(
Icons.chevron_left,
color: kbottomContainerColor,
),
label: Text(""),
),*/
daysHaveCircularBorder: true,
showOnlyCurrentMonthDate: false,
weekendTextStyle: TextStyle(
color: Colors.yellow,
),
thisMonthDayBorderColor: Colors.grey,
weekFormat: false,
// firstDayOfWeek: 4,
height: 360.0,
selectedDateTime: _currentDate,
customGridViewPhysics: NeverScrollableScrollPhysics(),
markedDateCustomShapeBorder:
CircleBorder(side: BorderSide(color: Colors.yellow)),
markedDateCustomTextStyle: TextStyle(
fontSize: 18,
color: Colors.blue,
),
showHeader: true,
headerText: monthHeader,
headerTextStyle: TextStyle(
color: Colors.white,
),
isScrollable: false,
todayTextStyle: TextStyle(
color: Colors.white,
),
todayButtonColor: Colors.yellow,
selectedDayTextStyle: TextStyle(
color: Colors.white,
),
weekdayTextStyle: TextStyle(color: Colors.white),
selectedDayButtonColor: Colors.blue,
selectedDayBorderColor: Colors.blue,
daysTextStyle: TextStyle(
color: Colors.white,
),
minSelectedDate: _currentDate.subtract(Duration(days: 360)),
maxSelectedDate: _currentDate.add(Duration(days: 360)),
prevDaysTextStyle: TextStyle(
fontSize: 16,
color: Colors.white70,
),
nextDaysTextStyle: TextStyle(
fontSize: 16,
color: Colors.white70,
),
inactiveDaysTextStyle: TextStyle(
color: Colors.tealAccent,
fontSize: 16,
),
onCalendarChanged: (DateTime date) {
this.setState(() => _currentMonth = DateFormat.yMMM().format(date));
monthHeader = _currentMonth;
},
onDayLongPressed: (DateTime date) {
print('long pressed date $date');
},
);
// TODO: implement build
return Scaffold(
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
//custom icon
Container(
width: double.infinity,
color: kbottomContainerColor,
margin: EdgeInsets.symmetric(horizontal: 16.0),
child: _calendarCarousel,
),
//
],
),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment