Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Droidcon EMEA]Effective Flutter Apps Development with Firebase & Tips

[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
Tweet

More Decks by Kenichi Kambara

Other Decks in Technology

Transcript

  1. 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) 
  2. • Authentication • Cloud Integration • Crash log • and

    others…  Features mobile developers want
  3. Firebase Authentication Cloud Firestore Firebase Crashlytics [So many features…] 

    • Authentication • Cloud Integration • Crash log • and others… Features Firebase provide
  4. •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)
  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
  6. Use Case 1: Authentication (Firebase Authentication) •Integration with existing account

    •Service available without login •Centralized management of User Credials 
  7. 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
  8. [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; }
  9.  [Backend] Collection / Document / Data collection document data

    ->ToDo Data: m ->ToDo Data: 1 ->Each column for ToDo Data: 1
  10. [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() }); }
  11.  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.)
  12.  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.)
  13.  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.)
  14. e.g. Stateful Widget  class SubPage extends StatefulWidget { @override

    _SubPageState createState() => _SubPageState(); } class _SubPageState extends State<SubPage> { @override Widget build(BuildContext context) { return Container(); } }
  15.  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
  16. 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 
  17. 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