I used Flavor and define two main classes. And also I used Chopper. How to set baseUrl based one environment?

import 'package:meta/meta.dart';

enum BuildFlavor { production, development }

BuildEnvironment get env => _env;
BuildEnvironment _env;

class BuildEnvironment {
  final String ssoBaseUrl;
  final BuildFlavor flavor;

  BuildEnvironment._init(
      {this.ssoBaseUrl,
      this.flavor});

  static void init(
          {@required flavor,
          @required ssoBaseUrl}) =>
      _env ??= BuildEnvironment._init(
          flavor: flavor,
          ssoBaseUrl: ssoBaseUrl);
}

main.dev.dart

void main() {
  BuildEnvironment.init(
      flavor: BuildFlavor.development,
      ssoBaseUrl: 'http://15.88.219.20');
  assert(env != null);
  runApp(MultiProvider(
    providers: globalProviders,
    child: MyApp(),
  ));
}

Chopper

@ChopperApi(baseUrl:'${env.ssoBaseUrl}')
abstract class Services extends ChopperService {
  static Services create([ChopperClient client]) => _$Services(client);

  @Post(path: '/sso-dev/registration')
  Future<Response> registerPost(

Error Message

click here to view error message


Solution 1: Matt

Annotations have to be provided with const values only. Since env is a getter property, it is not const. I'm afraid you won't be able to specify a baseUrl this way.