Skip to content

Instantly share code, notes, and snippets.

@locskot
Created June 11, 2021 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save locskot/1882a0cf13dee69dd7d987fa4f5ca655 to your computer and use it in GitHub Desktop.
Save locskot/1882a0cf13dee69dd7d987fa4f5ca655 to your computer and use it in GitHub Desktop.
import 'package:components/base/base_viewmodel.dart';
const registrationKey = 'registrationKey';
const loginKey = 'loginKey';
const forgotPasswordKey = 'forgotPasswordKey';
const homeKey = 'homeKey';
const servicesKey = 'servicesKey';
const inboxKey = 'inboxKey';
const visitsKey = 'visitsKey';
const notificationKey = 'notificationKey';
const patientProfileKey = 'patientProfileKey';
// ignore: avoid_classes_with_only_static_members
class ViewModelProvider {
static final _map = <String, dynamic>{};
static T getOrCreate<T>({String key, T Function() create}) {
assert(key != null, 'id must not be null');
assert(create != null, 'create must not be null');
_map.putIfAbsent(key, () => create.call());
return _map[key];
}
static void delete(String key) {
final viewModel = _map[key];
if (viewModel is BaseViewModel) {
viewModel.onRemove();
}
_map.remove(key);
}
static void clear() {
_map.forEach((key, value) {
delete(key);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment