@@ -792,11 +792,25 @@ class _EnumSelectParamInput<T extends Enum> extends ParamInput<List<T>> {
792792/// These are special expressions that read from Firebase environment
793793/// variables and are always available without being defined by the user.
794794class InternalExpression extends Param <String > {
795- const InternalExpression ._(String name, this .getter) : super (name, null );
796- final String Function (Map <String , String >) getter;
795+ const InternalExpression ._(String name, this ._configKey) : super (name, null );
796+
797+ final String _configKey;
797798
798799 @override
799- String runtimeValue () => getter (Platform .environment);
800+ String runtimeValue () {
801+ if (Platform .environment['FIREBASE_CONFIG' ] case final String config) {
802+ try {
803+ if (jsonDecode (config) case final Map <String , dynamic > map) {
804+ if (map[_configKey] case final String value) {
805+ return value;
806+ }
807+ }
808+ } on FormatException {
809+ // ignore
810+ }
811+ }
812+ return '' ;
813+ }
800814
801815 @override
802816 WireParamSpec <String > toSpec () {
@@ -820,45 +834,22 @@ sealed class ParamInput<T extends Object> {
820834
821835 // Internal Firebase expressions
822836
823- static final databaseURL = InternalExpression ._('DATABASE_URL' , (env) {
824- if (! env.containsKey ('FIREBASE_CONFIG' )) return '' ;
825- try {
826- final config = jsonDecode (env['FIREBASE_CONFIG' ]! );
827- return config['databaseURL' ] as String ? ?? '' ;
828- } on FormatException {
829- return '' ;
830- }
831- });
837+ static const databaseURL = InternalExpression ._(
838+ 'DATABASE_URL' ,
839+ 'databaseURL' ,
840+ );
832841
833- static final projectId = InternalExpression ._('PROJECT_ID' , (env) {
834- if (! env.containsKey ('FIREBASE_CONFIG' )) return '' ;
835- try {
836- final config = jsonDecode (env['FIREBASE_CONFIG' ]! );
837- return config['projectId' ] as String ? ?? '' ;
838- } on FormatException {
839- return '' ;
840- }
841- });
842+ static const projectId = InternalExpression ._('PROJECT_ID' , 'projectId' );
842843
843- static final gcloudProject = InternalExpression ._('GCLOUD_PROJECT' , (env) {
844- if (! env.containsKey ('FIREBASE_CONFIG' )) return '' ;
845- try {
846- final config = jsonDecode (env['FIREBASE_CONFIG' ]! );
847- return config['projectId' ] as String ? ?? '' ;
848- } on FormatException {
849- return '' ;
850- }
851- });
844+ static const gcloudProject = InternalExpression ._(
845+ 'GCLOUD_PROJECT' ,
846+ 'projectId' ,
847+ );
852848
853- static final storageBucket = InternalExpression ._('STORAGE_BUCKET' , (env) {
854- if (! env.containsKey ('FIREBASE_CONFIG' )) return '' ;
855- try {
856- final config = jsonDecode (env['FIREBASE_CONFIG' ]! );
857- return config['storageBucket' ] as String ? ?? '' ;
858- } on FormatException {
859- return '' ;
860- }
861- });
849+ static const storageBucket = InternalExpression ._(
850+ 'STORAGE_BUCKET' ,
851+ 'storageBucket' ,
852+ );
862853
863854 // Factory methods for creating input types
864855
0 commit comments