Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Firebaseでゼロからアプリを作る / Make app from scratch wit...
Search
consomme
August 28, 2018
Programming
2.2k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Firebaseでゼロからアプリを作る / Make app from scratch with Firebase
consomme
August 28, 2018
More Decks by consomme
See All by consomme
LayoutManagerをつくろう
consomme
2
3.1k
Other Decks in Programming
See All in Programming
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
290
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
120
今さら聞けない .NET CLI
htkym
0
160
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
200
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
640
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1.1k
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
0
180
Google Apps Script で Ruby を動かす
kawahara
0
120
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
490
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
840
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
160
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
140
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
1.1k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Code Review Best Practice
trishagee
74
20k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
Paper Plane (Part 1)
katiecoart
PRO
1
9.9k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
190
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
400
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
420
Chasing Engaging Ingredients in Design
codingconduct
0
250
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
240
Transcript
FirebaseͰ θϩ͔ΒΞϓϦΛ࡞Δ Flutter Meetup Tokyo #4 pixiv.inc
@consomme72 / Tadashi Yamazaki
ࣗݾհ ࢁ࡚ ਖ਼ / Tadashi Yamazaki Twitter: @consomme72
ϐΫγϒגࣜձࣾ ΫϦΤΠλʔࣄۀ෦ AndroidΞϓϦΤϯδχΞ
BOOTH ಉਓࢽɺάοζɺ ΞΫηαϦʔͳͲΛ खܰʹൢചͰ͖ΔαʔϏε ※ٕज़ॻଟൢചதʂ
࠷ۙձࣾͰ FlutterΛ͍ͬͯΔͷͰ ݟڞ༗
Flutter x Firebase
https://github.com/flutter/plugins/blob/master/FlutterFire.md
؆қTumblrతΞϓϦΛ࡞Δ
Setup Firebase
͍͍ͩͨެࣜʹॻ͍ͯ͋ΔͷͰ ཁ͚ͩ https://codelabs.developers.google.com/codelabs/flutter-firebase/
https://console.firebase.google.com/
iOS/Android྆ํͷઃఆΛߦ͏
Android ΞϓϦΛొ͢Δࡍʹ σόοάkeystoreͷSHA-1Λొ ʢGoogleAuthͰඞཁʣ
Android google-services.jsonɹΛ appҎԼʹஔ
Android app/build.gradle build.gradle buildscript { … dependencies {
… classpath 'com.google.gms:google-services:3.2.1' … } } apply plugin: 'com.google.gms.google-services'
iOS ී௨ʹόϯυϧIDΛهೖ
iOS $ open ios/Runner.xcworkspace ͰXCodeΛىಈͯ͠ RunnerσΟϨΫτϦʹ GoogleService-Info.plistɹΛஔ
• Firebase AuthenticationʢϢʔβʔೝূʣ • Google AuthenticationʢGoogleೝূʣ • Cloud Firestoreʢσʔλϕʔεʣ •
Cloud Storageʢը૾อଘʣ ࠓճ͏ػೳ
flutter: sdk: flutter # For Firebase firebase_auth: ^0.5.19
google_sign_in: ^3.0.5 cloud_firestore: ^0.7.4 firebase_storage: ^1.0.1 pubspec.yaml
Firebase Authentication
Firebase Console Ͱ ͍͍ͨೝূํࣜΛ ༗ޮʹ͓ͯ͘͠ ࣄલઃఆ
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>com.googleusercontent.apps.${hoge}</string>
</array> </dict> </array> iOS : Info.plist ʹه
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST
1.0//EN" "http://www.apple.com/DTDs/ PropertyList-1.0.dtd"> <plist version="1.0"> <dict> … <key>REVERSED_CLIENT_ID</key> <string>com.googleusercontent.apps.${hoge}</string> … </dict> </plist> GoogleServices-Info.plist ͔Βίϐϖ
class _AuthScreenState extends State<AuthScreen> { final GoogleSignIn _googleSignIn
= new GoogleSignIn( scopes: [ 'email' ] ); final FirebaseAuth _firebaseAuth = FirebaseAuth.instance; Future<FirebaseUser> _signIn() async { GoogleSignInAccount account = await _googleSignIn.signIn(); GoogleSignInAuthentication authentication = await account.authentication; FirebaseUser user = await _firebaseAuth.signInWithGoogle( accessToken: authentication.accessToken, idToken: authentication.idToken, ); return user; }
child: new FlatButton( child: const Text('Sign in'), color:
Colors.blue, textColor: Colors.white, onPressed: () { _signIn() .then((user) { Navigator.pushReplacement(context, new MaterialPageRoute( builder: (context) => new TimelineScreen() )); } ) .catchError((e) => Scaffold.of(context).showSnackBar(new SnackBar( content: new Text(e.toString()), ))); },
Firebase Cloud Storage
Future<void> _send(String body) async { Uri imageUrl; int
time = DateTime.now().millisecondsSinceEpoch; String uuid = Uuid().v4(); if (_image != null) { StorageUploadTask uploadTask = FirebaseStorage.instance .ref() .child('image') .child(uuid + '-' + time.toString()) .putFile(_image); imageUrl = (await uploadTask.future).downloadUrl; } … }
Cloud Firestore
import 'dart:async'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:sampleboard/model/post.dart'; final CollectionReference
postCollection = Firestore.instance.collection('posts'); class FirestoreService { Stream<QuerySnapshot> getPostList() { return postCollection.orderBy('order').snapshots(); } … } FirestoreService::getList
Future<Post> createPost(String body, String image, int order) {
final TransactionHandler handler = (Transaction transaction) async { final DocumentSnapshot snapshot = await transaction.get(postCollection.document()); final Post post = new Post(snapshot.documentID, body, image, order, 0); final Map<String, dynamic> data = post.toMap(); await transaction.set(snapshot.reference, data); return data; }; return Firestore.instance.runTransaction(handler).then((mapData) { return Post.fromMap(mapData); }); } FirestoreService::createPost
Future<dynamic> updatePost(Post post) { final TransactionHandler handler =
(Transaction transaction) async { final DocumentSnapshot snapshot = await transaction.get(postCollection.document(post.id)); await transaction.update(snapshot.reference, post.toMap()); return {'updated': true}; }; return Firestore.instance.runTransaction(handler).then((result) { return result['updated']; }); } FirestoreService::updatePost
StreamSubscription<QuerySnapshot> postSubscription; @override void initState() { super.initState(); _posts
= new List(); postSubscription?.cancel(); postSubscription = db.getPostList().listen((QuerySnapshot snapshot) { List<Post> posts = snapshot.documents.map((snapshot) => Post.fromMap(snapshot.data)).toList(); setState(() { _posts = posts; }); }); } getList
Demo
Tips?
υϝΠϯࢦఆͰ Create flutter create —org ${domain} ※Tips -i
ͰiOSͷݴޠࢦఆ -a ͰAndroidͷݴޠࢦఆ $ flutter create \ --org "net.pixiv.flutter" \ -i swift \ -a kotlin \ pixiv-flutter
Multidex͕ ඞཁ Firebaseͷplugin͕ ΊͬͪΌϝιουଟ͍ͷͰ MultidexͷઃఆͨͿΜඞਢ android { …
defaultConfig { multiDexEnabled true } … }
• αʔόΛ༻ҙ͠ͳ͍͍ͯ͘ͷΞϓϦΤϯδχΞͱָͯ͠ • Plugin͕ἧ͍ͬͯΔͷͰਂ͘ߟ͑ͣʹ࣮Ͱ͖Δ • ઃఆΛΕΔͱϋϚΔͷͰυΩϡϝϯτ͔ͬ͠ΓಡΉ • iOSͱAndroidͰผͷઃఆΛ͢Δ߹ଟ͍ • ΤϥʔϩάͩͱԿ͕͓͔͍͠ͷ͔શવΘ͔Βͳ͍
• ެࣜGithubStackOverflowΛۦ͢Δ ·ͱΊ
• Flutter Firestore example - Firebase Firestore CRUD with ListView
- grokonez • https://grokonez.com/flutter/flutter-firestore-example-firebase-firestore-crud- operations-with-listview • Flutter Institute — Firebase Firestore • https://flutter.institute/firebase-firestore/ References
Thanks! https://github.com/consomme/sample-board-flutter