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
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
Dockerfile CMD for Node.js
grazie1999
0
110
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
710
プロポーザルを書いてもらう
pvcresin
0
560
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.8k
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
120
What's New in Android 2026
veronikapj
0
270
FastAPI の並行処理モデルを完全に理解する
hoto17296
3
820
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
280
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
240
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
5
490
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Faster Mobile Websites
deanohume
310
32k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
540
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
66
57k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
220
Building AI with AI
inesmontani
PRO
1
1.1k
Statistics for Hackers
jakevdp
799
230k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
650
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