Skip to content

Commit

Permalink
Standardize Flutter bootstrap code (#2969)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed May 29, 2024
1 parent 10b6ccf commit e93bae9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
23 changes: 5 additions & 18 deletions pkgs/dart_services/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,17 @@ import 'dart:ui_web' as ui_web;
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'generated_plugin_registrant.dart';
import 'generated_plugin_registrant.dart' as pluginRegistrant;
import 'main.dart' as entrypoint;
Future<void> main() async {
registerPlugins(webPluginRegistrar);
await ui_web.bootstrapEngine(
runApp: () {
return entrypoint.main();
entrypoint.main();
},
registerPlugins: () {
pluginRegistrant.registerPlugins();
},
);
}
''';

const kBootstrapFlutterCode_3_16 = r'''
import 'dart:ui' as ui;
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'generated_plugin_registrant.dart';
import 'main.dart' as entrypoint;
Future<void> main() async {
registerPlugins(webPluginRegistrar);
await ui.webOnlyInitializePlatform();
entrypoint.main();
}
''';
10 changes: 2 additions & 8 deletions pkgs/dart_services/lib/src/compiling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,8 @@ class Compiler {
Directory(path.join(temp.path, 'lib')).createSync(recursive: true);

final bootstrapPath = path.join(temp.path, 'lib', kBootstrapDart);
String bootstrapContents;
if (usingFlutter) {
bootstrapContents = _sdk.usesNewBootstrapEngine
? kBootstrapFlutterCode
: kBootstrapFlutterCode_3_16;
} else {
bootstrapContents = kBootstrapDartCode;
}
final bootstrapContents =
usingFlutter ? kBootstrapFlutterCode : kBootstrapDartCode;

File(bootstrapPath).writeAsStringSync(bootstrapContents);
File(path.join(temp.path, 'lib', kMainDart)).writeAsStringSync(source);
Expand Down
13 changes: 0 additions & 13 deletions pkgs/dart_services/lib/src/sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,6 @@ final class Sdk {
String get flutterWebSdkPath =>
path.join(_flutterBinPath, 'cache', 'flutter_web_sdk', 'kernel');

bool get usesNewBootstrapEngine {
final uiWebPackage =
path.join(_flutterBinPath, 'cache', 'flutter_web_sdk', 'lib', 'ui_web');
final initializationLibrary =
path.join(uiWebPackage, 'ui_web', 'initialization.dart');

final file = File(initializationLibrary);
if (!file.existsSync()) return false;

// Look for 'Future<void> bootstrapEngine({ ... }) { ... }'.
return file.readAsStringSync().contains('bootstrapEngine(');
}

static Map<String, Object?> _retrieveFlutterVersion(
String flutterSdkPath,
String flutterToolPath,
Expand Down

0 comments on commit e93bae9

Please sign in to comment.