【问题标题】:The getter 'Timer' isn't defined for the class没有为类定义 getter 'Timer'
【发布时间】:2020-12-01 09:58:04
【问题描述】:

我正在关注this stack-overflow 以一秒为间隔实现计时器操作,并收到标题错误。我该怎么办?

  floatingActionButton: FloatingActionButton(
    child: Icon(Icons.add),
    onPressed: () async {
      Timer.periodic(Duration(seconds:1), (Timer t) => print(t));
    }
  );

错误:

lib/main.dart:182:48: Error: 'Timer' isn't a type.                      
      Timer.periodic(Duration(seconds:1), (Timer t) => print(t));   
                                           ^^^^^                    
lib/main.dart:182:11: Error: The getter 'Timer' isn't defined for the class '_UploadPageState'.
 - '_UploadPageState' is from 'package:decg_main/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Timer'.
          Timer.periodic(Duration(seconds:1), (Timer t) => print(t)); 

【问题讨论】:

  • 你也可以分享_UploadPageState吗?

标签: flutter


【解决方案1】:

我在这里找到了解决方案:https://developermemos.com/posts/create-repeating-timer-flutter

  1. 必须import 'dart:async';

  2. 必须在Timer.periodic() 函数之前添加Timer timer =

【讨论】:

    猜你喜欢
    • 2021-11-22
    • 2020-08-08
    • 2021-06-08
    • 2021-04-28
    • 1970-01-01
    • 2021-07-27
    • 2020-09-02
    • 2021-07-23
    • 1970-01-01
    相关资源
    最近更新 更多