我已经实现了禁用startDate和endDate之间的时间的代码,但我希望有相反的版本,我的意思是启用startDate和endDate之间的时间,并禁用所有其他时间,以下是我的代码:
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;
}
}
1条答案
按热度按时间ljsrvy3e1#
可以使用TimeRegion类的specialRegions属性实现相同的功能。
如何使用specialRegions属性禁用除startDate和endDate之间的时隙以外的所有时隙的示例:
完整示例