没有为类定义 getter 'Timer'
Posted
技术标签:
【中文标题】没有为类定义 getter \'Timer\'【英文标题】: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
吗?
【参考方案1】:
我在这里找到了解决方案:https://developermemos.com/posts/create-repeating-timer-flutter
必须import 'dart:async';
必须在Timer.periodic()
函数之前添加Timer timer =
。
【讨论】:
以上是关于没有为类定义 getter 'Timer'的主要内容,如果未能解决你的问题,请参考以下文章
错误:没有为类 'Utf8' 定义 getter 'addressOf'
flutter-web: build_runner getter 'typeArguments' 没有为类 'Annotation' 错误定义
错误:没有为类“BuildContext”定义方法“ancestorInheritedElementForWidgetOfExactType”