【发布时间】:2017-05-15 20:39:12
【问题描述】:
问题是这样的:我有一个包含一行文本的 .txt 文件,我需要将该行读入一个字符串变量。
我发现的大多数方法都返回 Future 或 Future,我不知道如何将这些类型转换为字符串。另外,我不确定我在 readAsStringSync 上做错了什么,因为我得到一个“FileSystemExeption:无法打开文件(操作系统错误:没有这样的文件或目录)”,即使我在 pubspec.yaml 中引用了它
class LessonPage extends StatelessWidget { LessonPage({this.title, this.appBarColor, this.barTitleColor, this.fileName});
final String title;
final Color appBarColor;
final Color barTitleColor;
final String fileName;
@override
Widget build(BuildContext context) {
final file = new File(this.fileName);
return new Scaffold(
appBar: new AppBar(
title: new Text(
this.title,
style: new TextStyle(color: this.barTitleColor)
),
backgroundColor: this.appBarColor,
),
body: new Center(
child: new Text(
file.readAsStringSync(),
softWrap: true,
)
),
);
【问题讨论】:
-
能否请您也发布您的 pubspec.yaml 的内容和文件名?
标签: flutter