0

My friend and I are doing a project. He will do the Firebase part and I will do the Front-End part.There is a problem: There isn't any Firebase.So I don't have any data. In that case what should I do?

Should I create fake datas or an Class with parameters like that:?

class Firebase_Datas{
   String name;
   String surname;
   .
   ..
   ...
   if (name == null){
    return "---";  //I assumed that arguments were given.
   .
   ..
   ...
}
}
```
Berke
  • 59
  • 6
  • 1
    What do you mean by "There isn't any Firebase"? You can set up a Firebase project in a matter of minutes (if not seconds...). Even if it is not the final/real project your front-end code will stay valid as soon as there is no DB data model changes or Storage bucket/"folders" naming. You just have to adapt the Firebase config to point to another project. – Renaud Tarnec Jun 03 '22 at 12:33

1 Answers1

1

Speaking in general, you should do Interface-Oriented Programming at some level, which means: talk to your partner and align what each side expects.

But your question specifically asks about models. There's no correct answer, but what I would suggest you to do is:

  • create the model as in your example:

    class UserModel {
      final String name;
      final String surname;
    }

  • use the repository pattern to shield your UI/Controller from changes in models

    abstract class UserRepository {
      Future<UserModel> getUser();
    }
    class UserFakeRepository implements UserRepository {
      @override
      Future<UserModel> getUser() {
        final result = UserModel('John', 'Doe');
      }
    }

  • in your UI/Controller layer you should use the repository instead of feeding the UI directly with the data:

    class _UserPageState extends State<UserPage> {
      UserModel? user;
    
      @override
      void initState() {
        _repository.getUser().then((result) =>
        setState(() {
          user = result;
        }));
      }
    }

  • after the Firebase part is built, you can implement a new UserRepository and change your dependency injection (meaning, stop using UserFakeRepository and use this new one):

    class UserFirebaseRepository implements UserRepository {
      @override
      Future<UserModel> getUser() {
        final result = _firebase.query(...);
      }
    }

  • for unit testing purposes, I advise you to create a wrapper for Firebase.instance. If you use them directly in your repositories, you'll be unable to write unit tests for your repositories.

  • by writing code this way, your UI layer will remain unchanged when you integrate the app with Firebase.

Eric Omine
  • 489
  • 4
  • 15