title: Text file is not being created in flutter
body: <p>Im trying to create a way to add a list of favourite names. When I submit a name it will update a list. then when i press save it should write the list to a text file. but when i run it i get the error <em>(OS Error: No such file or directory, errno = 2)</em></p>
  <p>How do i create the missing text file?</p>
  <p>I cannot locate the file path in my demo device either. the code is given below ..</p>
  <pre><code>import 'dart:io';
  
  import 'package:appoint/navigationDrawer/navigationDrawer.dart';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'package:path_provider/path_provider.dart';
  
  TextEditingController FavController = TextEditingController();
  List&lt;String&gt; Favs = [];
  
  TextEditingController TAController = TextEditingController();
  
  class Favourite extends StatefulWidget {
    static const String routeName = '/Favourite';
    const Favourite({Key? key}) : super(key: key);
  
    @override
    _FavouriteState createState() =&gt; _FavouriteState();
  }
  
  class _FavouriteState extends State&lt;Favourite&gt; {
    List _content = [];
  
    Future&lt;String&gt; _getDirPath() async {
      final _dir = await getApplicationDocumentsDirectory();
      return _dir.path;
    }
  
    Future&lt;File&gt; get _localfile async {
      final path = await _getDirPath();
      return File (&quot;$path/favs.txt&quot;);
    }
  
    Future&lt;void&gt; _readData() async {
      final file = await _localfile;
      String _data = await file.readAsString();
      setState(() {
        _content = [];
        _content.add(_data);
      });
    }
  
    Future&lt;void&gt; _writeData(pass) async {
      final _dirPath = await _getDirPath();
      final _myFile = File('$_dirPath/data.txt');
      await _myFile.writeAsString('\n' + '$pass');
    }
  
  
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Add Favourites',style: TextStyle(fontSize: 20.0, color: Colors.orange)),
        ),
        drawer: navigationDrawer(),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.only(right: 8.0, left: 8.0),
            child: Column(
              children: [
  
                Padding(
                  padding: const EdgeInsets.only(bottom: 30.0, top: 10.0),
                  child: TextField(
                    decoration: InputDecoration(border: OutlineInputBorder(), hintText: 'Enter New Favourite Name'),
                    controller: FavController,
                    onSubmitted: (text){
                      _readData();
                      print (_content);
                      Favs.add(text);
                      FavController.clear();
                      setState(() {
  
                      });
                    },
                  ),
                ),
  
  
  
                //addfields
  
                Container(
                  child: ListView.builder(
                      physics: ClampingScrollPhysics(),
                      shrinkWrap: true,
                      itemCount: Favs.length,
                      itemBuilder: (BuildContext ctxt, int index) {
                        return Container(
                          decoration: BoxDecoration(border: Border.all(color: Colors.white54), borderRadius: BorderRadius.all(Radius.circular(8.0))),
                          child: Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '$index . ' + Favs[index],
                                  style: TextStyle(fontSize: 20.0),),
                                IconButton(
                                    onPressed: (){
                                  Favs.remove(Favs[index]);
                                  setState(() {});
                                },
                                  tooltip: 'Clear name',
  
                                    icon: Icon(Icons.clear, color: Colors.red,),
                                ),
                              ],
                            ),
                          ),
                        );
                      }
                  ),
                ),
  
                RaisedButton(
                  child: Text ('Save'),
                    onPressed: (){
                      for (String i in Favs) {
                        _writeData(i);
                      }
  
                    }
                ),
  
              ],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>