One of the popular BaaS backend Service to quick charge your Flutter App
Flutter, a one in all solution for building software on all platforms of your choice. It supports a wide range of platforms but its strength lies in platforms like Android and iOS without compromising the performance and app load times.
Firebase, Google’s mobile and web app development platform that helps developers build apps and games that users will love. It’s like a toolkit full of handy resources that we can integrate seamlessly without worrying about writing code from scratch or learning a new stack just for backend.
These services include, Authentication, Firestore for storing and manipulating databases in real time, Crashlytics, and much, much more.
Out of all the frameworks, Firebase gels well with Flutter as it has good documentation and the integration for most of its features are just a few lines of code.
Firebase supports iOS, Android, web, and desktop platforms, so you can use the same backend for all your Flutter apps. This saves you time and money as you don’t have to maintain separate backends for different platforms. Basically, we can leverage the power of Flutter with the heavy services that Firebase offers for different platforms with ease.
Before we start, let’s gather the tools we need to embark on our first Flutter Firebase project.
Step 1:
Step 2:
Choose Project Name of Your Liking
Enable Google Analytics
It’s a good idea to enable google analytics as Google Analytics for Firebase is a tool that provides real-time information about how users interact with an app. It also helps you understand how people use your web, Apple, or Android app. The SDK automatically captures a number of events and user properties and also allows you to define your own custom events to measure the things that uniquely matter to your business.
Enable Google AnalyticsChoose Your Account For Analytics
Here, I’m choosing my Google Account for Google Analytics to view reports and its dashboard.
Congrats! You’ve Created Your First Firebase Project.
Now, Let’s Setup Your Project with Firebase in desired platforms.
Note: You can set up on platforms using the FlutterFire CLI as well. Details given below.
For Android:
Step 1
Note: In case you didn’t find it, you can look at the side panel. Navigate from “Project Overview”> ⚙️ >”Project Settings”. Scroll to bottom and choose your Platform.
Step 2:
Step 3:
Step 4:
Step 5:
Similarly, for iOS, do the following :
Step 1:
Step 2:
Step 3 :
Okay. So, for iOS, let’s open up the project in Xcode. Let us first add the required firebase package as mentioned above.
Follow this instruction for details: https://github.com/firebase/firebase-ios-sdk/blob/main/SwiftPackageManager.md
Step 1:
Step 2:
https://github.com/firebase/firebase-ios-sdk.git
Next, set the Dependency Rule to be Up to the Next Major Version.
Then, select Add Package.
Step 3:
Note: After installing sdk, go to your project in vscode.
Step 4:
Step 5:
Step 6:
Now, you should be all set.
// Importing necessary packages
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart'; // This file is auto-generated by Firebase CLI when setting up Firebase in the project.
Future<void> main() async {
// Ensures that widget binding is initialized before running the app.
// This is required to interact with the Flutter engine and use services like Firebase.
WidgetsFlutterBinding.ensureInitialized();
// Initialize Firebase with platform-specific options.
// The `DefaultFirebaseOptions` is a class that holds the Firebase configuration
// specific to each platform (e.g., Android, iOS, Web). It is auto-generated during setup.
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform, // Automatically selects platform-specific configuration.
);
// Runs the main app widget.
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key}); // Constructor for MainApp, marked as `const` for optimization.
@override
Widget build(BuildContext context) {
// The root of the application, a MaterialApp widget for material design styling.
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello Firebase App!'),
),
),
);
}
}
And that’s it. Firebase has been integrated into your project. If you want more, I’m planning on making another tutorial for integration of Firebase Auth and Firestore Database with your project. Let me know in the comments. Thank you
Our swift-paced team is capable of handling design projects on anywhere and anytime. We’re ready to deliver your best product wherever you are !