0

添加 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');  
4

1 回答 1

5

导入这个,你很高兴:-

import 'dart:io';
于 2018-07-18T14:41:17.170 回答