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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
560
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
160
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
820
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
970
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.7k
Lessons from Spec-Driven Development
simas
PRO
0
240
Agentic UI
manfredsteyer
PRO
0
220
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
320
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.6k
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
160
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
2
490
Featured
See All Featured
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
180
Deep Space Network (abreviated)
tonyrice
0
220
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.6k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
660
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
The untapped power of vector embeddings
frankvandijk
2
1.8k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
410
The SEO identity crisis: Don't let AI make you average
varn
0
510
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
490
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
350
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