日历轮播在颤振中给出范围误差

时间:2020-07-22 04:50:23

标签: flutter dart calendar

Calendar Carousel给了我以下错误,它之前可以正常工作。现在它不能正常工作,我已经尝试过抖动和切换频道,但是错误仍然存​​在。

 I/flutter (30661): RangeError (index): Invalid value: Valid value range is empty: 0
    I/flutter (30661): The relevant error-causing widget was:
    I/flutter (30661):   Container 
    lib\date.dart:53
    I/flutter (30661): When the exception was thrown, this was the stack:
    I/flutter (30661): #0      List.[]  (dart:core-patch/growable_array.dart:146:60)
    I/flutter (30661): #1      _CalendarState._setDatesAndWeeks 
    package:flutter_calendar_carousel/flutter_calendar_carousel.dart:836
    I/flutter (30661): #2      _CalendarState._setDate.<anonymous closure> 
    package:flutter_calendar_carousel/flutter_calendar_carousel.dart:854
    I/flutter (30661): #3      State.setState 
    package:flutter/…/widgets/framework.dart:1233
    I/flutter (30661): #4      _CalendarState._setDate 
    package:flutter_calendar_carousel/flutter_calendar_carousel.dart:853
    I/flutter (30661): #5      _CalendarState.initState

这是代码,我尝试过Calendar Carousel示例。它也给我同样的错误。我不知道是什么原因造成的。

class BoxContainer extends StatefulWidget {
  @override
  _BoxContainerState createState() => _BoxContainerState();
}

DateTime _currentDate;

class _BoxContainerState extends State<BoxContainer> {
  @override
  Widget build(BuildContext context) {
    return Container(
    margin: EdgeInsets.symmetric(horizontal: 16.0),
    child: CalendarCarousel<Event>(
      onDayPressed: (DateTime date, List<Event> events) {
        this.setState(() => _currentDate = date);
      },
      weekendTextStyle: TextStyle(
        color: Colors.red,
      ),
      thisMonthDayBorderColor: Colors.grey,
      customDayBuilder: (   
        bool isSelectable,
        int index,
        bool isSelectedDay,
        bool isToday,
        bool isPrevMonthDay,
        TextStyle textStyle,
        bool isNextMonthDay,
        bool isThisMonthDay,
        DateTime day,
      ) {
          
          if (day.day == 15) {
            return Center(
              child: Icon(Icons.local_airport),
            );
          } else {
            return null;
          }
      },
      weekFormat: false,
      markedDatesMap: _markedDateMap,
      height: 420.0,
      selectedDateTime: _currentDate,
      daysHaveCircularBorder: false, 
    ),
  );
}


}

0 个答案:

没有答案