I'm facing a problem in my Flutter project where I'm trying to generate the
$initGetIt
function using Injectable, but it's not being generated as expected. Here are the details of the issue:
- I've checked my pubspec.yaml, and the dependencies for
get_it
and injectable
seem to be correct. Everything is updated.
- I've run
flutter pub get
and flutter pub run build_runner watch --delete-conflicting-outputs
, but the $initGetIt
function is still not generated.
- Here's my
injection.dart
and injection.config.dart
files [include code snippets here].
I'd appreciate any help or insights on what might be causing this issue and how to fix it.
What I really do to fix, but won't succeed:
**1. Fix
pubspec.yaml **
**
pubspec.yaml**
environment:
sdk: '>=3.1.0 <4.0.0'
dependencies:
bloc: ^8.1.2
cupertino_icons: ^1.0.2
dartz: ^0.10.1
dio: ^5.3.3
flutter:
sdk: flutter
flutter_bloc: ^8.1.3
freezed: ^2.4.3
freezed_annotation: ^2.4.1
get_it: ^7.6.4
injectable: ^2.3.2
json_annotation: ^4.8.1
json_serializable: ^6.7.1
retrofit: ^4.0.2
dev_dependencies:
build_runner: ^2.4.6
flutter_lints: ^2.0.0
flutter_test:
sdk: flutter
injectable_generator: ^2.4.1
retrofit_generator: ^8.0.0`
**2. removing include package on
analysis.option.yaml**
# **Injection.dart**
import 'package:fadvanced_gunawan3_4/injection.config.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
final getIt = GetIt.instance;
@injectableInit
void configureInjection(String env) {
$initGetIt(getIt, environment: env);
}
# **Injection.config.dart**
`
import 'package:get_it/get_it.dart' as _i1;
import 'package:injectable/injectable.dart' as _i2;
extension GetItInjectableX on _i1.GetIt {
_i1.GetIt init({
String? environment,
_i2.EnvironmentFilter? environmentFilter,
}) {
_i2.GetItHelper(
this,
environment,
environmentFilter,
);
return this;
}
}
# **THE ERROR I GOT:**
**injection.dart**
The function $initGetIt
isn't defined.
Try importing the library that defines $initGetIt
, correcting the name to the name of an existing function, or defining a function named $initGetIt
.
What I have tried:
1. Fix all
pubspec.yaml dependencies version
2. Removing
include
package on
analysis.option.yaml