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
ソフトウェアラスタライザ
fadis
1
790
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
360
スマート反転とウェブアクセシビリティ
camiha
0
140
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
120
XHTMLが残したもの
yosuke_furukawa
PRO
2
430
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
170
Family mrubyの進捗
kishima
1
100
Hono + Inertia + React で LP を構築した話
oukayuka
2
220
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
160
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
470
「AI時代、配布するPythonコードをどう守るか: 難読化の実験と判断軸」 #PyconJP2026
pkshadeck
PRO
2
170
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
130
Featured
See All Featured
Statistics for Hackers
jakevdp
799
230k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
Git: the NoSQL Database
bkeepers
PRO
432
67k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Building an army of robots
kneath
306
46k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Building Applications with DynamoDB
mza
96
7.2k
What's in a price? How to price your products and services
michaelherold
247
13k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
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