Search code examples
firebaseflutterdartflutter-dependencieswhite-labelling

How can I override my main pubspec dependencies (white labelling a flutter app)


I have one project that I have to sell to another clients, so I wanna found a way to unify the code to, when I release some updates, I have to manipulate only one code (and, of course, keeping the specificities from each one)

The problem is In my first app I was using firebase_messaging with its google-services.json. But in this new client I won't use it... I tried to run and it throws this error:

E/flutter ( 7850): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project? 
E/flutter ( 7850):     
E/flutter ( 7850):     View the Android Installation documentation for more information: https://firebase.flutter.dev/docs/installation/android
E/flutter ( 7850):     
E/flutter ( 7850): #0      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:86:9)
E/flutter ( 7850): <asynchronous suspension>
E/flutter ( 7850): #1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:44:9)
E/flutter ( 7850): <asynchronous suspension>
E/flutter ( 7850): #2      main (package:app_md/main.dart:72:3)
E/flutter ( 7850): <asynchronous suspension>
E/flutter ( 7850): 

How can I deal with child projects that don't will use firebase_messaging:? I'm using the 'config' parameter to do this heritage

I used this way: https://medium.com/@ramiechaarani/how-to-make-a-white-label-app-in-flutter-6c3ea40fd7d5

In sum:

I have One main app that initially I did to one client. This client uses firebase. Now I wanna keep only the main functions and separate it to use in another client. The problem is, this new client does not use firebase, so when i try to run the app it throws that error because I haven't a google-services.json. How can I say that in this project (which inherit the main project) I don't will use firebase?

Expected outcome: in the second brand app don't use firebase..

maybe there is a way to override dependencies? Or there is another approach to achieve my goal..


Solution

    1. Extract a common module containing only client interface with common methods
    2. Add the implementation to clients' modules (or create module per implementation, depends if multiple clients are going to use the same implementation)
    3. In your 'core' (white label) module's entrypoint add the interface from step 1 as a parameter
    4. In client's module, pass the implementation as a parameter to the entrypoint

    This is essentially what Separation of conerns is about. Your BLOCs (or whatever you're using to do business logic) needn't to know where 'stuff' is coming from. All they care about is the fact that 'stuff' comes.

    In order to better understand SoC, you might want to read something more easygoing than the Wikipedia article, for example: How do you explain Separation of Concerns to others?