Skip to content

Conversation

@ditman
Copy link
Member

@ditman ditman commented Jul 1, 2022

The plugin_registrant.dart for web used to be created on flutter pub get. This was changed to be created only upon build/run time, so the file didn't have to live in the users' working copy (and didn't need to be analyzed alongside user code), here.

Making the plugin_registrant.dart ephemeral, however, broke the way that Dartpad compiles Flutter web apps quickly. Read more.

This PR adds a web_plugin_registrant.dart file in a known location (.dart_tool/dartpad/) at flutter pub get that Dartpad can use when bootstrapping their code.

The file is always generated, regardless of the app using web plugins or not. The contents are the same as for any Flutter web app.

Without plugins:

// Flutter web plugin registrant file.
//
// Generated file. Do not edit.
//

// ignore_for_file: type=lint

void registerPlugins() {}

With a bunch of plugins:

// Flutter web plugin registrant file.
//
// Generated file. Do not edit.
//

// ignore_for_file: type=lint

import 'package:camera_web/camera_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:video_player_web/video_player_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

void registerPlugins([final Registrar? pluginRegistrar]) {
  final Registrar registrar = pluginRegistrar ?? webPluginRegistrar;
  CameraPlugin.registerWith(registrar);
  UrlLauncherPlugin.registerWith(registrar);
  VideoPlayerPlugin.registerWith(registrar);
  registrar.registerMessageHandler();
}

Issues

Tests

  • Added a unit test to ensure the file is created in the expected location.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 1, 2022
@ditman
Copy link
Member Author

ditman commented Jul 1, 2022

/cc @srawlins hey Sam, is .dart_tool/dartpad OK, or does it need to be more specific?

@ditman ditman requested review from Jasguerrero and removed request for stuartmorgan-g July 1, 2022 01:17
@domesticmouse
Copy link
Contributor

/cc @srawlins hey Sam, is .dart_tool/dartpad OK, or does it need to be more specific?

That should be fine. =)

@ditman ditman requested a review from Jasguerrero July 1, 2022 18:59
@ditman
Copy link
Member Author

ditman commented Jul 1, 2022

@domesticmouse once this lands, should we attempt to cherry-pick this fix into beta or stable, or can you test/deploy dartpad from a master branch of flutter?

Also: can you verify the fix from this branch, or do we need to land this?

Copy link
Contributor

@Jasguerrero Jasguerrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@domesticmouse
Copy link
Contributor

@domesticmouse once this lands, should we attempt to cherry-pick this fix into beta or stable, or can you test/deploy dartpad from a master branch of flutter?

This is only an issue in beta, so no stable cherry pick is required. It's easiest for me to verify once it is in a named beta branch. I'd have to do some investigation to figure out how to get the tooling to work with master

@ditman
Copy link
Member Author

ditman commented Jul 1, 2022

@domesticmouse AFAIK once this lands, we can request a cherry-pick to beta. That should unblock your work faster than this landing on its own, I think?

@domesticmouse
Copy link
Contributor

I didn't know about a cherry pick for beta. I thought we just rolled beta weekly on the way to stable. And yes, DartPad is blocked from updating it's beta backend until this lands.

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 2, 2022
@auto-submit auto-submit bot merged commit c4aaa39 into flutter:master Jul 2, 2022
@ditman
Copy link
Member Author

ditman commented Jul 2, 2022

@domesticmouse created the CP request for beta here: #106983

@domesticmouse
Copy link
Contributor

domesticmouse commented Jul 21, 2022

Under what conditions will .dart_tool/dartpad/plugin_registrant.dart be created? I have a simplistic project that contains a pubspec.yaml file with the following content for which flutter pub get creates a .dart_tool directory, but no .dart_tool/dartpad/plugin_registrant.dart

$ flutter --version
Flutter 3.3.0-0.0.pre • channel beta • https://github.com/flutter/flutter
Framework • revision f90da9b167 (2 days ago) • 2022-07-18 18:59:23 -0700
Engine • revision 1388adb442
Tools • Dart 2.18.0 (build 2.18.0-271.2.beta) • DevTools 2.15.0
$ flutter pub get
Running "flutter pub get" in simple_project...                      4.4s
$ ls -laR
total 64
drwxr-xr-x   7 brettmorgan  primarygroup    224 Jul 21 12:49 .
drwxr-xr-x  17 brettmorgan  primarygroup    544 Jul 21 12:48 ..
drwxr-xr-x   5 brettmorgan  primarygroup    160 Jul 21 12:49 .dart_tool
-rw-r--r--   1 brettmorgan  primarygroup   2054 Jul 21 12:49 .flutter-plugins
-rw-r--r--   1 brettmorgan  primarygroup   7151 Jul 21 12:49 .flutter-plugins-dependencies
-rw-r--r--   1 brettmorgan  primarygroup  15018 Jul 21 12:49 pubspec.lock
-rw-r--r--   1 brettmorgan  primarygroup   2193 Jul 21 12:48 pubspec.yaml

./.dart_tool:
total 88
drwxr-xr-x  5 brettmorgan  primarygroup    160 Jul 21 12:49 .
drwxr-xr-x  7 brettmorgan  primarygroup    224 Jul 21 12:49 ..
-rw-r--r--  1 brettmorgan  primarygroup  18607 Jul 21 12:49 package_config.json
-rw-r--r--  1 brettmorgan  primarygroup  16871 Jul 21 12:49 package_config_subset
-rw-r--r--  1 brettmorgan  primarygroup     13 Jul 21 12:49 version

Contents of pubspec.yaml:

name: simple_project
environment:
  sdk: '>=2.18.0-0 <3.0.0'
dependencies:
  flutter:
    sdk: flutter
  flutter_test:
    sdk: flutter
  archive: 3.3.1
  async: 2.9.0
  bloc: 8.0.3
  boolean_selector: 2.1.0
  characters: 1.2.1
  clock: 1.1.1
  cloud_firestore: 3.3.0
  cloud_firestore_platform_interface: 5.6.0
  cloud_firestore_web: 2.7.0
  collection: 1.16.0
  crypto: 3.0.2
  english_words: 4.0.0
  fake_async: 1.3.1
  ffi: 2.0.1
  file: 6.1.2
  firebase_analytics: 9.2.0
  firebase_analytics_platform_interface: 3.2.0
  firebase_analytics_web: 0.4.1
  firebase_auth: 3.4.2
  firebase_auth_platform_interface: 6.3.2
  firebase_auth_web: 4.0.0
  firebase_core: 1.19.2
  firebase_core_platform_interface: 4.4.3
  firebase_core_web: 1.7.0
  firebase_database: 9.0.19
  firebase_database_platform_interface: 0.2.1+11
  firebase_database_web: 0.2.1
  firebase_messaging: 12.0.0
  firebase_messaging_platform_interface: 4.0.0
  firebase_messaging_web: 3.0.0
  firebase_storage: 10.3.2
  firebase_storage_platform_interface: 4.1.11
  firebase_storage_web: 3.3.0
  flame: 1.2.1
  flame_fire_atlas: 1.2.0
  flame_forge2d: 0.12.1
  flame_splash_screen: 0.1.0
  flame_tiled: 1.6.0
  flutter_bloc: 8.0.1
  flutter_hooks: 0.18.5+1
  flutter_lints: 2.0.1
  flutter_riverpod: 1.0.4
  forge2d: 0.11.0
  go_router: 4.1.1
  google_fonts: 3.0.1
  hooks_riverpod: 1.0.4
  http: 0.13.4
  http_parser: 4.0.1
  intl: 0.17.0
  js: 0.6.4
  lints: 2.0.0
  logging: 1.0.2
  matcher: 0.12.12
  material_color_utilities: 0.1.5
  meta: 1.8.0
  nested: 1.0.0
  ordered_set: 5.0.0
  path: 1.8.2
  path_provider: 2.0.11
  path_provider_android: 2.0.16
  path_provider_ios: 2.0.10
  path_provider_linux: 2.1.7
  path_provider_macos: 2.0.6
  path_provider_platform_interface: 2.0.4
  path_provider_windows: 2.1.0
  petitparser: 5.0.0
  platform: 3.1.0
  plugin_platform_interface: 2.1.2
  process: 4.2.4
  provider: 6.0.3
  riverpod: 1.0.3
  rxdart: 0.27.5
  source_span: 1.9.0
  stack_trace: 1.10.0
  state_notifier: 0.7.2+1
  stream_channel: 2.1.0
  string_scanner: 1.1.1
  term_glyph: 1.2.1
  test_api: 0.4.12
  tiled: 0.8.4
  typed_data: 1.3.1
  vector_math: 2.1.2
  win32: 2.7.0
  xdg_directories: 0.2.0+1
  xml: 5.4.1

@ditman
Copy link
Member Author

ditman commented Jul 21, 2022

@domesticmouse the file should be created when there's any web plugin declared in the dependencies (it uses the same logic as flutter build, just at a slightly different time).

If you're using flutter from git, though, please try this before flutter pub get:

rm your/path/to/flutter/bin/cache/flutter_tools.*

Otherwise you'll be using a cached version of the flutter_tools, and you won't get the new behavior from beta at all.


PS: This is what the cache directory looks like in my box (we want to delete the flutter_tools.snapshot and .stamp):

$ ls ~/github/flutter/bin/cache
android-sdk.stamp      flutter_sdk.stamp            flutter_web_sdk.stamp   libplist.stamp        pkg
artifacts              flutter_tools.snapshot       font-subset.stamp       linux-sdk.stamp       usbmuxd.stamp
dart-sdk               flutter_tools.stamp          gradle_wrapper.stamp    lockfile
downloads              flutter_version_check.stamp  ios-deploy.stamp        material_fonts.stamp
engine-dart-sdk.stamp  flutter_web_sdk              libimobiledevice.stamp  openssl.stamp

Once you've deleted the files, you'll get a Building flutter tool... message the next time you use flutter, and a slightly lengthier execution time; you can use flutter normally afterwards:

$ rm ~/github/flutter/bin/cache/flutter_tools.*
$ flutter --version
Building flutter tool...
Flutter 3.1.0-0.0.pre.1775 • channel master • [email protected]:ditman/flutter.git
Framework • revision a400d132c1 (2 hours ago) • 2022-07-20 21:04:06 -0400
Engine • revision 7892b36d1e
Tools • Dart 2.19.0 (build 2.19.0-16.0.dev) • DevTools 2.15.0

@domesticmouse
Copy link
Contributor

Hey @ditman, here's what I'm seeing:

$ rm ~/flutter/bin/cache/flutter_tools.s*
$ flutter --version
Building flutter tool...
Flutter 3.3.0-0.0.pre • channel beta • https://github.com/flutter/flutter
Framework • revision f90da9b167 (2 days ago) • 2022-07-18 18:59:23 -0700
Engine • revision 1388adb442
Tools • Dart 2.18.0 (build 2.18.0-271.2.beta) • DevTools 2.15.0
$ flutter pub get
Running "flutter pub get" in simple_project...                      4.3s
$ ls -l .dart_tool 
total 88
-rw-r--r--  1 brettmorgan  primarygroup  18607 21 Jul 13:45 package_config.json
-rw-r--r--  1 brettmorgan  primarygroup  16871 21 Jul 13:45 package_config_subset
-rw-r--r--  1 brettmorgan  primarygroup     13 21 Jul 13:45 version

What am I missing?

@ditman
Copy link
Member Author

ditman commented Jul 21, 2022

OK, switched to beta, and with your same pubspec.yaml, I only added an extra flutter clean (just in case the flutter tool decided that the app hadn't changed or something); here's what I see:

$ flutter --version
Flutter 3.3.0-0.0.pre • channel unknown • unknown source
Framework • revision f90da9b167 (2 days ago) • 2022-07-18 18:59:23 -0700
Engine • revision 1388adb442
Tools • Dart 2.18.0 (build 2.18.0-271.2.beta) • DevTools 2.15.0

$ rm ~/github/flutter/bin/cache/flutter_tools.*
$ flutter clean
Building flutter tool...
Deleting .dart_tool...                                               3ms
Deleting Generated.xcconfig...                                       0ms
Deleting flutter_export_environment.sh...                            0ms
Deleting ephemeral...                                                0ms
Deleting ephemeral...                                                0ms
Deleting ephemeral...                                                0ms
Deleting .flutter-plugins-dependencies...                            0ms
Deleting .flutter-plugins...                                         0ms

$ ls .dart_tool
ls: cannot access '.dart_tool': No such file or directory

$ flutter pub get
Running "flutter pub get" in simple_project...                   1,487ms

$ cat .dart_tool/dartpad/web_plugin_registrant.dart 
// Flutter web plugin registrant file.
//
// Generated file. Do not edit.
//

// ignore_for_file: type=lint

import 'package:cloud_firestore_web/cloud_firestore_web.dart';
import 'package:firebase_analytics_web/firebase_analytics_web.dart';
import 'package:firebase_auth_web/firebase_auth_web.dart';
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:firebase_database_web/firebase_database_web.dart';
import 'package:firebase_messaging_web/firebase_messaging_web.dart';
import 'package:firebase_storage_web/firebase_storage_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

void registerPlugins([final Registrar? pluginRegistrar]) {
  final Registrar registrar = pluginRegistrar ?? webPluginRegistrar;
  FirebaseFirestoreWeb.registerWith(registrar);
  FirebaseAnalyticsWeb.registerWith(registrar);
  FirebaseAuthWeb.registerWith(registrar);
  FirebaseCoreWeb.registerWith(registrar);
  FirebaseDatabaseWeb.registerWith(registrar);
  FirebaseMessagingWeb.registerWith(registrar);
  FirebaseStorageWeb.registerWith(registrar);
  registrar.registerMessageHandler();
}

😰

@ditman
Copy link
Member Author

ditman commented Jul 22, 2022

@domesticmouse finally found the bit that determines if a project needs web support or not:

/// Whether this flutter project has a web sub-project.
@override
bool existsSync() {
return parent.directory.childDirectory('web').existsSync()
&& indexFile.existsSync();
}

The tool checks that web/index.html exists, but it doesn't look inside the file at all.

@jmagman jmagman mentioned this pull request Aug 9, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 30, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web][tool] Generate a dartpad_plugin_registrant.dart with flutter pub get

3 participants