{"action":"created","issue":{"url":"https://api.github.com/repos/flutter/flutter/issues/5518","repository_url":"https://api.github.com/repos/flutter/flutter","labels_url":"https://api.github.com/repos/flutter/flutter/issues/5518/labels{/name}","comments_url":"https://api.github.com/repos/flutter/flutter/issues/5518/comments","events_url":"https://api.github.com/repos/flutter/flutter/issues/5518/events","html_url":"https://github.com/flutter/flutter/issues/5518","id":172216452,"number":5518,"title":"Request for richer snippet/example for Reading/Writing files","user":{"login":"sethladd","id":5479,"avatar_url":"https://avatars.githubusercontent.com/u/5479?v=3","gravatar_id":"","url":"https://api.github.com/users/sethladd","html_url":"https://github.com/sethladd","followers_url":"https://api.github.com/users/sethladd/followers","following_url":"https://api.github.com/users/sethladd/following{/other_user}","gists_url":"https://api.github.com/users/sethladd/gists{/gist_id}","starred_url":"https://api.github.com/users/sethladd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethladd/subscriptions","organizations_url":"https://api.github.com/users/sethladd/orgs","repos_url":"https://api.github.com/users/sethladd/repos","events_url":"https://api.github.com/users/sethladd/events{/privacy}","received_events_url":"https://api.github.com/users/sethladd/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/flutter/flutter/labels/%E2%9A%A0%20clear%20documentation","name":"⚠ clear documentation","color":"009800"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-08-19T20:42:40Z","updated_at":"2016-08-22T19:09:44Z","closed_at":null,"body":"Checking out the sample for reading and writing files, I see a call to runApp() twice. That first call isn't very obvious or ergonomic. https://flutter.io/reading-writing-files/\r\n\r\nHave we thought about a more obvious thing to do here? *Must* we initialize the shell this way? Or, can we do \"work\" before runApp in a more obvious way?\r\n\r\nNot sure how common this pattern is, but if we're showing it in docs, it's too easy to cargo cult. Not sure we want developers to use this pattern?\r\n\r\nThanks for any thoughts here."},"comment":{"url":"https://api.github.com/repos/flutter/flutter/issues/comments/241517687","html_url":"https://github.com/flutter/flutter/issues/5518#issuecomment-241517687","issue_url":"https://api.github.com/repos/flutter/flutter/issues/5518","id":241517687,"user":{"login":"collinjackson","id":394889,"avatar_url":"https://avatars.githubusercontent.com/u/394889?v=3","gravatar_id":"","url":"https://api.github.com/users/collinjackson","html_url":"https://github.com/collinjackson","followers_url":"https://api.github.com/users/collinjackson/followers","following_url":"https://api.github.com/users/collinjackson/following{/other_user}","gists_url":"https://api.github.com/users/collinjackson/gists{/gist_id}","starred_url":"https://api.github.com/users/collinjackson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/collinjackson/subscriptions","organizations_url":"https://api.github.com/users/collinjackson/orgs","repos_url":"https://api.github.com/users/collinjackson/repos","events_url":"https://api.github.com/users/collinjackson/events{/privacy}","received_events_url":"https://api.github.com/users/collinjackson/received_events","type":"User","site_admin":false},"created_at":"2016-08-22T19:09:44Z","updated_at":"2016-08-22T19:09:44Z","body":"Here's an example that is exactly like the template starter app except the number of button presses persists across relaunches of the app.\r\n\r\n```\r\nimport 'dart:io';\r\nimport 'dart:async';\r\nimport 'package:flutter/services.dart';\r\nimport 'package:flutter/material.dart';\r\n\r\nvoid main() {\r\n  runApp(\r\n    new MaterialApp(\r\n      title: 'Flutter Demo',\r\n      theme: new ThemeData(\r\n        primarySwatch: Colors.blue,\r\n      ),\r\n      home: new FlutterDemo(),\r\n    ),\r\n  );\r\n}\r\n\r\nclass FlutterDemo extends StatefulWidget {\r\n  FlutterDemo({Key key}) : super(key: key);\r\n\r\n  @override\r\n  _FlutterDemoState createState() => new _FlutterDemoState();\r\n}\r\n\r\nclass _FlutterDemoState extends State<FlutterDemo> {\r\n  int _counter;\r\n\r\n  @override\r\n  void initState() {\r\n    super.initState();\r\n    _readCounter();\r\n  }\r\n\r\n  Future<File> _getLocalFile() async {\r\n    String dir = (await PathProvider.getApplicationDocumentsDirectory()).path;\r\n    String filename = \"$dir/counter.txt\";\r\n    return new File(filename);\r\n  }\r\n\r\n  Future<Null> _readCounter() async {\r\n    try {\r\n      File file = await _getLocalFile();\r\n      String contents = await file.readAsString();\r\n      setState(() {\r\n        _counter = int.parse(contents);\r\n      });\r\n    } on FileSystemException {\r\n      setState(() {\r\n        _counter = 0;\r\n      });\r\n    }\r\n  }\r\n\r\n  void _incrementCounter() {\r\n    setState(() {\r\n      _counter++;\r\n      _getLocalFile().then((File file) {\r\n        file.writeAsStringSync(\"$_counter\");\r\n      });\r\n    });\r\n  }\r\n\r\n  @override\r\n  Widget build(BuildContext context) {\r\n    return new Scaffold(\r\n      appBar: new AppBar(\r\n        title: new Text('Flutter Demo'),\r\n      ),\r\n      body: new Center(\r\n        child: new Text('Button tapped $_counter time${ _counter == 1 ? '' : 's' }.'),\r\n      ),\r\n      floatingActionButton: new FloatingActionButton(\r\n        onPressed: _incrementCounter,\r\n        tooltip: 'Increment',\r\n        child: new Icon(Icons.add),\r\n      ),\r\n    );\r\n  }\r\n}\r\n\r\n```"}}
{"actor":{"display_login":"collinjackson"}}