![](/img/trans.png)
[英]The getter 'DatabaseHelper' isn't defined for the class '_MyCustomFormState'
[英]The getter 'Timer' isn't defined for the class
我按照這個堆棧溢出來以一秒的間隔實現一個計時器操作,並且得到了標題錯誤。 我需要做什么?
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));
我在這里找到了解決方案:https://developermemos.com/posts/create-repeating-timer-flutter
必須import 'dart:async';
必須在Timer.periodic()
function 之前添加Timer timer =
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.