簡體   English   中英

沒有為 class 定義吸氣劑“計時器”

[英]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

  1. 必須import 'dart:async';

  2. 必須在Timer.periodic() function 之前添加Timer timer =

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM