title: How to fix undefined File() class and its methods in Dart?
body: <p>I want to save files in local storage of Android/iOS. I followed the Flutter cookbook to save files but it didn't work. There are examples everywhere using the File class, but it's undefined when I use it. I'm using Dart 2.2.0 and Flutter 1.2.1</p>
  
  <p>I've tried example code snippets from a few websites. Nothing worked. File class, <code>readAsString</code>, and <code>writeAsString</code> are undefined in my Dart file.</p>
  
  <p>Here's the code. Checked it in DartPad. Where am I wrong?</p>
  
  <pre><code>//packages
  import 'dart:io';
  import 'dart:async';
  import 'package:path_provider/path_provider.dart';
  
  //start
  class File {
    /// Directory Path
    /// Local Directory Path
    Future&lt;String&gt; get _localPath async {
      final directory = await getApplicationDocumentsDirectory();
      // For your reference print the AppDoc directory
      print(directory.path);
      return directory.path;
    }
    /// Reference for file Location
    Future&lt;File&gt; get _localFile async {
      final path = await _localPath;
      final address = '$path/data.txt';
      return File(address);
    }
    /// Presenting different Data as 1 String
    String convertingtoString(String title, String author, String content) {
      return '$title\n$author\n\n$content';
    }
    /// Write to file
    /// Writing as String
    Future&lt;File&gt; writeContent(String matter) async {
      /// Get matter converted to string as matter
      final file = await _localFile;
      // Write the file
      return file.writeAsString(matter);
    }
    /// Read from file
    Future&lt;String&gt; readcontent() async {
      try {
        final file = await _localFile;
        // Read the file
        String contents = await file.readAsString();
        return contents;
      } catch (e) {
        // If there is an error reading, return a default String
        return 'Error, Couldn\'t read file';
      }
    }
  }
  
  </code></pre>
  
  <p>This is code from my android flutter project. I get the same errors like DartPad in VScode</p>