简体   繁体   中英

How to make @factoryParams nullable in dart/Flutter?

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)

│ ^^^

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM