Share
Embed
[Droidcon EMEA]Effective Flutter Apps Development with Firebase & Tips
It is my presentation file on DroidconEMEA 2020.
#Droidcon
#dcEMEA
#Flutter
#mobile
Kenichi Kambara
October 09, 2020
Transcript
59 slides
-
Effective Flutter Apps Development with Firebase & Tips Kenichi Kambara
(@korodroid) 9 October, 2020 -
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) -
•Introduction •Get Started with Flutter&Firebase •Use Cases & Development Tips
•Development Acceleration Overview -
• Authentication • Cloud Integration • Crash log • and
others… Features mobile developers want -
Firebase Authentication Cloud Firestore Firebase Crashlytics [So many features…]
• Authentication • Cloud Integration • Crash log • and others… Features Firebase provide -
Setup (Step 2/5) •Install Flutter SDK git clone https://github.com/flutter/flutter.git •Install
Flutter & Dart Plugins Example on Android Studio -
•Login to Firebase Console & Create a Firebase Project •https://firebase.google.com/
•Project Settings with Firebase •Register the Android/iOS app (Android:Package nameɺiOS: Bundle ID) •Get a configuration file( : google-services.jsonɺ : GoogleService-Info.plist) •Copy the file ( : into app/androidɺ : into Runner/Runner) ref: https://firebase.google.com/docs/flutter/setup?hl=ja Setup (Step 3/5) -
•Add FlutterFire plugin -> add import (*.dart) Setup (Step
5/5) pubspec.yaml ref: https://firebase.google.com/docs/flutter/setup?#add_flutterfire_plugins 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 -
Use Case 1: Authentication (Firebase Authentication) •Integration with existing account
•Service available without login •Centralized management of User Credials -
Choosing the appropriate plugin for each auth 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 <- Definition in my app [Frontend]Add each Auth Provider plugin -
[Frontend]Google Authentication (e.g.) final FirebaseAuth _auth = FirebaseAuth.instance; final
GoogleSignIn _googleSignIn = GoogleSignIn(); Future<FirebaseUser> 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 _auth.signInWithCredential(credential)).user; return user; } -
Use case 2: Data Management(Cloud Firestore) •Support cloud backup •Support
Android&iOS • Support offline -
[Backend] Collection / Document / Data collection document data
->ToDo Data: m ->ToDo Data: 1 ->Each column for ToDo Data: 1 -
[Backend] Important notice about Collection & Document collection document collection
document document collection document -
[Backend] Data Structure on Cloud Firestore User ID ToDo Data
collection document -
[Frontend] Writing Data (e.g.) Future<void> _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() }); } -
Future<void> _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() }); } [Frontend] Writing Data (e.g.) -
Stream<List<Todo>> _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(); }); } [Frontend] Reading Data (e.g.) -
Stream<List<Todo>> _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(); }); } [Frontend] Reading Data (e.g.) -
[Backend] Rules (Access Control) ྫ ࢦఆ·Ͱ FH 3FBE8SJUF1FSNJTTJPO GPS"VUIPSJ[FE6TFS
FH 3FBE8SJUF1FSNJTTJPO CFGPSFUIFTQFDJpFEEBUF -
class MainPage extends StatelessWidget { @override Widget build(BuildContext context)
{ return Container(); } } e.g. Stateless Widget -
e.g. Stateful Widget class SubPage extends StatefulWidget { @override
_SubPageState createState() => _SubPageState(); } class _SubPageState extends State<SubPage> { @override Widget build(BuildContext context) { return Container(); } } -
class AnimPage extends StatefulWidget { @override _AnimPageState createState() =>
_AnimPageState(); } class _AnimPageState extends State<AnimPage> with SingleTickerProviderStateMixin { AnimationController _controller; @override void initState() { _controller = AnimationController(vsync: this); super.initState(); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Container(); } } e.g. Animation -
Conclusion (about Flutter+Firebase) •One of the most greatest approach on
Cross platform •So many attractive features besides this talk •Can be allocated the extra cost for improving UI/UX -
•Codelabs - Firebase for Flutter https://codelabs.developers.google.com/codelabs/flutter-firebase/ • Firebase Authentication https://firebase.google.com/docs/auth
• Cloud Firestore https://firebase.google.com/docs/firestore Reference -
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