gpt4 book ai didi

android - Flutter 的 'path_provider' 依赖项中的未定义类

转载 作者:IT王子 更新时间:2023-10-29 07:10:08 25 4
gpt4 key购买 nike

添加 path_provider 依赖项后,我遇到了某些类未定义的问题。“目录”和"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';

关于android - Flutter 的 'path_provider' 依赖项中的未定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51404391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com