cellBuilder property Null safety

DateRangePickerCellBuilder? cellBuilder
final

A builder that builds a widget that replaces the cell in a month, year, decade and century views. The month cell, year cell, decade cell, century cell was differentiated by picker view.

See also:


DateRangePickerController _controller = DateRangePickerController();

@override
void initState() {
 _controller.view = DateRangePickerView.month;
 super.initState();
}

@override
Widget build(BuildContext context) {
  return MaterialApp(
      home: Scaffold(
    appBar: AppBar(
      title: const Text('Date range picker'),
    ),
    body: SfDateRangePicker(
      controller: _controller,
      cellBuilder:
          (BuildContext context, DateRangePickerCellDetails cellDetails) {
        if (_controller.view == DateRangePickerView.month) {
          return Container(
            width: cellDetails.bounds.width,
            height: cellDetails.bounds.height,
            alignment: Alignment.center,
            child: Text(cellDetails.date.day.toString()),
          );
        } else if (_controller.view == DateRangePickerView.year) {
          return Container(
            width: cellDetails.bounds.width,
            height: cellDetails.bounds.height,
            alignment: Alignment.center,
            child: Text(cellDetails.date.month.toString()),
          );
        } else if (_controller.view == DateRangePickerView.decade) {
          return Container(
            width: cellDetails.bounds.width,
            height: cellDetails.bounds.height,
            alignment: Alignment.center,
            child: Text(cellDetails.date.year.toString()),
          );
        } else {
          final int yearValue = (cellDetails.date.year ~/ 10) * 10;
          return Container(
            width: cellDetails.bounds.width,
            height: cellDetails.bounds.height,
            alignment: Alignment.center,
            child: Text(
               yearValue.toString() + ' - ' + (yearValue + 9).toString()),
          );
        }
      },
    ),
  ));
 }

Implementation

final DateRangePickerCellBuilder? cellBuilder;