Flutter: Designing an Authentication API with Service Classes

Andrea Bizzotto
Jun 18 · 4 min read
  • This includes API methods with all their input and output (return) arguments.
  • (optional) create a base abstract class for the service class, so that it’s easier to swap this with a different implementation

Problem Statement

In the previous article, we used this code to sign in the user with FirebaseAuth:

  • What if we want to swap FirebaseAuth with a different auth provider in the future?

Solution: create service classes

A service class is simply a wrapper.

Showtime

Here is a video showing all these techniques in practice, using my Reference Authentication Flow as an example:

Conclusion

Service classes are a good way of hiding the implementation details of 3rd party code in your app.

  • This includes API methods with all their input and output (return) arguments.
  • (optional) create a base abstract class for the service class, so that it’s easier to swap this with a different implementation

Source code

This article was based on my Reference Authentication Flow with Flutter & Firebase:

For more articles and video tutorials, check out Coding With Flutter.

Coding with Flutter

Learn to build iOS and Android apps with Dart and Flutter

Andrea Bizzotto

Written by

iOS, Flutter Developer & Blogger ❖ https://codingwithflutter.com ❖ http://bizz84.github.io ❖ Open Source https://github.com/bizz84 ❖ Watching #ClimateChange

Coding with Flutter

Learn to build iOS and Android apps with Dart and Flutter