首页 > 解决方案 > 为什么我在颤动中从 FileUtilsDisplayTime() 中获取先前保存的值?

问题描述

我想读取我的时间并传递给我的 toast 函数。但我得到的是以前存储的数字而不是当前值。

这是代码:

String time = '2';

String getTimeForDisplay() {
  FileUtilsDisplayTime().readFromFile().then((String value) {
    time = value;
    print("time from file---" + time);
  });
  return time;
}

void notificationToast() {
  String s = getTimeForDisplay();
  int timeIn = int.parse(s);
  print("time incoming---------" + s);
  Fluttertoast.showToast(
      msg: "------------------------------------------------message---------",
      toastLength: Toast.LENGTH_LONG,
      timeInSecForIos: timeIn,
      gravity: ToastGravity.BOTTOM,
      backgroundColor: Colors.black,
      textColor: Colors.red,
      fontSize: 16.0);
}

传入的时间和来自文件的时间不是相同的值吗?

标签: fileflutterdart

解决方案


推荐阅读