-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: first hourThe first hour of using FlutterThe first hour of using Flutterteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtriaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
Description
Flutter's templates used by flutter create should be up-to-date with the latest dart format.
Work
- Update Flutter's templates to the latest
dart formatstyle - Consider adding tests that verify Flutter's templates are up-to-date. (This might cause friction in Dart rolls that change
dart format's style. This might not be desirable. It's not the end of the world if the templates are behind)
Repro steps
Commands to check if templates are up-to-date...
# Create a directory to test the templates
rm -rf templates_test
mkdir templates_test
cd templates_test
# Create the templates
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
# Use git to check for changes
git init
git add .
git commit -m "Start"
# Format the templates
dart format .
# Check for "unexpected" changes:
git diffExpected results
Running dart format results in no "unexpected" changes.
Note: some dart format changes are expected:
- The templates depend on inputs like the project's name. Using a long project name can result in long lines that are affected by
dart format. - Code generated by tools like
ffigen
Actual
Running dart format results in "unexpected" changes:
Diff of template changes...
diff --git a/empty_app/lib/main.dart b/empty_app/lib/main.dart
index a725658..640824f 100644
--- a/empty_app/lib/main.dart
+++ b/empty_app/lib/main.dart
@@ -10,11 +10,7 @@ class MainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
- home: Scaffold(
- body: Center(
- child: Text('Hello World!'),
- ),
- ),
+ home: Scaffold(body: Center(child: Text('Hello World!'))),
);
}
}
diff --git a/my_ffi_package/example/lib/main.dart b/my_ffi_package/example/lib/main.dart
index b5e5f32..108180a 100644
--- a/my_ffi_package/example/lib/main.dart
+++ b/my_ffi_package/example/lib/main.dart
@@ -31,9 +31,7 @@ class _MyAppState extends State<MyApp> {
const spacerSmall = SizedBox(height: 10);
return MaterialApp(
home: Scaffold(
- appBar: AppBar(
- title: const Text('Native Packages'),
- ),
+ appBar: AppBar(title: const Text('Native Packages')),
body: SingleChildScrollView(
child: Container(
padding: const .all(10),
@@ -55,8 +53,9 @@ class _MyAppState extends State<MyApp> {
FutureBuilder<int>(
future: sumAsyncResult,
builder: (BuildContext context, AsyncSnapshot<int> value) {
- final displayValue =
- (value.hasData) ? value.data : 'loading';
+ final displayValue = (value.hasData)
+ ? value.data
+ : 'loading';
return Text(
'await sumAsync(3, 4) = $displayValue',
style: textStyle,
diff --git a/my_ffi_package/hook/build.dart b/my_ffi_package/hook/build.dart
index d8f0bce..ed5d839 100644
--- a/my_ffi_package/hook/build.dart
+++ b/my_ffi_package/hook/build.dart
@@ -8,9 +8,7 @@ void main(List<String> args) async {
final cbuilder = CBuilder.library(
name: packageName,
assetName: '${packageName}_bindings_generated.dart',
- sources: [
- 'src/$packageName.c',
- ],
+ sources: ['src/$packageName.c'],
);
await cbuilder.run(
input: input,
diff --git a/my_ffi_package/lib/my_ffi_package_bindings_generated.dart b/my_ffi_package/lib/my_ffi_package_bindings_generated.dart
index 65642b4..d61c422 100644
--- a/my_ffi_package/lib/my_ffi_package_bindings_generated.dart
+++ b/my_ffi_package/lib/my_ffi_package_bindings_generated.dart
@@ -13,10 +13,7 @@ import 'dart:ffi' as ffi;
/// They will block the Dart execution while running the native function, so
/// only do this for native functions which are guaranteed to be short-lived.
@ffi.Native<ffi.IntPtr Function(ffi.IntPtr, ffi.IntPtr)>()
-external int sum(
- int a,
- int b,
-);
+external int sum(int a, int b);
/// A longer lived native function, which occupies the thread calling it.
///
@@ -24,7 +21,4 @@ external int sum(
/// block Dart execution. This will cause dropped frames in Flutter applications.
/// Instead, call these native functions on a separate isolate.
@ffi.Native<ffi.IntPtr Function(ffi.IntPtr, ffi.IntPtr)>()
-external int sum_long_running(
- int a,
- int b,
-);
+external int sum_long_running(int a, int b);
diff --git a/my_ffi_plugin/example/lib/main.dart b/my_ffi_plugin/example/lib/main.dart
index eb0f47c..c197f07 100644
--- a/my_ffi_plugin/example/lib/main.dart
+++ b/my_ffi_plugin/example/lib/main.dart
@@ -31,9 +31,7 @@ class _MyAppState extends State<MyApp> {
const spacerSmall = SizedBox(height: 10);
return MaterialApp(
home: Scaffold(
- appBar: AppBar(
- title: const Text('Native Packages'),
- ),
+ appBar: AppBar(title: const Text('Native Packages')),
body: SingleChildScrollView(
child: Container(
padding: const .all(10),
@@ -55,8 +53,9 @@ class _MyAppState extends State<MyApp> {
FutureBuilder<int>(
future: sumAsyncResult,
builder: (BuildContext context, AsyncSnapshot<int> value) {
- final displayValue =
- (value.hasData) ? value.data : 'loading';
+ final displayValue = (value.hasData)
+ ? value.data
+ : 'loading';
return Text(
'await sumAsync(3, 4) = $displayValue',
style: textStyle,
diff --git a/my_ffi_plugin/lib/my_ffi_plugin.dart b/my_ffi_plugin/lib/my_ffi_plugin.dart
index 8e6248d..435d651 100644
--- a/my_ffi_plugin/lib/my_ffi_plugin.dart
+++ b/my_ffi_plugin/lib/my_ffi_plugin.dart
@@ -58,7 +58,6 @@ final DynamicLibrary _dylib = () {
/// The bindings to the native functions in [_dylib].
final MyFfiPluginBindings _bindings = MyFfiPluginBindings(_dylib);
-
/// A request to compute `sum`.
///
/// Typically sent from one isolate to another.
diff --git a/my_ffi_plugin/lib/my_ffi_plugin_bindings_generated.dart b/my_ffi_plugin/lib/my_ffi_plugin_bindings_generated.dart
index f198a2f..404a609 100644
--- a/my_ffi_plugin/lib/my_ffi_plugin_bindings_generated.dart
+++ b/my_ffi_plugin/lib/my_ffi_plugin_bindings_generated.dart
@@ -15,31 +15,24 @@ import 'dart:ffi' as ffi;
class MyFfiPluginBindings {
/// Holds the symbol lookup function.
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
- _lookup;
+ _lookup;
/// The symbols are looked up in [dynamicLibrary].
MyFfiPluginBindings(ffi.DynamicLibrary dynamicLibrary)
- : _lookup = dynamicLibrary.lookup;
+ : _lookup = dynamicLibrary.lookup;
/// The symbols are looked up with [lookup].
MyFfiPluginBindings.fromLookup(
- ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
- lookup)
- : _lookup = lookup;
+ ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName) lookup,
+ ) : _lookup = lookup;
/// A very short-lived native function.
///
/// For very short-lived functions, it is fine to call them on the main isolate.
/// They will block the Dart execution while running the native function, so
/// only do this for native functions which are guaranteed to be short-lived.
- int sum(
- int a,
- int b,
- ) {
- return _sum(
- a,
- b,
- );
+ int sum(int a, int b) {
+ return _sum(a, b);
}
late final _sumPtr =
@@ -51,19 +44,14 @@ class MyFfiPluginBindings {
/// Do not call these kind of native functions in the main isolate. They will
/// block Dart execution. This will cause dropped frames in Flutter applications.
/// Instead, call these native functions on a separate isolate.
- int sum_long_running(
- int a,
- int b,
- ) {
- return _sum_long_running(
- a,
- b,
- );
+ int sum_long_running(int a, int b) {
+ return _sum_long_running(a, b);
}
late final _sum_long_runningPtr =
_lookup<ffi.NativeFunction<ffi.Int Function(ffi.Int, ffi.Int)>>(
- 'sum_long_running');
- late final _sum_long_running =
- _sum_long_runningPtr.asFunction<int Function(int, int)>();
+ 'sum_long_running',
+ );
+ late final _sum_long_running = _sum_long_runningPtr
+ .asFunction<int Function(int, int)>();
}
diff --git a/my_plugin/example/integration_test/plugin_integration_test.dart b/my_plugin/example/integration_test/plugin_integration_test.dart
index e05450d..f8678b5 100644
--- a/my_plugin/example/integration_test/plugin_integration_test.dart
+++ b/my_plugin/example/integration_test/plugin_integration_test.dart
@@ -6,7 +6,6 @@
// For more information about Flutter integration tests, please see
// https://flutter.dev/to/integration-testing
-
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
diff --git a/my_plugin/example/lib/main.dart b/my_plugin/example/lib/main.dart
index 6778945..4482100 100644
--- a/my_plugin/example/lib/main.dart
+++ b/my_plugin/example/lib/main.dart
@@ -51,12 +51,8 @@ class _MyAppState extends State<MyApp> {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
- appBar: AppBar(
- title: const Text('Plugin example app'),
- ),
- body: Center(
- child: Text('Running on: $_platformVersion\n'),
- ),
+ appBar: AppBar(title: const Text('Plugin example app')),
+ body: Center(child: Text('Running on: $_platformVersion\n')),
),
);
}
diff --git a/my_plugin/example/test/widget_test.dart b/my_plugin/example/test/widget_test.dart
index 5456e0f..41bbed2 100644
--- a/my_plugin/example/test/widget_test.dart
+++ b/my_plugin/example/test/widget_test.dart
@@ -18,8 +18,8 @@ void main() {
// Verify that platform version is retrieved.
expect(
find.byWidgetPredicate(
- (Widget widget) => widget is Text &&
- widget.data!.startsWith('Running on:'),
+ (Widget widget) =>
+ widget is Text && widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
diff --git a/my_plugin/lib/my_plugin.dart b/my_plugin/lib/my_plugin.dart
index c547b30..86c6955 100644
--- a/my_plugin/lib/my_plugin.dart
+++ b/my_plugin/lib/my_plugin.dart
@@ -1,4 +1,3 @@
-
import 'my_plugin_platform_interface.dart';
class MyPlugin {
diff --git a/my_plugin/lib/my_plugin_method_channel.dart b/my_plugin/lib/my_plugin_method_channel.dart
index 7adf03f..d21f001 100644
--- a/my_plugin/lib/my_plugin_method_channel.dart
+++ b/my_plugin/lib/my_plugin_method_channel.dart
@@ -11,7 +11,9 @@ class MethodChannelMyPlugin extends MyPluginPlatform {
@override
Future<String?> getPlatformVersion() async {
- final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
+ final version = await methodChannel.invokeMethod<String>(
+ 'getPlatformVersion',
+ );
return version;
}
}
diff --git a/my_plugin/test/my_plugin_method_channel_test.dart b/my_plugin/test/my_plugin_method_channel_test.dart
index 48102c4..ea592db 100644
--- a/my_plugin/test/my_plugin_method_channel_test.dart
+++ b/my_plugin/test/my_plugin_method_channel_test.dart
@@ -9,16 +9,15 @@ void main() {
const MethodChannel channel = MethodChannel('my_plugin');
setUp(() {
- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
- channel,
- (MethodCall methodCall) async {
- return '42';
- },
- );
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(channel, (MethodCall methodCall) async {
+ return '42';
+ });
});
tearDown(() {
- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
+ .setMockMethodCallHandler(channel, null);
});
test('getPlatformVersion', () async {
diff --git a/my_plugin/test/my_plugin_test.dart b/my_plugin/test/my_plugin_test.dart
index 8bbb8fc..5b0b86b 100644
--- a/my_plugin/test/my_plugin_test.dart
+++ b/my_plugin/test/my_plugin_test.dart
@@ -7,7 +7,6 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockMyPluginPlatform
with MockPlatformInterfaceMixin
implements MyPluginPlatform {
-
@override
Future<String?> getPlatformVersion() => Future.value('42');
}
justinmc and robert-ancell
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: first hourThe first hour of using FlutterThe first hour of using Flutterteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtriaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team