Unlock the Power of Firebase Extensions

Majid Hajian

mhadaily

Darren

Majid Hajian

mhadaily

import 'package:flutter/material.dart';
MaterialApp(
   ThemeData(
        name: "Majid Hajian",
        location: "Oslo, Norway",
        description: '''
                Google Developer Expert
        	Passionate Software engineer, 
	        Community Leader, Author and international Speaker
         ''',
        main: "Head of DevRel at Invertase.io",
        homepage: "https://www.majidhajian.com",
        socials: {
          twitter: "https://www.twitter.com/mhadaily",
          github: "https://www.github.com/mhadaily"
        },
        author: {
          Pluralsight: "www.pluralsight.com/authors/majid-hajian",
          Apress: "Progressive Web App with Angular, Book",
          PacktPub: "PWA development",
          Udemy: "PWA development",
        }
        founder: "Softiware As (www.Softiware.com)"
        devDependencies: {
          tea: "Ginger", 
          mac: "10.14+",
        },
        community: {
          FlutterVikings: "Orginizer", 
          FlutterCommunity: "Admin/Lead",
          ...more
        },
        ),
       );

mhadaily

Find me on the internet by

Head of DevRel at Invertase

Majid Hajian

flutter create geek_photos


flutter pub global activate flutterfire_cli


flutter pub add firebase_core


flutter pub add cloud_firestore


flutter pub add firebase_storage

mhadaily

mhadaily

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';

import 'firebase_options.dart';

void main() {
 WidgetsFlutterBinding.ensureInitialized();
 Firebase.initializeApp(
 	options: DefaultFirebaseOptions.currentPlatform
   );

  runApp(const MyApp());
}

mhadaily

class Home extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(title: const Text("Vacation photos")),
     body: Container(),
     floatingActionButton: const FloatingActionButton(
       onPressed: addPictures,
       child: Icon(Icons.add),
     ),
   );
 }
}



// Basic homepage

mhadaily

Future<void> addPictures() async {
 final filePickerResult = await FilePicker.platform.pickFiles();
 if (filePickerResult == null) return;

 for (var file in filePickerResult.files) {
   final result = await FirebaseStorage.instance
       .ref('photos/${file.name}')
       .putData(
         file.bytes!,
         SettableMetadata(contentType: mime.lookupMimeType(file.name)),
       );

   await FirebaseFirestore.instance.collection('photos').add({
     'createdAt': DateTime.now().toIso8601String(),
     'imageUrl': result.ref.fullPath,
   });
 }
}

mhadaily

Performance

mhadaily

mhadaily

mhadaily

mhadaily

Future<String> getThumbnail(String photoPath) async {
   final ext = path.extension(photoPath);
   final name = path.basenameWithoutExtension(photoPath);
   final thumbnailPath = 'photos/thumbnails/${name}_200x200$ext';

   final ref = FirebaseStorage.instance.ref(thumbnailPath);

   while (true) {
     try {
       await ref.getMetadata();
       return ref.getDownloadURL();
     } catch (e) {
       await Future.delayed(const Duration(milliseconds: 1000));
     }
   }
 }

mhadaily

mhadaily

mhadaily

Future<void> sendEmailWithPhoto(String url) async {
 await FirebaseFirestore.instance
 .collection('sharedPhotos')
 .add({
   'to': 'awesome@extensions.dev',
   'message': {
     'subject': 'Vacation photo 🏞',
     'html': '<img src="$url" />',
     'text': 'Check out this photo 👀',
   }
 });
}

mhadaily

mhadaily

const body = 'Hey, check my photo now! $photoUrl';

const smsBody = {
  to: '$phoneNumber',
  body: body,
};

const whatsappBody = {
  from: 'whatsapp:+14155238886',
  to: 'whatsapp:$phoneNumber',
  body: body,
};
Future<void> sendSmsWithPhoto(
  String photoUrl, 
  String phoneNumber,
) async {
  
   await FirebaseFirestore.instance
   .collection('messages')
   .add({
    to: '$phoneNumber',
    body: 'Hey, check my photo now! $photoUrl',
  });
}
Future<void> sendWhatsappMsgWithPhoto(
  String photoUrl, 
  String phoneNumber,
) async {

   await FirebaseFirestore.instance
   .collection('messages')
   .add({
    from: `whatsapp:${TWILIO_FROM_NUMBER}`,
    to: `whatsapp:${phoneNumber}`,
    body: 'Hey, check my photo now! $photoUrl',
  });
}

mhadaily

Find me on the internet by

Head of DevRel at Invertase

Majid Hajian

Slides

slides.com/mhadaily

Extending Firebase

By Majid Hajian

Extending Firebase

  • 574