无法在SfDateRangePicker日历中选择今天的日期

问题描述 投票:0回答:1

我正在尝试显示从昨天到明天日期的初始日期范围,但今天的日期未突出显示,我尝试更改范围,例如今天到明天,但我单击了它未选择的今天日期。我正在使用名为 SfDateRangePicker 的包。

syncfusion_flutter_datepicker:^22.2.10

下面我提供了屏幕截图和代码

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key,});


  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _datetimeController = DateRangePickerController();

  @override
  Widget build(BuildContext context) {
    DateTime previousDate = DateTime.parse("2024-02-06 20:30:00.000Z");
    DateTime nextDate = DateTime.parse("2024-02-08 21:30:00.000Z");
    DateTime today = DateTime.now();
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text("Calender range"),
      ),
      body: Column(
        children: [
          Text("Today -- $today",
              style: const TextStyle(
              fontFamily: "regular",
              fontSize: 18,
              letterSpacing: 1.5,
              color: Colors.black)),
          Center(
            child: SfDateRangePicker(
              controller: _datetimeController,
              view: DateRangePickerView.month,
              headerStyle: const DateRangePickerHeaderStyle(
                backgroundColor: Colors.white,
                textAlign: TextAlign.left,
                textStyle: TextStyle(
                    fontFamily: "regular",
                    fontSize: 18,
                    letterSpacing: 1.5,
                    color: Colors.black),
              ),
              monthViewSettings: const DateRangePickerMonthViewSettings(
                firstDayOfWeek: 1,
                dayFormat: 'EEE',
                //numberOfWeeksInView: 5,
                viewHeaderStyle: DateRangePickerViewHeaderStyle(
                  textStyle: TextStyle(
                    fontFamily: "semibold",
                    fontSize: 12,
                    letterSpacing: 0.2,
                    color: Color(0xFFC8C9CC),
                  ),
                ),
              ),
              enablePastDates: true,
              minDate: previousDate,
              monthCellStyle: const DateRangePickerMonthCellStyle(
                cellDecoration: BoxDecoration(
                  color: Colors.white,
                ),
                textStyle: TextStyle(
                  color: Colors.black,
                  fontFamily: "bold",
                  fontSize: 14,
                ),
                leadingDatesTextStyle: TextStyle(
                    color: Colors.white,
                    backgroundColor: Colors.white),
                trailingDatesTextStyle: TextStyle(
                  color: Color(0xFFC8C9CC),
                  backgroundColor: Colors.white,
                  fontFamily: "bold",
                  fontSize: 15,
                ),
                todayCellDecoration:
                BoxDecoration(color: Colors.white),
                todayTextStyle: TextStyle(
                  color: Colors.white,
                  fontFamily: "bold",
                  fontSize: 15,
                ),
              ),
              initialSelectedRange: PickerDateRange(previousDate, nextDate),
              selectionMode: DateRangePickerSelectionMode.range,
              selectionTextStyle: const TextStyle(
                color: Colors.white,
                fontFamily: "bold",
                fontSize: 14,
              ),
              selectionColor: Colors.black,
              startRangeSelectionColor: Colors.black,
              endRangeSelectionColor: Colors.black,
              rangeSelectionColor: Colors.black26,
              rangeTextStyle: const TextStyle(
                color: Colors.white,
                fontFamily: "bold",
                fontSize: 14,
              ),
              onSelectionChanged: (DateRangePickerSelectionChangedArgs args) {
                print(args.value);
              },
            ),
          ),
        ],
      ),
    );
  }
}
flutter dart syncfusion date-range syncfusion-calendar
1个回答
0
投票

借助共享代码片段检查查询,我们发现您的开始日期值和结束日期值中有基于时间的值,例如小时和分钟。在这里,我们想让您知道,在 SfDateRangePicker 中,仅根据年、月和日期选择范围。因此,我们要求您删除开始和结束日期时间中的时间值,然后它才能正常工作。我们分享了屏幕截图供您参考。我们希望它能帮助您实现您的要求,如果您有任何进一步疑问,请回复我们。

截图:

© www.soinside.com 2019 - 2024. All rights reserved.