title: Flutter/Dart get_It singleton locator method failure
body: <p>I have a simple dart class as follows:</p>
  <pre><code>import 'package:flutter/material.dart';
  
  class UiUtils {
    // TEMPORARY FOR UNIT TEST PURPOSES ONLY
    int addition(int x, int y) {
      return x + y;
    }
  }
  </code></pre>
  <p>(Note: The above is a sample, the actual class does have more than that temp function.)</p>
  <p>My <code>pubspec.yml</code> file contains the following:</p>
  <pre><code>dependencies:
    flutter:
      sdk: flutter
    flutter_localizations:
      sdk: flutter
    intl: ^0.17.0
  
    # The following adds the Cupertino Icons font to your application.
    # Use with the CupertinoIcons class for iOS style icons.
    cupertino_icons: ^1.0.2
    get_it: ^7.1.3
    provider: ^6.0.1
    mockito: ^5.0.16
  </code></pre>
  <p>I have a <code>dependency locator</code> file as such:</p>
  <pre><code>import 'package:get_it/get_it.dart';
  import 'package:quiz_test/utils/UiUtils.dart';
  
  GetIt dependencyLocator = GetIt.instance;
  
  void setupDependencyLocator() {
    //dependencyLocator.registerSingleton(() =&gt; UiUtils());
    dependencyLocator.registerFactory(() =&gt; UiUtils());
  }
  </code></pre>
  <p>Finally, in <code>main.dart</code> I have the following:</p>
  <pre><code>void main() {
    setupDependencyLocator();
    runApp(MyApp());
  }
  </code></pre>
  <p>(There is of course more code than this).</p>
  <p>As it is displayed, the code works fine, however if I change the dependancy_locator file from the current factory method to the singleton instead (i.e. comment out one to enable the other) I get the following error:</p>
  <pre><code>[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: type '_ServiceFactory&lt;() =&gt; UiUtils, void, void&gt;' is not a subtype of type '_ServiceFactory&lt;Object, dynamic, dynamic&gt;' of 'value'
  #0      _LinkedHashMapMixin.[]= (dart:collection-patch/compact_hash.dart)
  #1      _GetItImplementation._register (package:get_it/get_it_impl.dart:844:35)
  #2      _GetItImplementation.registerSingleton (package:get_it/get_it_impl.dart:587:5)
  #3      setupDependencyLocator (package:quiz_test/utils/dependency_locator.dart:7:21)
  #4      main (package:quiz_test/main.dart:13:3)
  #5      _runMainZoned.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (dart:ui/hooks.dart:145:25)
  #6      _rootRun (dart:async/zone.dart:1428:13)
  #7      _CustomZone.run (dart:async/zone.dart:1328:19)
  #8      _runZoned (dart:async/zone.dart:1863:10)
  #9      runZonedGuarded (dart:async/zone.dart:1851:12)
  #10     _runMainZoned.&lt;anonymous closure&gt; (dart:ui/hooks.dart:141:5)
  #11     _delayEntrypointInvocation.&lt;anonymous closure&gt; (dart:isolate-patch/isolate_patch.&lt;…&gt;
  </code></pre>
  <p>Can anyone please help me to understand why I cannot use the singleton call rather than the factory one? My thought process is that I do not need a unique instance of this class, which is what I believe factory will give me, I just need a single instance of it for any classes that require it.</p>
  <p>Any help is greatly appreciated.</p>