get_it_mixin
get_it_mixin copied to clipboard
Couldn't make it work for me
Let's suppose the structure below of a Viewmodel
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
@Injectable()
class MyViewmodel {
final name = ValueNotifier<String?>(null);
bool _initialized = false;
Future<void> initialize() async {
if (_initialized) return;
final resp = await Dio().get('https://jsonplaceholder.typicode.com/users/2');
name.value = resp.data['name'];
_initialized = true;
}
}
But on the build
method it is never anything than null
... Do every viewmodel need to be stored as singleton on GetIt?
Could you please show me where you watch it in your build method?
Also I recommend switching to my new package watch_it.