在添加了path_provider依赖项之后,我遇到了某些未定义类的问题 . “目录”和“文件”未定义,我试图在pubspec.yaml中为我的项目实现path_provider后出现问题 . 这需要在图标按钮上添加字符串到文本文件 .
Imports:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:cryptick/data/crypto_data.dart';
import 'package:cryptick/modules/crypto_presenter.dart';
import 'package:shimmer/shimmer.dart';
import 'dart:async';
import 'package:path_provider/path_provider.dart';
Code in question:
ListTile _getListItemUi(Crypto currency, MaterialColor color) {
return new ListTile(
leading: new Image.network("http://cryptoicons.co/32@2x/color/"+currency.symbol.toLowerCase()+"@2x.png"),
title: new Text(currency.name,
style: new TextStyle(fontWeight: FontWeight.bold)),
subtitle:
_getSubtitleText(currency.price_usd, currency.percent_change_1h),
isThreeLine: true,
trailing: new IconButton(
icon: new Icon(Icons.add),
onPressed: () async { Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
new File('$appDocPath/my_file.txt').writeAsStringSync('myVar: $_currencies');
}
),
);
}
These are the two lines showing the errors:
onPressed: () async { Directory appDocDir = await getApplicationDocumentsDirectory();
And:
new File('$appDocPath/my_file.txt').writeAsStringSync('myVar: $_currencies');
1 回答
导入这个,你很高兴: -