@@ -59,11 +59,8 @@ class FirebaseDartConfigurationWrite {
5959 );
6060 outputFile.writeAsStringSync (updatedFileString);
6161 } else {
62- _writeHeader ();
63- _writeClass ();
64-
6562 outputFile.createSync (recursive: true );
66- outputFile.writeAsStringSync (_stringBuffer. toString ());
63+ outputFile.writeAsStringSync (_buildConfigurationFile ());
6764 }
6865
6966 return _firebaseJsonWrites ();
@@ -130,14 +127,28 @@ class FirebaseDartConfigurationWrite {
130127 platform == kWeb ? 'if (kIsWeb)' : 'case TargetPlatform.$platform :' ,
131128 ),
132129 );
133- final unsupportedErrorLineIndex = startIndex + 1 ;
134130
135- if (fileConfigurationLines[unsupportedErrorLineIndex]
136- .contains ('UnsupportedError' )) {
131+ // Existing file does not match generated FlutterFire structure.
132+ // Regenerate so configure can recover from template placeholders.
133+ if (startIndex == - 1 ) {
134+ return _buildConfigurationFile ();
135+ }
136+
137+ final unsupportedErrorLineIndex = fileConfigurationLines.indexWhere (
138+ (line) =>
139+ line.contains ('throw UnsupportedError(' ) ||
140+ line.contains ('throw UnimplementedError(' ),
141+ startIndex,
142+ );
143+
144+ if (unsupportedErrorLineIndex != - 1 ) {
137145 final endIndex = fileConfigurationLines.indexWhere (
138146 (line) => line.contains (');' ),
139147 unsupportedErrorLineIndex,
140148 );
149+ if (endIndex == - 1 ) {
150+ return _buildConfigurationFile ();
151+ }
141152 fileConfigurationLines.removeRange (
142153 unsupportedErrorLineIndex,
143154 endIndex + 1 ,
@@ -150,7 +161,7 @@ class FirebaseDartConfigurationWrite {
150161 : ' return ${platform .toLowerCase ()};' ,
151162 );
152163 } else {
153- throw Exception ( '`UnsupportedError` not found in $ platform ' );
164+ return _buildConfigurationFile ( );
154165 }
155166
156167 final insertIndex = fileConfigurationLines.lastIndexOf ('}' );
@@ -169,6 +180,13 @@ class FirebaseDartConfigurationWrite {
169180 return formatList (fileConfigurationLines).join ('\n ' );
170181 }
171182
183+ String _buildConfigurationFile () {
184+ _stringBuffer.clear ();
185+ _writeHeader ();
186+ _writeClass ();
187+ return formatList (_stringBuffer.toString ().split ('\n ' )).join ('\n ' );
188+ }
189+
172190 // ensure only one empty line between each static property
173191 List <String > formatList (List <String > items) {
174192 return items.fold <List <String >>([], (acc, item) {
0 commit comments