【问题标题】:''00:00'' format in textField (Flutter)文本字段中的“00:00”格式(颤振)
【发布时间】:2020-12-11 05:14:14
【问题描述】:

00:00 format

您好,我想制作一个 Interval Timer 类型的应用程序作为我在 Flutter 中的第一个项目。我现在的问题是我不知道如何使 textField 显示分钟和秒。我尝试像这样使用''flutter_masked_text'':

var controller = new MaskedTextController(mask: '000.000.000-00');

Row(
                         
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Icon(
                              Icons.add
                          ),
                          SizedBox(
                            width: 70.0,
                            height: 25.0,
                            child: TextField(controller: controller,),
                         ),
                      Icon(
                          Icons.remove
                      ),
                    ],
                  )

有点效果,但不是我预期的那样。

【问题讨论】:

    标签: android android-studio flutter flutter-layout


    【解决方案1】:

    将 TextField 小部件替换为以下代码:

    DateTimeField(
                decoration: InputDecoration(
                  contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
                  hintText: "Enter Time",
                  border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0),borderSide: BorderSide(color: Colors.black,width: 2.0))
                ),
                format: _format,
                onShowPicker: (context, currentValue) async {
                  final timed = await showTimePicker(
                    context: context,
                    initialTime: TimeOfDay.fromDateTime(currentValue ?? DateTime.now()),
                  );
                  return DateTimeField.convert(timed);
                },
              ),
    

    并将“_format”定义为状态内部但上下文外部的波纹管:

    final _format = DateFormat("HH-mm");
    

    这应该有帮助。:)

    【讨论】:

    • 我需要为此安装一个库吗?
    • YESS,在您的 pubspec,yaml 文件中添加以下依赖项: datetime_picker_formfield: "1.0.0"
    • 这是 Visual Studio 代码没有保存 pubspec.yaml
    • 我仍然明白这个:The method 'DateFormat' isn't defined for the type '_SetupState'. Try correcting the name to the name of an existing method, or defining a method named 'DateFormat'.
    • 也添加这个:intl: "0.16.1"
    猜你喜欢
    • 2011-06-27
    • 2021-07-05
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 2015-03-11
    • 2014-10-10
    • 1970-01-01
    相关资源
    最近更新 更多