【发布时间】:2020-06-04 13:09:26
【问题描述】:
我想从 FLutter 中的 .txt 文件中读取数据,它只包含一个数字。我使用官方文档中的函数(https://flutter.dev/docs/cookbook/persistence/reading-writing-files),当然对它们进行了一些修改以适应我的程序:
class _InClassRoomState extends State<InClassRoom> {
@override
var pontsz = readpontok().toString();
void initState() {
super.initState();
}
Future<String> readpontok() async {
try {
final file = await _localFile;
// Read the file.
String contents = await file.readAsString();
return await contents;
} catch (e) {
// If encountering an error, return 0.
return null;
}
}
我的小部件树的相关部分是 Scaffold 的主体:
body: Center(
child: Text(
pontsz.toString(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 50,
color: Colors.black,
),
),
),
但是当我运行代码时,它只是在脚手架的主体中写入“Future 的实例。为什么?
【问题讨论】:
标签: string file flutter text future