{"id":698,"date":"2020-04-11T09:42:18","date_gmt":"2020-04-11T00:42:18","guid":{"rendered":"https:\/\/www.typea.info\/blog\/?p=698"},"modified":"2020-04-11T10:00:27","modified_gmt":"2020-04-11T01:00:27","slug":"flutter_cloud_firestore_android","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2020\/04\/11\/flutter_cloud_firestore_android\/","title":{"rendered":"Flutter : Cloud Firestore \u304b\u3089\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u3068\u4fdd\u5b58\u307e\u305aAndroid\u3067\u78ba\u8a8d"},"content":{"rendered":"<p><a href=\"https:\/\/www.amazon.co.jp\/%E5%AE%9F%E8%B7%B5Firestore-%E6%8A%80%E8%A1%93%E3%81%AE%E6%B3%89%E3%82%B7%E3%83%AA%E3%83%BC%E3%82%BA%EF%BC%88NextPublishing%EF%BC%89-%E7%A6%8F%E7%94%B0-%E9%9B%84%E8%B2%B4\/dp\/484437852X\/ref=as_li_ss_il?__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&amp;dchild=1&amp;keywords=Firestore&amp;qid=1586565468&amp;sr=8-1&amp;linkCode=li2&amp;tag=typea09-22&amp;linkId=64227452706e8d6a55ed7360dd0d4c44&amp;language=ja_JP\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"\/\/ws-fe.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=484437852X&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=JP&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=typea09-22&amp;language=ja_JP\" border=\"0\"><\/a><img loading=\"lazy\" decoding=\"async\" style=\"margin: 0px !important; border: currentcolor !important; border-image: none !important !important;\" src=\"https:\/\/ir-jp.amazon-adsystem.com\/e\/ir?t=typea09-22&amp;language=ja_JP&amp;l=li2&amp;o=9&amp;a=484437852X\" alt=\"\" width=\"1\" height=\"1\" border=\"0\"><\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/04\/04\/firebase-hosting-firestore-release\/\">Firebase Hosting \u306b Angular \u3092\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u3057\u3066\u3001\u305d\u3053\u304b\u3089 Firestore \u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u305f<\/a>\u306e\u3067\u3001\u540c\u3058\u3053\u3068\u3092Flutter\u3067\u3082\u5b9f\u73fe\u3059\u308b\u3002<\/p>\n<h2>1.Flutter\u306bFirebase\u3092\u9069\u7528<\/h2>\n<p><a href=\"https:\/\/firebase.google.com\/docs\/flutter\/etup?hl=ja\">https:\/\/firebase.google.com\/docs\/flutter\/etup?hl=ja<\/a><\/p>\n<p>\u3053\u306e\u8fba\u308a\u3092\u53c2\u8003\u306b\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2019\/10\/03\/xamarin_flutter\/\">\u6628\u5e74\u306e10\u6708\u3054\u308d\u306b\u8a2d\u5b9a\u3057\u305f\u3068\u304d\u306b\u306f\u3001\u3044\u308d\u3044\u308d\u30c8\u30e9\u30d6\u30eb\u30b7\u30e5\u30fc\u30c8\u304c\u9762\u5012\u3060\u3063\u305f<\/a>\u6c17\u304c\u3059\u308b\u304c\u3001Flutter\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u3069\u5404\u7a2e\u30c4\u30fc\u30eb\u985e\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u4e0a\u304c\u3063\u3066\u304b\u3001\u304b\u306a\u308a\u3059\u3093\u306a\u308a\u3002<\/p>\n<h2>2.Flutter \u30a2\u30d7\u30ea Firebase \u3068\u7d71\u5408<\/h2>\n<h3>2.1 \u30af\u30a4\u30c3\u30af\u30b9\u30bf\u30fc\u30c8<\/h3>\n<ul>\n<li><a href=\"https:\/\/github.com\/firebase\/quickstart-android\/blob\/master\/firestore\/README.md\">https:\/\/github.com\/firebase\/quickstart-android\/blob\/master\/firestore\/README.md<\/a><\/li>\n<li><a href=\"https:\/\/firebase.google.com\/docs\/firestore\/quickstart\">https:\/\/firebase.google.com\/docs\/firestore\/quickstart<\/a><\/li>\n<\/ul>\n<p>\u3053\u306e\u3042\u305f\u308a\u3092\u53c2\u8003\u306b\u3002<\/p>\n<h3>2.2 FIrestore\u8a2d\u5b9a<\/h3>\n<p>Firestore\u306e\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30fc\u30eb\u30fc\u30eb\u306a\u3069\u306e\u8a2d\u5b9a\u306f\u3001<a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/03\/28\/firebase-hosting-firestore\/\">Firesotre\u306e\u78ba\u8a8d\u3092\u3057\u305f\u6642\u306e\u3082\u306e\u3092\u4f7f\u3044\u307e\u308f\u3059<\/a><\/p>\n<h3>2.3 Firebase\u306bFlutter\u30a2\u30d7\u30ea\u306e\u767b\u9332<\/h3>\n<h4>(1) \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3ID \u306e\u8a2d\u5b9a<\/h4>\n<p><a href=\"https:\/\/developer.android.com\/studio\/build\/application-id?hl=ja\">https:\/\/developer.android.com\/studio\/build\/application-id?hl=ja<\/a><\/p>\n<h4>(2) google.service.json \u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3068Flutter\u30a2\u30d7\u30ea\u3078\u306e\u767b\u9332<\/h4>\n<p>Firebase\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u6982\u8981\u306e\u6b6f\u8eca\u30a2\u30a4\u30b3\u30f3\u304b\u3089\u8a2d\u5b9a\u30da\u30fc\u30b8\u3092\u958b\u304f<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/firebase_settings0.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"firebase_settings0\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/firebase_settings0_thumb.png\" alt=\"firebase_settings0\" width=\"351\" height=\"170\" border=\"0\"><\/a><\/p>\n<p>google.service.json\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firebase_settings.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"flutter_firebase_settings\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firebase_settings_thumb.png\" alt=\"flutter_firebase_settings\" width=\"513\" height=\"258\" border=\"0\"><\/a><\/p>\n<p>Android Studio \u306eFlutter\u30a2\u30d7\u30ea\u306e\u3001android\/app\/ \u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firebase_settings2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"flutter_firebase_settings2\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firebase_settings2_thumb.png\" alt=\"flutter_firebase_settings2\" width=\"433\" height=\"356\" border=\"0\"><\/a><\/p>\n<p>\u30e1\u30cb\u30e5\u30fc Tools &#8211; Flutter \u2013 Flutter Package Get \u3092\u5b9f\u884c<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_package_get.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"flutter_package_get\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_package_get_thumb.png\" alt=\"flutter_package_get\" width=\"506\" height=\"299\" border=\"0\"><\/a><\/p>\n<h2>3.Flutter Fire<\/h2>\n<p>Flutt<a href=\"https:\/\/firebaseopensource.com\/projects\/firebaseextended\/flutterfire\/\">Flutter\u304b\u3089\u3001Firebase\u3092\u4f7f\u3046\u305f\u3081\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u4e00\u89a7<\/a><\/p>\n<p><a href=\"https:\/\/firebaseopensource.com\/projects\/firebaseextended\/flutterfire\/\">https:\/\/firebaseopensource.com\/projects\/firebaseextended\/flutterfire\/<\/a><\/p>\n<p>\u304b\u3089\u3001<\/p>\n<p><a href=\"https:\/\/pub.dev\/packages\/cloud_firestore\">Cloud Firestore plugin for Flutter \u3092\u4f7f\u7528\u3059\u308b\u3002<\/a><\/p>\n<p><a href=\"https:\/\/pub.dev\/packages\/cloud_firestore\">https:\/\/pub.dev\/packages\/cloud_firestore<\/a><\/p>\n<p>Flutter\u3001Firebase\u3001Angular \u3068 Google\u306b\u30ed\u30c3\u30af\u30aa\u30f3\u3055\u308c\u305f\u611f\u306f\u3042\u308b\u304c\u3001Google\u8b39\u88fd\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u540c\u58eb\u306e\u9023\u643a\u306e\u305f\u3081\u3001\u3053\u306e\u3042\u305f\u308a\u306e\u9023\u643a\u30c4\u30fc\u30eb\u304c\u5145\u5b9f\u3057\u3066\u3044\u308b\u306e\u306f\u6357\u308b\u3002<\/p>\n<p>\u3053\u3053\u3067\u3001\u3044\u3063\u305f\u3093\u52d5\u304b\u3057\u3066\u307f\u308b\u3068\u3001multidex \u30a8\u30e9\u30fc\u3068\u3084\u3089\u304c\u767a\u751f\u3059\u308b\u306e\u3067\u3001\u4ee5\u4e0b\u3092\u53c2\u7167\u3057\u3066\u5bfe\u5fdc<\/p>\n<p>64K \u3092\u8d85\u3048\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u30a2\u30d7\u30ea\u5411\u3051\u306b multidex \u3092\u6709\u52b9\u5316\u3059\u308b<\/p>\n<p><a href=\"https:\/\/developer.android.com\/studio\/build\/multidex?hl=ja\">https:\/\/developer.android.com\/studio\/build\/multidex?hl=ja<\/a><\/p>\n<h3>3.1 Cloud Firestore \u30d7\u30e9\u30b0\u30a4\u30f3<\/h3>\n<p><a href=\"https:\/\/pub.dev\/packages\/cloud_firestore\">https:\/\/pub.dev\/packages\/cloud_firestore<\/a><\/p>\n<p>\u3053\u3044\u3064\u3092\u4f7f\u3046\u3002<\/p>\n<h2>4.\u78ba\u8a8d\u5b9f\u88c5<\/h2>\n<p><a href=\"https:\/\/www.typea.info\/blog\/index.php\/2020\/04\/04\/firebase-hosting-firestore-release\/\">Angular\u540c\u69d8\u3001\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u3001Load\u30dc\u30bf\u30f3\u3067Firesotre\u306e\u5024\u3092\u8aad\u307f\u3053\u307f\u3001Save\u3067\u4fdd\u5b58\u3059\u308b<\/a>\u3060\u3051\u3002<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firestore01.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"flutter_firestore01\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firestore01_thumb.png\" alt=\"flutter_firestore01\" width=\"216\" height=\"390\" border=\"0\"><\/a><\/p>\n<h3>4.1 \u8a2d\u5b9a<\/h3>\n<h4>(1) pubspec.yaml<\/h4>\n<ul>\n<li>cloud_firestore \u3092dependencies\u306b\u8ffd\u8a18<\/li>\n<\/ul>\n<pre class=\"prettyprint\">dependencies:\n  flutter:\n    sdk: flutter\n\n  # The following adds the Cupertino Icons font to your application.\n  # Use with the CupertinoIcons class for iOS style icons.\n  cupertino_icons: ^0.1.2\n  cloud_firestore: 0.13.4+2\n<\/pre>\n<h4>(2) \/android\/app\/build.gradle<\/h4>\n<ul>\n<li>\u4e0a\u3067\u8ff0\u3079\u305fmultidex\u306e\u5bfe\u5fdc\u3092dependencies \u306b\u8ffd\u8a18<\/li>\n<li>Google\u30b5\u30fc\u30d3\u30b9\u3092\u5229\u7528\u3059\u308b\u8a18\u8ff0\u3092\u6700\u5f8c\u5c3e\u306b\u8ffd\u8a18<\/li>\n<\/ul>\n<pre class=\"prettyprint\">dependencies {\n    def multidex_version = \"2.0.1\"\n    implementation \"androidx.multidex:multidex:$multidex_version\"\n               :\n}\napply plugin: 'com.google.gms.google-services'  \/\/ Google Play services Gradle plugin\n<\/pre>\n<h4>(3) \/lib\/main.dart<\/h4>\n<pre class=\"prettyprint\">import 'package:flutter\/material.dart';\nimport 'package:cloud_firestore\/cloud_firestore.dart';\n\nvoid main() =&gt; runApp(MyApp());\n\nclass MyApp extends StatelessWidget {\n  final message = \"Initial Message.\";\n  @override\n  Widget build(BuildContext context) {\n    return new MaterialApp(\n      title: 'Flutter Sample',\n      home: MyPage(message:this.message),\n    );\n  }\n}\n\nclass MyPageState extends State&lt;MyPage&gt;{\n  \/\/ \u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30b9\u30c6\u30fc\u30c8\u3092\u7ba1\u7406\n  final _stateController = TextEditingController();\n\n  @override\n  void initState() {\n    super.initState();\n  }\n\n  @override\n  void dispose() {\n    this._stateController.dispose();\n    super.dispose();\n  }\n\n  \/\/\/ Load\u30dc\u30bf\u30f3\u304c\u304a\u3055\u308c\u305f\u3089Firestore\u306e\u5024\u3092\u53d6\u5f97\n  void loadOnPressed() {\n    Firestore.instance.document(\"sample\/sandwichData\")\n        .get().then((DocumentSnapshot ds){\n          setState(() {\n            this._stateController.text = ds[\"hotDogStatus\"];\n          });\n          print(\"status=$this.status\");\n        });\n  }\n\n  \/\/\/ Save\u30dc\u30bf\u30f3\u304c\u304a\u3055\u308c\u305f\u3089Firestore\u306b\u5024\u3092\u4fdd\u5b58\n  void saveOnPressed() {\n    Firestore.instance.document(\"sample\/sandwichData\")\n        .updateData({\"hotDogStatus\":_stateController.text})\n        .then((value) =&gt; print(\"success\"))\n        .catchError((value) =&gt; print(\"error $value\"));\n  }\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        title: Text('Flutter State Sample'),\n      ),\n      body: Column(\n        \/\/ Column\u306e\u914d\u7f6e\u5834\u6240\n        mainAxisAlignment: MainAxisAlignment.start,\n        \/\/ Widget\u306e\u30b5\u30a4\u30ba\n        mainAxisSize: MainAxisSize.max,\n        \/\/\u3000Column\u306b\u7d44\u307f\u8fbc\u3093\u3060Widget\u306e\u914d\u7f6e\u5834\u6240\n        crossAxisAlignment: CrossAxisAlignment.start,\n        children: &lt;Widget&gt;[\n          Row(\n            mainAxisAlignment: MainAxisAlignment.start,\n            mainAxisSize: MainAxisSize.max,\n            crossAxisAlignment: CrossAxisAlignment.start,\n            children: &lt;Widget&gt;[\n              Flexible(\n                child: TextField(\n                  controller: _stateController,\n                ),\n              ),\n              Padding(\n                padding: EdgeInsets.all(2.0),\n                child: RaisedButton(\n                    onPressed: saveOnPressed,\n                    child: Text(\"Save\")),\n              ),\n              Padding(\n                padding: EdgeInsets.all(2.0),\n                child: RaisedButton(\n                    onPressed: loadOnPressed,\n                    child: Text(\"Load\"))\n              )\n            ],\n          ),\n        ],\n      ),\n    );\n  }\n}\n\nclass MyPage extends StatefulWidget {\n  final String message;\n  MyPage({this.message}):super() {}\n  @override\n  State&lt;StatefulWidget&gt; createState() =&gt; new MyPageState();\n}<\/pre>\n<h2>5.\u78ba\u8a8d<\/h2>\n<p>Firestore\u306e\u5024<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/firestore_before.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"firestore_before\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/firestore_before_thumb.png\" alt=\"firestore_before\" width=\"438\" height=\"163\" border=\"0\"><\/a><\/p>\n<p>Load\u30dc\u30bf\u30f3\u3067\u3001Firestore\u306e\u5024\u3092\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u8aad\u307f\u8fbc\u307fOK<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firestore02.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"flutter_firestore02\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firestore02_thumb.png\" alt=\"flutter_firestore02\" width=\"431\" height=\"218\" border=\"0\"><\/a><\/p>\n<p>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u9069\u5f53\u306b\u5909\u66f4\u3057Save\u30dc\u30bf\u30f3\u3092\u62bc\u4e0b<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firestore03.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"flutter_firestore03\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/flutter_firestore03_thumb.png\" alt=\"flutter_firestore03\" width=\"438\" height=\"245\" border=\"0\"><\/a><\/p>\n<p>Firestore\u306e\u5024\u304c\u66f4\u65b0\u3055\u308c\u305fOK\uff01<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/firestore_after.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"firestore_after\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/2020\/04\/firestore_after_thumb.png\" alt=\"firestore_after\" width=\"440\" height=\"122\" border=\"0\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Firebase Hosting \u306b Angular \u3092\u30db\u30b9\u30c6\u30a3\u30f3\u30b0\u3057\u3066\u3001\u305d\u3053\u304b\u3089 Firestore \u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u305f\u306e\u3067\u3001\u540c\u3058\u3053\u3068\u3092Flutter\u3067\u3082\u5b9f\u73fe\u3059\u308b\u3002 1.Flutter\u306bFirebase\u3092\u9069\u7528 https [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[104,111],"tags":[],"class_list":["post-698","post","type-post","status-publish","format-standard","hentry","category-firebase","category-flutter"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=698"}],"version-history":[{"count":4,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/698\/revisions"}],"predecessor-version":[{"id":702,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/698\/revisions\/702"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}