Convert 'key' to a super parameter warning -- how to change existing super calls to use super named parameters?

Viewed 18
class FooPage extends StatefulWidget {
  const FooPage(Key? key) : super(key: key);

  @override
  State<FooPage> createState() => _FooPageState();
}

Is there any dart fix xyz command I can use to convert all the super(key:key) calls to super.key?

In other words:

Before:

const FooPage({Key? key}) : super(key: key);

After:

const FooPage({super.key});
1 Answers

Add this linter rule to your analysis_options.yaml file:

linter:
  rules:
    use_super_parameters: true

Now run

dart fix --apply --code use_super_parameters 
Related