-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Open
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterc: tech-debtTechnical debt, code quality, testing, etc.Technical debt, code quality, testing, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.refactorImproving readability/efficiency without behavioral changesImproving readability/efficiency without behavioral changesteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
before
class _MyState extends State<MyWidget> with SingleTickerProviderMixin {
late final int _value;
AnimationController? _controller;
@override
void initState() {
_value = widget.value;
_controller = AnimationController(
duration: Durations.medium1,
vsync: this,
);
}
// ...
}after
class _MyState extends State<MyWidget> with SingleTickerProviderMixin {
late final int _value = widget.value;
late final AnimationController _controller = AnimationController(
duration: Durations.medium1,
vsync: this,
);
// ...
}This has a few advantages:
- More concise
- Less jumping around to see how fields are initialized
- Less prone to late initialization errors
- The prefer final & unnecessary nullable lints will kick in
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterc: tech-debtTechnical debt, code quality, testing, etc.Technical debt, code quality, testing, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.refactorImproving readability/efficiency without behavioral changesImproving readability/efficiency without behavioral changesteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team