【发布时间】:2020-04-11 20:27:12
【问题描述】:
从url读取txt文件
var responser = await http.get("https://xxx .com/api.txt");
var puu = responser.body;
int iss = int.parse(puu);
并尝试获取上次保存的内容
SharedPreferences prefs;
String userName = prefs.getString("counter");
然后使用如果之前保存不做任何事情,如果之前没有保存新值则需要运行它
if (userName == iss) {
} else {
prefs.setInt('counter', iss);
Category category = Category();
category.id = puu;
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => FourthRoute(
category: category,
accountLogin: accountLogin,
account: currentAccountProfile)));
}
得到错误
Unhandled Exception: NoSuchMethodError: The method 'getString' was called on null.
Receiver: null
Tried calling: getString("counter")
【问题讨论】: