-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
-
Dart SDK version: 3.9.2 (stable) (Wed Aug 27 03:49:40 2025 -0700) on "windows_x64"
-
repro:
The following is demonstrated using vscode. In addition, after my tests, the same problem will occur in IDEA and Android Studio
-
problem:
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(),
// Here is a redundant comma that will cause the code to not be formatted correctly.
// Manually deleting it manually when there are fewer parameters,
// but when there are many parameters, it will make the entire line of code very long
// and it is impossible to simply format the document to make it automatically wrap
// the line to facilitate code writing
// ↓
body: FilledButton(onPressed: () { },, child: null,),
),
);
}
}

-
expected:
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(),
body: FilledButton(onPressed: () {}, child: null,),
),
);
}
}
-
solution
We can see the problem in the refactoring preview

Then I targeted the "compute" function in "add_missing_required_argument.dart" and found that the problem seems to be in this code of line 143
if ((arguments.isNotEmpty || index > 0) && !insertBetweenParams) {
builder.write(', ');
}
I think it should be modified like this
if (arguments.isNotEmpty && !hasTrailingComma && !insertBetweenParams) {
builder.write(', ');
}
I removed the "index" variable here, and this variable has not been used elsewhere in this "for" loop, so the code of line 94 might be changed like this
// before
for (var (index, diagnostic) in diagnostics.indexed) {
// after
for (final diagnostic in diagnostics) {
-
consultation
I would like to ask how to become a contributor to this project, and I found that it seems that all pull requests are closed. Is it possible that even if the pull request is closed, as long as the "Gerrit for code reviews" is approved, I can become a member of the contributor?