With the injectable_annotations package, we are able to utilize the @singleton annotation to create services.


Here is an example from the Myoro Matchup codebase:

/// User service.
@singleton
final class UserService {
  /// Default constructor.
  UserService(this._sharedPreferencesService);

  /// Shared preferences service.
  final SharedPreferencesService _sharedPreferencesService;
  
  /// If we wanted to, we can fields such as [ValueNotifier]s.
  ///
  /// No need to dispose as singletons are destroyed on stop.
  final _someImportantGlobalStateController = ValueNotifier(null);

  /// Getter of the logged in user.
  LoggedInUser? get loggedInUser {
    return _sharedPreferencesService.loggedInUser;
  }

  /// Returns if there is a user logged in.
  bool get isLoggedIn {
    return _sharedPreferencesService.loggedInUser != null;
  }
}