如何在 runApp(MyApp()); 之前使用环境变量
How to use env variable before runApp(MyApp());
我需要传递一个环境变量才能像这样使用
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());
}
我收到一个错误
string.fromenvironment can only be used as a constant constructor
有办法吗?
谢谢
你会从 'final' 改为 '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());
}
我需要传递一个环境变量才能像这样使用
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());
}
我收到一个错误
string.fromenvironment can only be used as a constant constructor
有办法吗?
谢谢
你会从 'final' 改为 '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());
}