【问题标题】:The return type 'CupertinoDatePicker' isn't a 'Future<DateTime>', as required by the closure's context根据闭包上下文的要求,返回类型“CupertinoDatePicker”不是“Future<DateTime>”
【发布时间】:2021-07-08 09:11:34
【问题描述】:

我正在尝试为 Android 和 Ios 构建一个自适应日期和时间选择器,

DateTimeField(
    controller: date,
    focusNode: _focusNodeDate,
    validator: (value){
        if(value == null){
            return 'Ce champ est requis';
        };
        return null;
    },
    decoration: InputDecoration(
        labelText: 'Date de naissance',
        labelStyle: TextStyle(
            fontSize: getProportionateScreenWidth(20),
            color: Colors.grey,
        ),
    ),
    format: format,
    onShowPicker: (context, currentValue) {
        if(Platform.isAndroid){
            return showDatePicker(
                context: context,
                firstDate: DateTime(1900),
                initialDate: currentValue ?? DateTime.now(),
                lastDate: DateTime(2100)
            );
        } else if(Platform.isIOS) {
            return CupertinoDatePicker(onDateTimeChanged: (datetime){});
        }
    },
)

我得到了这个错误

错误:返回类型“CupertinoDatePicker”不是 'Future',根据闭包上下文的要求。 (return_of_invalid_type_from_closure at [app_isophro] lib\addProfile\addprofile.dart:232)

【问题讨论】:

    标签: android ios flutter datetime dart


    【解决方案1】:

    您需要将您的小部件CupertinoDatePicker 包装为显示它并返回值的东西,例如:

    showModalBottomSheet<DateTime>(
          context: context,
          builder: (context) => CupertinoDatePicker(onDateTimeChanged: (datetime){}))
    ``
    

    【讨论】:

    猜你喜欢
    • 2021-10-14
    • 2021-06-27
    • 2021-09-18
    • 2020-10-14
    • 2023-02-13
    • 2022-01-12
    • 2021-08-26
    • 2021-10-29
    • 2021-05-04
    相关资源
    最近更新 更多