Skip to the content.

Flutter Codes

Website Demo Documentation Detailed Documentation

Purpose

Generic Packages

Splash Screen

Firebase

Cloud Firestore Collection Documents Setting up cloud firestore

Firebase Storage Features Configuration

Authentication

Google Authentication Google Authentication Setup

Facebook Authentication Facebook Developer Consoler Setup Enable Facebook Authentication

One-to-One Chatting One-to-One Calls

Purpose of this Repository

I have made this repository for reusing the most commonly used code modules. As a developer, I know the headache of re-doing the same piece of code again and again and sometimes, you just forgot about one step and here you go, your code stops working with a long list of errors. So, here is the easiest solution I think of to make this repository and add all the working codes in it, to get it whenever they are needed.

Some Generic Flutter Packages

TOP

Animated Splash Screen

Website Demo

Splash Screens made your applications look more professional and I have created a little module for animated splash screen. I have used the Animated Splash Screen package for this and this package a little depend on the Page Transition package. Read more about the animated splash screen package here and about the page transition package here. Add these dependencies in pubspec.yaml:

     animated_splash_screen:
     page_transition:

Create a new class named AnimatedSplashScreen add the following code in that class like this:

  return AnimatedSplashScreen(
      duration: 7,
      splash: "[n]https://i.imgur.com/p3i6j7o.png",
      nextScreen: Mainpage(),
      splashTransition: SplashTransition.fadeTransition,
      pageTransitionType: PageTransitionType.bottomToTop,
      backgroundColor: Colors.transparent,
    );

Now just replace your home: attribute in your main function with AnimatedSplashScreen()

  void main(){
    runApp(
      MaterialApp(
        home: AnimatedSplashScreen(),
      ),
    );
  }

TOP

Firebase

Firebase gives you the tools to develop high-quality apps, grow your user base, and earn more money. Follow these instructions to get stated with firebase.

Create Project

Add Application

TOP

Cloud Firestore

Cloud firestore is used to store data of an application. Data is stored in _Collections and Documents__.

Collection

A collection points out to a certain type of data class like collection of Pet. We can consider it as a class in object oriented language.

Documents

A collection consists of multiple documents which stores the data fields about an entity. Each document has a unique id in a collection which can be used to refer to the data included/saved in that document. In the same manner as an id of a sql database’table.

Just like an SQL database, we can perfrom different functions on data like

Setting up Cloud Firestore

Select Cloud Firestore

Create Database

Update Rules

    <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>

TOP

Firebase Storage

Cloud Storage is designed to help you quickly and easily store and serve user-generated content without any server, such as photos and videos.

Features of Firebase Storage:

Configure the Firebase Storage in your project

Enable Firebase Storage

It should look like this. Now, you can add the folders here or can upload images directly to be accessed later.

Storage

Default Rules

I have used Image Picker package for getting image on Android and iOs and File Picker package for Web. On Android and iOS, we need permissions for accessing gallery. - Add External Storage Read & Write Permission for Android in AnroidManifest.xml file. android> app> src> main> AndroidManifes.xml <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> - Add Photos permission in Info.plist for iOS. ios> Runner> Info.plist <key>NSPhotoLibraryUsageDescription</key> <string>This app requires to save your images user gallery</string>

Add the image picker and file picker package along with permission handler package in pubspec.yaml.

    image_picker: 

We are using permission handler package because image picker package does not handle permissions by itself. Read more about image picker package here.

TOP

Authentication Modules

We are using Firebase Authentication in our project so we need to add Firebase Auth package in pubspec.yaml. Read more about this here.

    firebase_auth: 
    <script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-auth.js"></script>

Google Authentication

Google Sign In using Firebase Authentication

Website Demo

Google Sign In is the most commonly used authentication method which is used by almost all the websites and other platforms. In this project, we are going to use google authentication which will also manage the auto signing in of a user by using Shared Preferences. Add Google Sign In and Shared Preference packages into pubspec.yaml like this:

      google_sign_in:
      shared_preferences:

Read more about google sign in here and about shared preferences here.

Guidelines for Google Authentication Setup

We will add authentication method (google) in our project.

Add Authentication Method

Select Authentication

Google

Additional Setup for Android

It will generate the list of whitelist client id’s to be used by the system.

Additional Setup for Web Applications

Setting up google authentication for an website requires some additional steps, which we are going to discuss below:

You are all set-up, just place the following two commands in your index.html.

  <meta name="google-signin-client_id" content="yourclientid.apps.googleusercontent.com">
  <script src="https://apis.google.com/js/platform.js" async defer></script>

Facebook Authentication

Facebook authentication is also one of the common authentication methods used for uer sign up into an application by following minimum steps on user side, but for a developer you have to follow some steps to make it work properly in your application. The neccessary steps are mentioned below:

Setup Application on Facebook Developer Console

Add app

Android Setup

Flutter Codes your_facebook_app_id fbyour_facebook_app_id
- Add the following permission in `AndroidManifest.xml`
- Now add the following config in you `AndroidManifest.xml` file.
- Now associalte your package name and default class of your app

![Package Name](https://i.imgur.com/tnXZm2c.png)
 
- Now provide development and release key hashes. You need to follow the instructions mentioned here to get the key hashes [https://developers.facebook.com/docs/facebook-login/android?locale=en_US#6--provide-the-development-and-release-key-hashes-for-your-app](https://developers.facebook.com/docs/facebook-login/android?locale=en_US#6--provide-the-development-and-release-key-hashes-for-your-app)

![key hashes](https://i.imgur.com/viRthgD.png)

**Note:** if you find it difficult to get the hash  key by following the instructions. You can convert the SHA1 into your hash key on this [Hex to Base64 Converter](http://tomeko.net/online_tools/hex_to_base64.php). You just need to put your SHA1 key and it will generate the hash key. 

![hash key converter](https://i.imgur.com/4Rb73fX.png)


#### Website Setup
- You need to add the facebook javascript sdk into your `index.html` file.
- In `main.dart`, add the following code but before `runapp()`
```dart
if (kIsWeb) {
    // initialiaze the facebook javascript SDK
    FacebookAuth.i.webInitialize(
      appId: "YOUR APP_ID",
      cookie: true,
      xfbml: true,
      version: "v1.0",
    );
  }
  • Apart from this, you need to add your website url too.

    Website URL

  • Also you need to add all the domains and subdomain related to your application. To add these go to your app’s** settings>basic**

    App Domains

Note: You need to add domain names without http/https. And you can also add a logo of your application and the privacy policy and terms of services.

TOP

Enable Facebook Authentication

TOP

Application Screenshots

Splash Screen Login Screen User Profile File Picker

TOP

Check the web application here.

You are all set, just clone the repository and use the code in your project.

Happy Coding 😊

Let’s Connect

Ayesha Iftikhar Github Linkedin Facebook Twitter Instagram Youtube Medium StackOverflow Gmail Messenger WhatsApp RPubs