-1

I need to pass an env variable to be used like this

import 'package:flutter/foundation.dart' show kIsWeb;  
.
.
.
void main() {
  // check if is running on Web
  if (kIsWeb) {
  final appId = String.fromEnvironment('FACEBOOK_APP_ID',
  defaultValue: 'somedefaultvalue');
    // initialiaze the facebook javascript SDK
    FacebookAuth.instance.webInitialize(
      appId: appId,//<-- YOUR APP_ID
      cookie: true,
      xfbml: true,
      version: "v9.0",
    );
  }
  runApp(MyApp());
}

I get an error

string.fromenvironment can only be used as a constant constructor

is there a way to do this?

Thank you

user3808307
  • 2,270
  • 9
  • 45
  • 99

1 Answers1

1

Would you change from 'final' to 'const?

import 'package:flutter/foundation.dart' show kIsWeb;  
.
.
.
void main() {
  // check if is running on Web
  if (kIsWeb) {
  const appId = String.fromEnvironment('FACEBOOK_APP_ID',
  defaultValue: 'somedefaultvalue');
    // initialiaze the facebook javascript SDK
    FacebookAuth.instance.webInitialize(
      appId: appId,//<-- YOUR APP_ID
      cookie: true,
      xfbml: true,
      version: "v9.0",
    );
  }
  runApp(MyApp());
}
KuKu
  • 6,654
  • 1
  • 13
  • 25