Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A non-null value must be returned since the return type 'S' doesn't allow null. #2826

Closed
nik2208 opened this issue Jun 12, 2023 · 1 comment
Assignees

Comments

@nik2208
Copy link

nik2208 commented Jun 12, 2023

Started getting this error:
../../.pub-cache/hosted/pub.dev/get-4.6.5/lib/
get_instance/src/get_instance.dart:281:5:
Error: A non-null value must be returned since
the return type 'S' doesn't allow null.

the referred code is the find fuction in get_instance.dart file:

/// Finds the registered type <[S]> (or [tag])
  /// In case of using Get.[create] to register a type <[S]> or [tag],
  /// it will create an instance each time you call [find].
  /// If the registered type <[S]> (or [tag]) is a Controller,
  /// it will initialize it's lifecycle.
  S find<S>({String? tag}) {
    final key = _getKey(S, tag);
    if (isRegistered<S>(tag: tag)) {
      final dep = _singl[key];
      if (dep == null) {
        if (tag == null) {
          throw 'Class "$S" is not registered';
        } else {
          throw 'Class "$S" with tag "$tag" is not registered';
        }
      }

      // if (dep.lateRemove != null) {
      //   dep.isDirty = true;
      //   if(dep.fenix)
      // }

      /// although dirty solution, the lifecycle starts inside
      /// `initDependencies`, so we have to return the instance from there
      /// to make it compatible with `Get.create()`.
      final i = _initDependencies<S>(name: tag);
      return i ?? dep.getDependency() as S;
    } else {
      // ignore: lines_longer_than_80_chthrow '"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"';
    }
  }

**Reproduction code
Create a new project:
Simply import the package:

import 'package:get/get.dart';

Flutter version is:

Flutter 3.10.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 682aa387cf (7 days ago) • 2023-06-05 18:04:56 -0500
Engine • revision 2a3401c9bb
Tools • Dart 3.0.3 • DevTools 2.23.1

I've recently updated from 3.10.3, but even downgrading the error persists.

@nik2208
Copy link
Author

nik2208 commented Jun 12, 2023

to anybody who incurs in this, I solved the issue installing a new instance of flutter and (suggested while running flutter doctor) doing a dart pub cache clean.

Don't really know whether running dart pub cache clean would have been enough.

The suspect that the problem was related to the framework instance came from the fact that downgrading to the flutter previous (and working) version didn't affect the errors in the build process.

@nik2208 nik2208 closed this as completed Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants