From 2d0fbe84764f96a7ffa7febd589e58775cc3477a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Sharma?= <737941+loic-sharma@users.noreply.github.com> Date: Wed, 24 Sep 2025 16:18:41 -0700 Subject: [PATCH] Update Flutter's templates to use dot shorthands (#175891) The next stable release of Flutter includes Dart's new dot shorthands feature. This updates Flutter's templates to use shorthands. For example, this updates the counter app that's generated by `flutter create`. This change does not affect the framework's style guide; Flutter's templates use a different style than the framework. For example, templates use things like implicit types ([example](https://github.com/flutter/flutter/blob/440e7c2978dddc6a0b9b213918c4fccf5cb93775/packages/flutter_tools/templates/app/lib/main.dart.tmpl#L234)). ### Testing To use these templates, run: ``` flutter create counter_app flutter create empty_app --empty flutter create my_package --template=package flutter create my_plugin --template=plugin --platforms=android,ios,linux,macos,windows flutter create my_ffi_package --template=package_ffi flutter create my_ffi_plugin --template=plugin_ffi flutter create my_module --template module ``` ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- .../flutter_tools/templates/app/lib/main.dart.tmpl | 12 ++++++------ .../templates/module/common/lib/main.dart.tmpl | 2 +- .../templates/package_ffi/hook/build.dart.tmpl | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/flutter_tools/templates/app/lib/main.dart.tmpl b/packages/flutter_tools/templates/app/lib/main.dart.tmpl index 90806145615..6048c886753 100644 --- a/packages/flutter_tools/templates/app/lib/main.dart.tmpl +++ b/packages/flutter_tools/templates/app/lib/main.dart.tmpl @@ -62,7 +62,7 @@ class MyApp extends StatelessWidget { // // This works for code too, not just values: Most code changes can be // tested with just a hot reload. - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + colorScheme: .fromSeed(seedColor: Colors.deepPurple), ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); @@ -136,7 +136,7 @@ class _MyHomePageState extends State { // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" // action in the IDE, or press "p" in the console), to see the // wireframe for each widget. - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: .center, children: [ const Text('You have pushed the button this many times:'), Text( @@ -240,20 +240,20 @@ class _MyAppState extends State { ), body: SingleChildScrollView( child: Container( - padding: const EdgeInsets.all(10), + padding: const .all(10), child: Column( children: [ const Text( 'This calls a native function through FFI that is shipped as source in the package. ' 'The native code is built as part of the Flutter Runner build.', style: textStyle, - textAlign: TextAlign.center, + textAlign: .center, ), spacerSmall, Text( 'sum(1, 2) = $sumResult', style: textStyle, - textAlign: TextAlign.center, + textAlign: .center, ), spacerSmall, FutureBuilder( @@ -264,7 +264,7 @@ class _MyAppState extends State { return Text( 'await sumAsync(3, 4) = $displayValue', style: textStyle, - textAlign: TextAlign.center, + textAlign: .center, ); }, ), diff --git a/packages/flutter_tools/templates/module/common/lib/main.dart.tmpl b/packages/flutter_tools/templates/module/common/lib/main.dart.tmpl index 8c81633ac67..14d21ea2751 100644 --- a/packages/flutter_tools/templates/module/common/lib/main.dart.tmpl +++ b/packages/flutter_tools/templates/module/common/lib/main.dart.tmpl @@ -97,7 +97,7 @@ class _MyHomePageState extends State { // center the children vertically; the main axis here is the vertical // axis because Columns are vertical (the cross axis would be // horizontal). - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: .center, children: [ const Text('You have pushed the button this many times:'), Text( diff --git a/packages/flutter_tools/templates/package_ffi/hook/build.dart.tmpl b/packages/flutter_tools/templates/package_ffi/hook/build.dart.tmpl index e33e0554bfc..d8f0bcef974 100644 --- a/packages/flutter_tools/templates/package_ffi/hook/build.dart.tmpl +++ b/packages/flutter_tools/templates/package_ffi/hook/build.dart.tmpl @@ -16,7 +16,7 @@ void main(List args) async { input: input, output: output, logger: Logger('') - ..level = Level.ALL + ..level = .ALL ..onRecord.listen((record) => print(record.message)), ); });