【问题标题】:Cannot create a file in flutter无法在颤振中创建文件
【发布时间】:2021-12-08 09:06:12
【问题描述】:

我在下面尝试了这段代码,但我找到了一个空文件夹,仍然无法创建文件,但在终端中没有发现错误。

这是我用过的包:

import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:io';

这是创建文件的代码,有什么问题吗:

Future<String> getFilePath() async {
    
    Directory? appExtDirectory = await getExternalStorageDirectory();
    
    String appExtPath = appExtDirectory.toString();
    
    print('$appExtPath');
    return appExtPath;
  }

  

  Future<File> get _localFile async {
    final path = await getFilePath();
    
    return File('$path/counter.txt');
  }

  Future<File> writeCounter() async {
    final file = await _localFile;

    // Write the file
    return file.writeAsString("This is my demo text that will be saved to : counter.txt");
  }

  void saveFile() {
    writeCounter();
  }

问候..

【问题讨论】:

    标签: flutter filehandle


    【解决方案1】:

    试试String appExtPath = appExtDirectory.path;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-11
      • 2020-09-02
      • 2021-12-13
      • 1970-01-01
      • 2019-03-07
      • 2021-05-08
      相关资源
      最近更新 更多