Home > Back-end >  How to make @factoryParams nullable in dart/Flutter?
How to make @factoryParams nullable in dart/Flutter?

Time:07-14

I'm trying to use the @factoryParam annotation of injectable package by using it in a class. But whenever I try to run the build runner to generate the config file, it gives me an error saying the Factory params must be nullable.

import 'package:injectable/injectable.dart';

@injectable
class QuoteRepository {
  const QuoteRepository(
      @factoryParam String env)
      : _env = env;
  final String _env;

  String getQuotes() {
    return _env;
  }
}

Error: [SEVERE] injectable_generator:injectable_builder on features/testing_view_model.dart:

Factory params must be nullable
package:features/testing_view_model.dart:6:28
  ╷
6 │       @factoryParam String env)

│ ^^^

CodePudding user response:

Try changing it to String? This will enable a String to be able to accept a null value also

  • Related