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
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
350
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
210
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.6k
Swiftのレキシカルスコープ管理
kntkymt
0
220
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
4.9k
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
160
JavaDoc 再入門
nagise
0
320
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.2k
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
230
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
390
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
120
CSC307 Lecture 17
javiergs
PRO
0
320
Featured
See All Featured
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
570
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
150
Building AI with AI
inesmontani
PRO
1
1.1k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Automating Front-end Workflow
addyosmani
1370
210k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
Writing Fast Ruby
sferik
630
63k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
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