Hi! I want to get access to _authenticatedUser which is in UserModel from ProductsModel.
What is the most effective way to get it?
I guess i can use ScopedModel.of and pass it as an argument from View. But i don't feel like this is ideal.
Or is it okay to use DI library like get_it in a model file? (UserModel _userModel = locator< UserModel >();)
If it's okay, whether i use singleton or not when registering model using DI library makes any difference?
I guess i have to use singleton to keep states in a model.
class ProductsModel extends Model {
List<Product> _products = [];
void addProduct(
String title, String description, String image, double price) {
final Product newProduct = Product(
title: title,
description: description,
image: image,
price: price,
userEmail: _authenticatedUser.email,
userId: _authenticatedUser.id);
_products.add(newProduct);
notifyListeners();
}
}
class UserModel extends Model {
User _authenticaedUser;
void login(String email, String password) {
_authenticaedUser = User(id: 'fjekfjk', email: email, password: password);
}
}
Hi! I want to get access to _authenticatedUser which is in UserModel from ProductsModel.
What is the most effective way to get it?
I guess i can use ScopedModel.of and pass it as an argument from View. But i don't feel like this is ideal.
Or is it okay to use DI library like get_it in a model file? (UserModel _userModel = locator< UserModel >();)
If it's okay, whether i use singleton or not when registering model using DI library makes any difference?
I guess i have to use singleton to keep states in a model.