Flutter 的 'path_provider' 依赖项中未定义 class
Undefined class in 'path_provider' dependency for Flutter
添加 path_provider 依赖项后,我 运行 遇到了某些 类 未定义的问题。'Directory' 和 'File' 未定义,问题在我尝试在 pubspec.yaml 中对我的项目实施 path_provider 之后发生。这是在按下图标按钮时将字符串添加到文本文件所必需的。
进口:
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';
有问题的代码:
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');
}
),
);
}
这些是显示错误的两行:
onPressed: () async { Directory appDocDir = await getApplicationDocumentsDirectory();
和:
new File('$appDocPath/my_file.txt').writeAsStringSync('myVar: $_currencies');
导入这个就可以了:-
import 'dart:io';
添加 path_provider 依赖项后,我 运行 遇到了某些 类 未定义的问题。'Directory' 和 'File' 未定义,问题在我尝试在 pubspec.yaml 中对我的项目实施 path_provider 之后发生。这是在按下图标按钮时将字符串添加到文本文件所必需的。
进口:
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';
有问题的代码:
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');
}
),
);
}
这些是显示错误的两行:
onPressed: () async { Directory appDocDir = await getApplicationDocumentsDirectory();
和:
new File('$appDocPath/my_file.txt').writeAsStringSync('myVar: $_currencies');
导入这个就可以了:-
import 'dart:io';