@@ -792,11 +792,26 @@ 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 > m) {
804+ return switch (m[_configKey]) {
805+ final String value => value,
806+ _ => '' ,
807+ };
808+ }
809+ } on FormatException {
810+ // ignore
811+ }
812+ }
813+ return '' ;
814+ }
800815
801816 @override
802817 WireParamSpec <String > toSpec () {
@@ -820,45 +835,22 @@ sealed class ParamInput<T extends Object> {
820835
821836 // Internal Firebase expressions
822837
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- });
838+ static const databaseURL = InternalExpression ._(
839+ 'DATABASE_URL' ,
840+ 'databaseURL' ,
841+ );
832842
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- });
843+ static const projectId = InternalExpression ._('PROJECT_ID' , 'projectId' );
842844
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- });
845+ static const gcloudProject = InternalExpression ._(
846+ 'GCLOUD_PROJECT' ,
847+ 'projectId' ,
848+ );
852849
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- });
850+ static const storageBucket = InternalExpression ._(
851+ 'STORAGE_BUCKET' ,
852+ 'storageBucket' ,
853+ );
862854
863855 // Factory methods for creating input types
864856
0 commit comments