I already implemented codes that disable times between startDate and endDate, but I want to have the reverse version, I mean enable times between startDate and endDate and disable all the other times, here is my codes:
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
class TestFile extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<TestFile> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('SfDataGrid Column Resizing Example')),
body: SfCalendar(
initialDisplayDate: DateTime.now(),
view: CalendarView.week,
specialRegions: _getTimeRegions(),
),
);
}
List<TimeRegion> _getTimeRegions() {
final List<TimeRegion> regions = <TimeRegion>[];
DateTime now = DateTime.now();
DateTime startTime = DateTime(now.year, now.month, now.day, 14, 0, 0);
DateTime endTime = DateTime(now.year, now.month, now.day, 15, 0, 0);
regions.add(TimeRegion(
startTime: startTime,
endTime: endTime,
color: Colors.grey.withOpacity(0.2),
textStyle: TextStyle(color: Colors.black45, fontSize: 15),
recurrenceRule: 'FREQ=DAILY;COUNT=1',
));
return regions;
}
}
2
Answers
You can achieve the same functionality by using the specialRegions property of the TimeRegion class.
Example of how you can use the specialRegions property to disable all timeslots except for the ones that fall between startDate and endDate:
Full example
You can achieve your requirement by using the “specialRegions” support in the Flutter calendar. We have prepared the sample for the same, please find the attached sample and output for the same,
Refer to our UG documentation to know more details about special regions support in the calendar,
https://help.syncfusion.com/flutter/calendar/timeslot-views#special-time-regions
Sample: ` List _getTimeRegions() {
final List regions = [];
}`