title: Saving variables to a file - Flutter
body: <p>I've been looking for a piece of code to save a specified <strong>variable</strong> to a <strong>text file</strong>. Ideally this would work by simply <strong>pressing a button.</strong></p>
  
  <p>This is the code I would like to implement this into, so that on the <strong>far right</strong> of each listview item I can press an icon button and execute the aforementioned code.</p>
  
  <p>If anyone has any ideas on how to achieve this, I would be grateful for any advice.</p>
  
  <pre><code>Widget _cryptoWidget() {
      return new Container(
          child: new Column(
            children: &lt;Widget&gt;[
              new Flexible(
                child: new ListView.builder(
                  itemCount: _currencies.length,
                  itemBuilder: (BuildContext context, int index) {
                    final int i = index ~/ 2;
                    final Crypto currency = _currencies[i];
                    final MaterialColor color = _colors[i % _colors.length];
                    if (index.isOdd) {
                      return new Divider();
                    }
                    return _getListItemUi(currency, color);
                  },
                ),
              )
            ],
          )
        );
    }
  </code></pre>
  
  <p>Thank you for your time.</p>
  
  <p>Edit: </p>
  
  <pre><code>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,
      );
    }
  </code></pre>
  
  <p>Second Edit:</p>
  
  <pre><code>Widget _getSaveValueButton() {
      new IconButton(
      icon: new Icon(Icons.add),
      onPressed: () { Directory appDocDir = await getApplicationDocumentsDirectory();
      String appDocPath = appDocDir.path;
      new File('$appDocPath/my_file.txt').writeAsStringSync('myVar: $_currencies');  
  
    }
  </code></pre>