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

时间:2018-07-18 14:18:20

标签: android ios dart flutter flutter-dependencies

添加path_provider依赖项后,我遇到了某些类未定义的问题.``目录''和``文件''未定义,当我尝试在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');  

1 个答案:

答案 0 :(得分:3)

将其导入,您就可以开始:-

abc.properties