diff --git a/dev/bots/analyze_snippet_code.dart b/dev/bots/analyze_snippet_code.dart index 4b635c90586e..b2bae35d7cdb 100644 --- a/dev/bots/analyze_snippet_code.dart +++ b/dev/bots/analyze_snippet_code.dart @@ -61,6 +61,11 @@ // contains no explicit imports, the snippets will implicitly import all the // main Flutter packages (including material and flutter_test), as well as most // core Dart packages with the usual prefixes. +// +// When invoked without an additional path argument, the script will analyze +// the code snippets for all packages in the "packages" subdirectory that do +// not specify "nodoc: true" in their pubspec.yaml (i.e. all packages for which +// we publish docs will have their doc code snippets analyzed). import 'dart:async'; import 'dart:convert'; @@ -73,9 +78,6 @@ import 'package:watcher/watcher.dart'; final String _flutterRoot = path.dirname(path.dirname(path.dirname(path.fromUri(Platform.script)))); final String _packageFlutter = path.join(_flutterRoot, 'packages', 'flutter', 'lib'); -final String _packageFlutterTest = path.join(_flutterRoot, 'packages', 'flutter_test', 'lib'); -final String _packageFlutterDriver = path.join(_flutterRoot, 'packages', 'flutter_driver', 'lib'); -final String _packageIntegrationTest = path.join(_flutterRoot, 'packages', 'integration_test', 'lib'); final String _defaultDartUiLocation = path.join(_flutterRoot, 'bin', 'cache', 'pkg', 'sky_engine', 'lib', 'ui'); final String _flutter = path.join(_flutterRoot, 'bin', Platform.isWindows ? 'flutter.bat' : 'flutter'); @@ -147,18 +149,28 @@ Future main(List arguments) async { exit(0); } - List flutterPackages; + final List flutterPackages; if (parsedArguments.rest.length == 1) { // Used for testing. flutterPackages = [Directory(parsedArguments.rest.single)]; } else { - flutterPackages = [ - Directory(_packageFlutter), - Directory(_packageFlutterTest), - Directory(_packageIntegrationTest), - Directory(_packageFlutterDriver), - // TODO(goderbauer): Add all other packages for which we publish docs. - ]; + // By default analyze snippets in all packages in the packages subdirectory + // that do not specify "nodoc: true" in their pubspec.yaml. + flutterPackages = []; + final String packagesRoot = path.join(_flutterRoot, 'packages'); + for (final FileSystemEntity entity in Directory(packagesRoot).listSync()) { + if (entity is! Directory) { + continue; + } + final File pubspec = File(path.join(entity.path, 'pubspec.yaml')); + if (!pubspec.existsSync()) { + throw StateError("Unexpected package '${entity.path}' found in packages directory"); + } + if (!pubspec.readAsStringSync().contains('nodoc: true')) { + flutterPackages.add(Directory(path.join(entity.path, 'lib'))); + } + } + assert(flutterPackages.length >= 4); } final bool includeDartUi = parsedArguments.wasParsed('dart-ui-location') || parsedArguments['include-dart-ui'] as bool; diff --git a/examples/api/pubspec.yaml b/examples/api/pubspec.yaml index ccfd967cf3f2..bd4643727083 100644 --- a/examples/api/pubspec.yaml +++ b/examples/api/pubspec.yaml @@ -29,8 +29,12 @@ dev_dependencies: sdk: flutter flutter_goldens: sdk: flutter + flutter_localizations: + sdk: flutter flutter_test: sdk: flutter + flutter_web_plugins: + sdk: flutter test: 1.24.6 _fe_analyzer_shared: 64.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" diff --git a/packages/flutter_localizations/lib/src/cupertino_localizations.dart b/packages/flutter_localizations/lib/src/cupertino_localizations.dart index 4efbfb671c65..68a5c0bc8b0b 100644 --- a/packages/flutter_localizations/lib/src/cupertino_localizations.dart +++ b/packages/flutter_localizations/lib/src/cupertino_localizations.dart @@ -10,6 +10,10 @@ import 'l10n/generated_cupertino_localizations.dart'; import 'utils/date_localizations.dart' as util; import 'widgets_localizations.dart'; +// Examples can assume: +// import 'package:flutter_localizations/flutter_localizations.dart'; +// import 'package:flutter/cupertino.dart'; + /// Implementation of localized strings for Cupertino widgets using the `intl` /// package for date and time formatting. /// @@ -32,11 +36,11 @@ import 'widgets_localizations.dart'; /// app supports with [CupertinoApp.supportedLocales]: /// /// ```dart -/// CupertinoApp( +/// const CupertinoApp( /// localizationsDelegates: GlobalCupertinoLocalizations.delegates, -/// supportedLocales: [ -/// const Locale('en', 'US'), // American English -/// const Locale('he', 'IL'), // Israeli Hebrew +/// supportedLocales: [ +/// Locale('en', 'US'), // American English +/// Locale('he', 'IL'), // Israeli Hebrew /// // ... /// ], /// // ... @@ -432,11 +436,11 @@ abstract class GlobalCupertinoLocalizations implements CupertinoLocalizations { /// app supports with [CupertinoApp.supportedLocales]: /// /// ```dart - /// CupertinoApp( + /// const CupertinoApp( /// localizationsDelegates: GlobalCupertinoLocalizations.delegates, - /// supportedLocales: [ - /// const Locale('en', 'US'), // English - /// const Locale('he', 'IL'), // Hebrew + /// supportedLocales: [ + /// Locale('en', 'US'), // English + /// Locale('he', 'IL'), // Hebrew /// ], /// // ... /// ) diff --git a/packages/flutter_localizations/lib/src/material_localizations.dart b/packages/flutter_localizations/lib/src/material_localizations.dart index 477940e38497..e415db1726ba 100644 --- a/packages/flutter_localizations/lib/src/material_localizations.dart +++ b/packages/flutter_localizations/lib/src/material_localizations.dart @@ -11,6 +11,10 @@ import 'l10n/generated_material_localizations.dart'; import 'utils/date_localizations.dart' as util; import 'widgets_localizations.dart'; +// Examples can assume: +// import 'package:flutter_localizations/flutter_localizations.dart'; +// import 'package:flutter/material.dart'; + /// Implementation of localized strings for the material widgets using the /// `intl` package for date and time formatting. /// @@ -30,11 +34,11 @@ import 'widgets_localizations.dart'; /// app supports with [MaterialApp.supportedLocales]: /// /// ```dart -/// MaterialApp( +/// const MaterialApp( /// localizationsDelegates: GlobalMaterialLocalizations.delegates, -/// supportedLocales: [ -/// const Locale('en', 'US'), // American English -/// const Locale('he', 'IL'), // Israeli Hebrew +/// supportedLocales: [ +/// Locale('en', 'US'), // American English +/// Locale('he', 'IL'), // Israeli Hebrew /// // ... /// ], /// // ... @@ -681,11 +685,11 @@ abstract class GlobalMaterialLocalizations implements MaterialLocalizations { /// app supports with [MaterialApp.supportedLocales]: /// /// ```dart - /// MaterialApp( + /// const MaterialApp( /// localizationsDelegates: GlobalMaterialLocalizations.delegates, - /// supportedLocales: [ - /// const Locale('en', 'US'), // English - /// const Locale('he', 'IL'), // Hebrew + /// supportedLocales: [ + /// Locale('en', 'US'), // English + /// Locale('he', 'IL'), // Hebrew /// ], /// // ... /// ) diff --git a/packages/flutter_web_plugins/lib/src/navigation/url_strategy.dart b/packages/flutter_web_plugins/lib/src/navigation/url_strategy.dart index 427942a4a8d3..e0f0dbeaa81b 100644 --- a/packages/flutter_web_plugins/lib/src/navigation/url_strategy.dart +++ b/packages/flutter_web_plugins/lib/src/navigation/url_strategy.dart @@ -34,8 +34,10 @@ void usePathUrlStrategy() { /// ```dart /// import 'package:flutter_web_plugins/flutter_web_plugins.dart'; /// -/// // Somewhere before calling `runApp()` do: -/// setUrlStrategy(PathUrlStrategy()); +/// void main() { +/// // Somewhere before calling `runApp()` do: +/// setUrlStrategy(PathUrlStrategy()); +/// } /// ``` class PathUrlStrategy extends ui_web.HashUrlStrategy { /// Creates an instance of [PathUrlStrategy]. diff --git a/packages/flutter_web_plugins/lib/src/navigation_non_web/url_strategy.dart b/packages/flutter_web_plugins/lib/src/navigation_non_web/url_strategy.dart index f9622608bdac..0a4703b8120b 100644 --- a/packages/flutter_web_plugins/lib/src/navigation_non_web/url_strategy.dart +++ b/packages/flutter_web_plugins/lib/src/navigation_non_web/url_strategy.dart @@ -99,8 +99,10 @@ void usePathUrlStrategy() { /// ```dart /// import 'package:flutter_web_plugins/flutter_web_plugins.dart'; /// -/// // Somewhere before calling `runApp()` do: -/// setUrlStrategy(const HashUrlStrategy()); +/// void main() { +/// // Somewhere before calling `runApp()` do: +/// setUrlStrategy(const HashUrlStrategy()); +/// } /// ``` class HashUrlStrategy extends UrlStrategy { /// Creates an instance of [HashUrlStrategy]. @@ -117,8 +119,10 @@ class HashUrlStrategy extends UrlStrategy { /// ```dart /// import 'package:flutter_web_plugins/flutter_web_plugins.dart'; /// -/// // Somewhere before calling `runApp()` do: -/// setUrlStrategy(PathUrlStrategy()); +/// void main() { +/// // Somewhere before calling `runApp()` do: +/// setUrlStrategy(PathUrlStrategy()); +/// } /// ``` class PathUrlStrategy extends HashUrlStrategy { /// Creates an instance of [PathUrlStrategy]. diff --git a/packages/flutter_web_plugins/lib/src/plugin_registry.dart b/packages/flutter_web_plugins/lib/src/plugin_registry.dart index 78108b9699c3..a6ff602a4322 100644 --- a/packages/flutter_web_plugins/lib/src/plugin_registry.dart +++ b/packages/flutter_web_plugins/lib/src/plugin_registry.dart @@ -9,6 +9,12 @@ import 'dart:ui_web' as ui_web; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; +// Examples can assume: +// import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +// import 'package:flutter/services.dart'; +// import 'dart:ui_web' as ui_web; +// void handleFrameworkMessage(String name, ByteData? data, PlatformMessageResponseCallback? callback) { } + /// A registrar for Flutter plugins implemented in Dart. /// /// Plugins for the web platform are implemented in Dart and are @@ -32,6 +38,11 @@ import 'package:flutter/services.dart'; /// final MyPlugin instance = MyPlugin(); /// channel.setMethodCallHandler(instance.handleMethodCall); /// } +/// +/// Future handleMethodCall(MethodCall call) async { +/// // ... +/// } +/// /// // ... /// } /// ```