Slide 1

Slide 1 text

ʲOnlineʳFlutter Meetup 2020.07.14 ਆݪ ݈Ұ (@korodroid) FlutterͰFirebaseͷػೳΛ׆༻͠Α͏

Slide 2

Slide 2 text

About me •Mobile App Development •Speeches (e.g. 8 International confs.) •Writings (e.g. 5 Dev Books) •[Official] Evangelist at NTT TechnoCross •[Private] iplatform.org Kenichi Kambara (@korodroid)

Slide 3

Slide 3 text

•Firebaseͷศརػೳ •Flutter+Firebaseͷ͸͡Ίํ •[ຊ୊]Ϣʔεέʔεʴ։ൃTips •࠷৽τϐοΫ Introduction

Slide 4

Slide 4 text

mBaaS = mobile Backend as a Service GoogleӡӦͷmBaaS

Slide 5

Slide 5 text

What’s Firebase? ※ग़య: FirebaseެࣜαΠτ(Ҏ߱εϥΠυ΋ಉ༷)

Slide 6

Slide 6 text

• ೝূ • Ϋϥ΢υ࿈ܞ • Ϋϥογϡϩά • සग़ػೳͷ։ൃޮ཰޲্ Firebase Authentication Cloud Firestore Firebase Crashlytics [So many features…] ϞόΠϧ։ൃऀ͔ΒݟͨFirebaseͷศརػೳ

Slide 7

Slide 7 text

[ೝূ]Firebase Authentication ෳࡶͳೝূॲཧΛόοΫΤϯυͱ؆୯ʹ౷߹Մೳ

Slide 8

Slide 8 text

[Ϋϥ΢υ࿈ܞ]Cloud Firestore খճΓͷར͘Ϋϥ΢υσʔλϕʔε(NoSQL)

Slide 9

Slide 9 text

[Ϋϥογϡϩά]Firebase Crashlytics ϦΞϧλΠϜͷΫϥογϡϨϙʔτπʔϧ

Slide 10

Slide 10 text

Flutter+Firebaseͷ͸͡Ίํ

Slide 11

Slide 11 text

؀ڥߏங •Step1. FlutterΞϓϦͷ։ൃ؀ڥ(IDE or ΤσΟλ౳) •Step2. FirebaseϩάΠϯ&ϓϩδΣΫτ࡞੒(Webϒϥ΢β) •https://firebase.google.com/ •Step3. FirebaseͷϓϩδΣΫτઃఆ •Android/iOSΞϓϦͷొ࿥(Android:ύοέʔδ໊ɺiOS: όϯυϧID) •ߏ੒ϑΝΠϧͷऔಘ( : google-services.jsonɺ : GoogleService-Info.plist) •↑ϑΝΠϧͷ഑ஔ( : app/android഑Լ΁ɺ : Runner/Runner഑Լ΁) •ৄࡉ͸ͪ͜Β: https://firebase.google.com/docs/flutter/setup?hl=ja

Slide 12

Slide 12 text

•Step4. Firebase؀ڥઃఆ(ར༻͢Δػೳʹ߹Θͤͯ) ؀ڥߏங Firebase Authentication Cloud Firestore

Slide 13

Slide 13 text

•Step5. FlutterFireϓϥάΠϯͷ௥Ճˠimport௥Ճ(*.dart) ؀ڥߏங dependencies: flutter: sdk: flutter # Firebase Core firebase_core: ^0.4.5 # e.g. Firebase Authentication firebase_auth: ^0.16.1 # e.g. Cloud Firestore cloud_firestore: ^0.13.7 pubspec.yaml

Slide 14

Slide 14 text

[Tips]FlutterFire https://firebaseopensource.com/projects/firebaseextended/flutterfire/ όʔδϣϯ৘ใˍϓϥοτϑΥʔϜରԠঢ়گ

Slide 15

Slide 15 text

Flutter+FirebaseͷϢʔεέʔεɾ։ൃTips

Slide 16

Slide 16 text

ToDo؅ཧΞϓϦ

Slide 17

Slide 17 text

Ϣʔεέʔεᶃೝূ(Authentication) •طଘΞΧ΢ϯτ࿈ܞΛ༰қʹ࣮ݱ •ϩάΠϯͳ͠Ͱ΋ར༻Մೳʹ •ೝূ৘ใΛҰݩ؅ཧ͍ͨ͠

Slide 18

Slide 18 text

Frontend / Backend

Slide 19

Slide 19 text

ೝূϓϩόΠμຖʹ࠷దͳϓϥάΠϯΛબఆ dependencies: # Firebase Authentication firebase_auth: ^0.15.5+3 # for Google Signed-In google_sign_in: ^4.2.0 # for Facebook Authentication flutter_facebook_login: ^3.0.0 # for Twitter Authentication flutter_twitter_login: ^1.1.0 # for Apple Authentication apple_sign_in: ^0.1.0 pubspec.yaml ↑ࣗ෼͕࢖͍ͬͯΔ΋ͷ [Frontend]ඞཁͳೝূϓϩόΠμͷϓϥάΠϯ௥Ճ

Slide 20

Slide 20 text

[Frontend]Firebase+Googleೝূ(ྫ) final FirebaseAuth _firebaseAuth = FirebaseAuth.instance; final GoogleSignIn _googleSignIn = GoogleSignIn(); Future _signInWithGoogle() async { final GoogleSignInAccount googleUser = await _googleSignIn.signIn(); final GoogleSignInAuthentication googleAuth = await googleUser.authentication; final AuthCredential credential = GoogleAuthProvider.getCredential( idToken: googleAuth.idToken, accessToken: googleAuth.accessToken, ); final FirebaseUser user = (await _firebaseAuth.signInWithCredential(credential)).user; return user; }

Slide 21

Slide 21 text

[Tips][Backend]ೝূઃఆ ɹূ໌ॻϑΟϯΨʔϓϦϯτొ࿥ σόοά༻ɾϦϦʔε༻

Slide 22

Slide 22 text

Ϣʔεέʔεᶄσʔλ؅ཧ(Cloud Firestore) •Ϋϥ΢υόοΫΞοϓʹରԠ͍ͨ͠ •Android/iOS྆ରԠʹ͍ͨ͠ • ΦϑϥΠϯͰ΋࢖͍͍ͨ

Slide 23

Slide 23 text

Frontend / Backend

Slide 24

Slide 24 text

[Backend] σʔλߏ଄ͷઃܭ ϢʔβID ToDoσʔλ

Slide 25

Slide 25 text

[Backend] σʔλߏ଄ྫ

Slide 26

Slide 26 text

[Backend] collection / document / data collection document data →ྫ)ToDoσʔλn݅ →ྫ)ToDoσʔλ಺ͷϑΟʔϧυ →ྫ)ToDoσʔλ1݅

Slide 27

Slide 27 text

[Backend] collection / documentͷ஫ҙ఺ collection document collection document document collection document

Slide 28

Slide 28 text

[Backend] Firestore಺Ͱͷߏ଄(ྫ) ϢʔβID collection document ToDoσʔλ

Slide 29

Slide 29 text

[Frontend] σʔλWrite(ྫ) Future _updateData(Todo todo, String userId) { return Firestore.instance .collection(COLLECTION_USERS_GROUP) .document(userId) .collection(COLLECTION_USERS_DATA) .document() .setData({ COLUMN_ICON_ID: todo.iconId, COLUMN_NOTIFICATION_ID: todo.notificationId, COLUMN_TITLE: todo.title, COLUMN_CONTENT: todo.content, COLUMN_DATE: todo.date, COLUMN_ISSTARRED: todo.isStarred, COLUMN_ISDONE: todo.isDone, COLUMN_ISREMIND: todo.isRemind, COLUMN_CREATEDAT: FieldValue.serverTimestamp() }); }

Slide 30

Slide 30 text

[Frontend] σʔλWrite(ྫ) Future _updateData(Todo todo, String userId) { return Firestore.instance .collection(COLLECTION_USERS_GROUP) .document(userId) .collection(COLLECTION_USERS_DATA) .document() .setData({ COLUMN_ICON_ID: todo.iconId, COLUMN_NOTIFICATION_ID: todo.notificationId, COLUMN_TITLE: todo.title, COLUMN_CONTENT: todo.content, COLUMN_DATE: todo.date, COLUMN_ISSTARRED: todo.isStarred, COLUMN_ISDONE: todo.isDone, COLUMN_ISREMIND: todo.isRemind, COLUMN_CREATEDAT: FieldValue.serverTimestamp() }); }

Slide 31

Slide 31 text

[Frontend] σʔλRead(ྫ) Stream> _fetchData(String userId) { return Firestore.instance .collection(COLLECTION_USERS_GROUP) .document(userId) .collection(COLLECTION_USERS_DATA) .snapshots() .map((snapshot) { return snapshot.documents.map((docs) { return Todo( id: docs.documentID, iconId: docs.data[COLUMN_ICON_ID], notificationId: docs.data[COLUMN_NOTIFICATION_ID], title: docs.data[COLUMN_TITLE], content: docs.data[COLUMN_CONTENT], date: calculateDate(docs.data[COLUMN_DATE]), isStarred: docs.data[COLUMN_ISSTARRED], isDone: docs.data[COLUMN_ISDONE], isRemind: docs.data[COLUMN_ISREMIND], ); }).toList(); }); }

Slide 32

Slide 32 text

[Frontend] σʔλRead(ྫ) Stream> _fetchData(String userId) { return Firestore.instance .collection(COLLECTION_USERS_GROUP) .document(userId) .collection(COLLECTION_USERS_DATA) .snapshots() .map((snapshot) { return snapshot.documents.map((docs) { return Todo( id: docs.documentID, iconId: docs.data[COLUMN_ICON_ID], notificationId: docs.data[COLUMN_NOTIFICATION_ID], title: docs.data[COLUMN_TITLE], content: docs.data[COLUMN_CONTENT], date: calculateDate(docs.data[COLUMN_DATE]), isStarred: docs.data[COLUMN_ISSTARRED], isDone: docs.data[COLUMN_ISDONE], isRemind: docs.data[COLUMN_ISREMIND], ); }).toList(); }); }

Slide 33

Slide 33 text

[Tips][Backend] ϧʔϧઃఆ(ΞΫηε੍ޚ) ͋͘·Ͱྫ ೝূϢʔβͷΈSFBEXSJUFڐՄ ※ʮRule Playgroundʯ΋ಈ࡞γϛϡϨʔγϣϯʹ͓͢͢Ί

Slide 34

Slide 34 text

[Frontend] ΦϑϥΠϯରԠ Frontend Backend NoSQL Database ΦϑϥΠϯૢ࡞Մ ࣗಈಉظ

Slide 35

Slide 35 text

࠷৽τϐοΫ: Cloud Firestore %FW൛ /PU4UBCMF൛ ϦϦʔε #SFBLJOH$IBOHFT΋͋Γ ຯݟΛ࢝ΊΔ͘Β͍͕͓͢͢Ί

Slide 36

Slide 36 text

Conclusion (about Flutter+Firebase) •ΫϩεϓϥοτϑΥʔϜରԠͷ࠷ڧ૊Έ߹Θͤͷ̍ͭ •ࠓճ঺հͨ͠΋ͷҎ֎ʹ΋ັྗతͳػೳ͕ଟ਺ •Firebase׆༻Ͱු͍ͨ޻਺ΛUI/UXͳͲʹׂΓ౰ͯՄೳ

Slide 37

Slide 37 text

•[ຊൃදͷBackendࢹ఺ͷൃදεϥΠυ] Firebase Realtime Meetup https://bit.ly/3iNEDzD •[͓͢͢Ί]Codelabs - Firebase for Flutter https://codelabs.developers.google.com/codelabs/flutter-firebase/ Reference

Slide 38

Slide 38 text

Please let me know if you have any requests such as technical speeches, technical writings and so on. Facebook:http://fb.com/kanbara.kenichi Twitter:@korodroid LinkedIn:http://www.linkedin.com/in/korodroid Thank you so much