get_it_mixin icon indicating copy to clipboard operation
get_it_mixin copied to clipboard

Couldn't make it work for me

Open marcobraghim opened this issue 1 year ago • 1 comments

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?

marcobraghim avatar Aug 30 '23 21:08 marcobraghim

Could you please show me where you watch it in your build method?

Also I recommend switching to my new package watch_it.

escamoteur avatar Aug 31 '23 07:08 escamoteur