Builders in Flutter Date Range Picker (SfDateRangePicker)

11 Jun 20219 minutes to read

The date range picker allows you to create a responsive UI with the conditions based on a widget’s details, and to design and create your custom view to the month cells and year cells in the date range picker.

Cell builder

The DateRangePickerCellBuilder allows you to design your custom view and assign the view to the month and year view cells of the date range picker by returning an appropriate widget in the cellBuilder of SfDateRangePicker.

DateRangePickerCellDetails: Returns the details of the cell.

date: The date associate with the cell.
bound: Returns the cell bounds.
visibleDates: The visible dates of the current view.

class MyAppState extends State<MyApp> {
  DateRangePickerController _controller = DateRangePickerController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          body: SfDateRangePicker(
              controller: _controller,
			  cellBuilder:
                (BuildContext context, DateRangePickerCellDetails details) {
              final bool isToday = isSameDate(details.date, DateTime.now());
              final bool isBlackOut = isBlackedDate(details.date.day);
              final bool isSpecialDate = isSpecialDay(details.date.day);
              return Container(
                margin: EdgeInsets.all(2),
                padding: EdgeInsets.only(top: kIsWeb ? 5 : 10),
                decoration: BoxDecoration(
                    color: Colors.blueAccent,
                    border: isToday
                        ? Border.all(color: Colors.black, width: 2)
                        : null),
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    Text(
                      details.date.day.toString(),
                      style: TextStyle(
                        fontSize: kIsWeb ? 11 : 15,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    isBlackOut
                        ? Icon(
                            Icons.block_sharp,
                            size: 13,
                          )
                        : isSpecialDate
                            ? Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Icon(
                                    Icons.cake,
                                    size: 13,
                                  ),
                                  Icon(
                                    Icons.celebration,
                                    size: 13,
                                  ),
                                  Icon(
                                    Icons.audiotrack,
                                    size: 13,
                                  )
                                ],
                              )
                            : Container()
                  ],
                ),
              );
            },
              )),
    );
  }
}

Cell builder

NOTE

See also