enter image description here

我需要设计一个日期选取器作为一个列内的小部件包含另一个小部件,而不是弹出日期选取器

有没有人能告诉我怎么把它作为PIC来实现

推荐答案

您可以使用table_calendar或您需要的任何其他自定义小部件:

class CalendarBottomSheet extends StatefulWidget {
  const CalendarBottomSheet({Key key}) : super(key: key);

  @override
  State<CalendarBottomSheet> createState() => _CalendarBottomSheetState();
}

class _CalendarBottomSheetState extends State<CalendarBottomSheet> {
  DateTime _selectedDate;

  @override
  void initState() {
    super.initState();
    _selectedDate = DateTime.now();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var height = MediaQuery.of(context).size.height;
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          child: const Text('Show Calendar'),
          onPressed: () {
            showModalBottomSheet(
              context: context,
              builder: (BuildContext context) {
                return SizedBox(
                  height: height * 0.6,
                  child: Column(
                    children: <Widget>[
                      TableCalendar(
                        firstDay: DateTime(2000),
                        lastDay: DateTime(2050),
                        focusedDay: DateTime.now(),
                        calendarFormat: CalendarFormat.month,
                        calendarStyle: CalendarStyle(
                          selectedDecoration: BoxDecoration(
                            color: Theme.of(context).primaryColor,
                            shape: BoxShape.circle,
                          ),
                          todayDecoration: BoxDecoration(
                            color: Colors.grey[300],
                            shape: BoxShape.circle,
                          ),
                        ),
                        selectedDayPredicate: (date) {
                          return isSameDay(_selectedDate, date);
                        },
                        onDaySelected: (date, focusedDay) {
                          setState(() {
                            _selectedDate = date;
                          });
                          Navigator.pop(context);
                        },
                        calendarBuilders: CalendarBuilders(
                          selectedBuilder: (context, date, _) => Container(
                            decoration: BoxDecoration(
                              color: Theme.of(context).primaryColor,
                              shape: BoxShape.circle,
                            ),
                            child: Center(
                              child: Text(
                                date.day.toString(),
                                style: const TextStyle(color: Colors.white),
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                );
              },
            );
          },
        ),
      ),
    );
  }
}

enter image description here

enter image description here

快乐的编码...

Flutter相关问答推荐

ShaderMask上的文本渐变问题

如何使用Dio/Ffltter(前端)和amp;Go(后端)向API发送正确的请求

悬停时打开Flutter 下拉按钮

为什么Spotify Auth API返回400,而";code_verier不正确?

Flutter飞溅屏幕即使在修改后仍显示默认徽标和背景色

如何在点击查看措辞下方添加句子?

Flutter 附近的连接

在 Flutter 中滑动关闭 PageView.builder 时出现问题

Flutter:我的应用程序是否需要包含退款购买?

如何在列表视图生成器中显示图像

运行任何 flutter 命令都会显示无法安装 <版本>

如何在Flutter中显示ListView Builder区域外的列表数据?

reactive_flutter_BLE - 应用找到设备但无法连接(并读取 BLE 数据)

Flutter:如何从运行时创建的列表中访问单个子部件的值

启动画面中的淡入淡出图像

在 Flutter 中使用 HardwareKeyboard 时所有键都没有响应

Flutter 如何使用 ClipPath 编辑容器的顶部?

无法在 flutter 中更新 void 方法内的变量值

Flutter 如何要求用户在应用程序中设置电话密码?

如何在Flutter 中水平滚动堆叠定位的小部件?