Skip to content

Commit 3179875

Browse files
authored
replace some ._() constructors with class modifiers (#122765)
1 parent 7b7af9f commit 3179875

37 files changed

+45
-204
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ linter:
4242
- avoid_bool_literals_in_conditional_expressions
4343
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
4444
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
45-
- avoid_classes_with_only_static_members
45+
# avoid_classes_with_only_static_members # # we do this commonly for `abstract final class`es
4646
- avoid_double_and_int_checks
4747
- avoid_dynamic_calls
4848
- avoid_empty_else

dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ class BenchMouseRegionGridHover extends WidgetRecorder {
116116
}
117117
}
118118

119-
class _UntilNextFrame {
120-
_UntilNextFrame._();
121-
119+
abstract final class _UntilNextFrame {
122120
static Completer<void>? _completer;
123121

124122
static Future<void> wait() {

dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ class BenchMouseRegionGridScroll extends WidgetRecorder {
8888
}
8989
}
9090

91-
class _UntilNextFrame {
92-
_UntilNextFrame._();
93-
91+
abstract final class _UntilNextFrame {
9492
static Completer<void>? _completer;
9593

9694
static Future<void> wait() {

dev/integration_tests/flutter_gallery/lib/gallery/icons.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
import 'package:flutter/material.dart';
66

7-
class GalleryIcons {
8-
// This class is not meant to be instantiated or extended; this constructor
9-
// prevents instantiation and extension.
10-
GalleryIcons._();
11-
7+
abstract final class GalleryIcons {
128
static const IconData tooltip = IconData(0xe900, fontFamily: 'GalleryIcons');
139
static const IconData text_fields_alt = IconData(0xe901, fontFamily: 'GalleryIcons');
1410
static const IconData tabs = IconData(0xe902, fontFamily: 'GalleryIcons');

packages/flutter/lib/src/animation/curves.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,11 +1353,7 @@ class ElasticInOutCurve extends Curve {
13531353
///
13541354
/// * [Curve], the interface implemented by the constants available from the
13551355
/// [Curves] class.
1356-
class Curves {
1357-
// This class is not meant to be instantiated or extended; this constructor
1358-
// prevents instantiation and extension.
1359-
Curves._();
1360-
1356+
abstract final class Curves {
13611357
/// A linear animation curve.
13621358
///
13631359
/// This is the identity map over the unit interval: its [Curve.transform]

packages/flutter/lib/src/cupertino/colors.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ import 'theme.dart';
3737
/// ### Background Colors
3838
/// ![](https://flutter.github.io/assets-for-api-docs/assets/cupertino/cupertino_background_colors.png)
3939
///
40-
class CupertinoColors {
41-
// This class is not meant to be instantiated or extended; this constructor
42-
// prevents instantiation and extension.
43-
CupertinoColors._();
44-
40+
abstract final class CupertinoColors {
4541
/// iOS 13's default blue color. Used to indicate active elements such as
4642
/// buttons, selected tabs and your own chat bubbles.
4743
///

packages/flutter/lib/src/cupertino/icons.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ import 'package:flutter/widgets.dart';
6060
///
6161
/// * [Icon], used to show these icons.
6262
@staticIconProvider
63-
class CupertinoIcons {
64-
// This class is not meant to be instantiated or extended; this constructor
65-
// prevents instantiation and extension.
66-
CupertinoIcons._();
67-
63+
abstract final class CupertinoIcons {
6864
/// The icon font used for Cupertino icons.
6965
static const String iconFont = 'CupertinoIcons';
7066

packages/flutter/lib/src/foundation/licenses.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,7 @@ class LicenseEntryWithLineBreaks extends LicenseEntry {
282282
/// uses this API to select licenses to show.
283283
/// * [AboutListTile], which is a widget that can be added to a [Drawer]. When
284284
/// tapped it calls [showAboutDialog].
285-
class LicenseRegistry {
286-
// This class is not meant to be instantiated or extended; this constructor
287-
// prevents instantiation and extension.
288-
LicenseRegistry._();
289-
285+
abstract final class LicenseRegistry {
290286
static List<LicenseEntryCollector>? _collectors;
291287

292288
/// Adds licenses to the registry.

packages/flutter/lib/src/foundation/unicode.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
///
1111
/// * <http://unicode.org/reports/tr9/>, which describes the Unicode
1212
/// bidirectional text algorithm.
13-
class Unicode {
14-
// This class is not meant to be instantiated or extended; this constructor
15-
// prevents instantiation and extension.
16-
Unicode._();
13+
abstract final class Unicode {
1714
/// `U+202A LEFT-TO-RIGHT EMBEDDING`
1815
///
1916
/// Treat the following text as embedded left-to-right.

packages/flutter/lib/src/gestures/converter.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ int _synthesiseDownButtons(int buttons, PointerDeviceKind kind) {
3737
/// This takes [PointerDataPacket] objects, as received from the engine via
3838
/// [dart:ui.PlatformDispatcher.onPointerDataPacket], and converts them to
3939
/// [PointerEvent] objects.
40-
class PointerEventConverter {
41-
// This class is not meant to be instantiated or extended; this constructor
42-
// prevents instantiation and extension.
43-
PointerEventConverter._();
44-
40+
abstract final class PointerEventConverter {
4541
/// Expand the given packet of pointer data into a sequence of framework
4642
/// pointer events.
4743
///

packages/flutter/lib/src/gestures/hit_test.dart

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ export 'package:vector_math/vector_math_64.dart' show Matrix4;
1515
export 'events.dart' show PointerEvent;
1616

1717
/// An object that can hit-test pointers.
18-
abstract class HitTestable {
19-
// This class is intended to be used as an interface, and should not be
20-
// extended directly; this constructor prevents instantiation and extension.
21-
HitTestable._();
22-
18+
abstract interface class HitTestable {
2319
/// Check whether the given position hits this object.
2420
///
2521
/// If this given position hits this object, consider adding a [HitTestEntry]
@@ -28,21 +24,13 @@ abstract class HitTestable {
2824
}
2925

3026
/// An object that can dispatch events.
31-
abstract class HitTestDispatcher {
32-
// This class is intended to be used as an interface, and should not be
33-
// extended directly; this constructor prevents instantiation and extension.
34-
HitTestDispatcher._();
35-
27+
abstract interface class HitTestDispatcher {
3628
/// Override this method to dispatch events.
3729
void dispatchEvent(PointerEvent event, HitTestResult result);
3830
}
3931

4032
/// An object that can handle events.
41-
abstract class HitTestTarget {
42-
// This class is intended to be used as an interface, and should not be
43-
// extended directly; this constructor prevents instantiation and extension.
44-
HitTestTarget._();
45-
33+
abstract interface class HitTestTarget {
4634
/// Override this method to receive events.
4735
void handleEvent(PointerEvent event, HitTestEntry<HitTestTarget> entry);
4836
}

packages/flutter/lib/src/material/animated_icons/animated_icons_data.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ part of material_animated_icons; // ignore: use_string_in_part_of_directives
2424
/// See also:
2525
///
2626
/// * [Icons], for the list of available static Material Icons.
27-
abstract class AnimatedIcons {
28-
// This class is not meant to be instantiated or extended; this constructor
29-
// prevents instantiation and extension.
30-
AnimatedIcons._();
31-
27+
abstract final class AnimatedIcons {
3228
/// The Material Design add to event icon animation.
3329
///
3430
/// {@animation 72 72 https://flutter.github.io/assets-for-api-docs/assets/widgets/add_event.mp4}

packages/flutter/lib/src/material/chip.dart

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ const Icon _kDefaultDeleteIcon = Icon(Icons.cancel, size: _kDeleteIconSize);
6262
/// * [FilterChip], uses tags or descriptive words as a way to filter content.
6363
/// * [ActionChip], represents an action related to primary content.
6464
/// * <https://material.io/design/components/chips.html>
65-
abstract class ChipAttributes {
66-
// This class is intended to be used as an interface, and should not be
67-
// extended directly; this constructor prevents instantiation and extension.
68-
ChipAttributes._();
69-
65+
abstract interface class ChipAttributes {
7066
/// The primary content of the chip.
7167
///
7268
/// Typically a [Text] widget.
@@ -214,11 +210,7 @@ abstract class ChipAttributes {
214210
/// as an entity (person, place, or thing) or conversational text, in a
215211
/// compact form.
216212
/// * <https://material.io/design/components/chips.html>
217-
abstract class DeletableChipAttributes {
218-
// This class is intended to be used as an interface, and should not be
219-
// extended directly; this constructor prevents instantiation and extension.
220-
DeletableChipAttributes._();
221-
213+
abstract interface class DeletableChipAttributes {
222214
/// The icon displayed when [onDeleted] is set.
223215
///
224216
/// Defaults to an [Icon] widget set to use [Icons.cancel].
@@ -284,11 +276,7 @@ abstract class DeletableChipAttributes {
284276
/// compact form.
285277
/// * [FilterChip], uses tags or descriptive words as a way to filter content.
286278
/// * <https://material.io/design/components/chips.html>
287-
abstract class CheckmarkableChipAttributes {
288-
// This class is intended to be used as an interface, and should not be
289-
// extended directly; this constructor prevents instantiation and extension.
290-
CheckmarkableChipAttributes._();
291-
279+
abstract interface class CheckmarkableChipAttributes {
292280
/// Whether or not to show a check mark when
293281
/// [SelectableChipAttributes.selected] is true.
294282
///
@@ -319,11 +307,7 @@ abstract class CheckmarkableChipAttributes {
319307
/// chips contain related descriptive text or categories.
320308
/// * [FilterChip], uses tags or descriptive words as a way to filter content.
321309
/// * <https://material.io/design/components/chips.html>
322-
abstract class SelectableChipAttributes {
323-
// This class is intended to be used as an interface, and should not be
324-
// extended directly; this constructor prevents instantiation and extension.
325-
SelectableChipAttributes._();
326-
310+
abstract interface class SelectableChipAttributes {
327311
/// Whether or not this chip is selected.
328312
///
329313
/// If [onSelected] is not null, this value will be used to determine if the
@@ -429,11 +413,7 @@ abstract class SelectableChipAttributes {
429413
/// chips contain related descriptive text or categories.
430414
/// * [FilterChip], uses tags or descriptive words as a way to filter content.
431415
/// * <https://material.io/design/components/chips.html>
432-
abstract class DisabledChipAttributes {
433-
// This class is intended to be used as an interface, and should not be
434-
// extended directly; this constructor prevents instantiation and extension.
435-
DisabledChipAttributes._();
436-
416+
abstract interface class DisabledChipAttributes {
437417
/// Whether or not this chip is enabled for input.
438418
///
439419
/// If this is true, but all of the user action callbacks are null (i.e.
@@ -477,11 +457,7 @@ abstract class DisabledChipAttributes {
477457
/// * [FilterChip], uses tags or descriptive words as a way to filter content.
478458
/// * [ActionChip], represents an action related to primary content.
479459
/// * <https://material.io/design/components/chips.html>
480-
abstract class TappableChipAttributes {
481-
// This class is intended to be used as an interface, and should not be
482-
// extended directly; this constructor prevents instantiation and extension.
483-
TappableChipAttributes._();
484-
460+
abstract interface class TappableChipAttributes {
485461
/// Called when the user taps the chip.
486462
///
487463
/// If [onPressed] is set, then this callback will be called when the user

packages/flutter/lib/src/material/colors.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ class MaterialAccentColor extends ColorSwatch<int> {
190190
/// See also:
191191
///
192192
/// * Cookbook: [Use themes to share colors and font styles](https://flutter.dev/docs/cookbook/design/themes)
193-
class Colors {
194-
// This class is not meant to be instantiated or extended; this constructor
195-
// prevents instantiation and extension.
196-
Colors._();
197-
193+
abstract final class Colors {
198194
/// Completely invisible.
199195
static const Color transparent = Color(0x00000000);
200196

packages/flutter/lib/src/material/date.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import 'package:flutter/foundation.dart';
77
import 'material_localizations.dart';
88

99
/// Utility functions for working with dates.
10-
class DateUtils {
11-
// This class is not meant to be instantiated or extended; this constructor
12-
// prevents instantiation and extension.
13-
DateUtils._();
14-
10+
abstract final class DateUtils {
1511
/// Returns a [DateTime] with the date of the original, but time set to
1612
/// midnight.
1713
static DateTime dateOnly(DateTime date) {

packages/flutter/lib/src/material/elevation_overlay.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ import 'theme.dart';
1111

1212
/// A utility class for dealing with the overlay color needed
1313
/// to indicate elevation of surfaces.
14-
class ElevationOverlay {
15-
// This class is not meant to be instantiated or extended; this constructor
16-
// prevents instantiation and extension.
17-
ElevationOverlay._();
18-
14+
abstract final class ElevationOverlay {
1915
/// Applies a surface tint color to a given container color to indicate
2016
/// the level of its elevation.
2117
///

packages/flutter/lib/src/material/feedback.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ import 'theme.dart';
8181
/// }
8282
/// ```
8383
/// {@end-tool}
84-
class Feedback {
85-
// This class is not meant to be instantiated or extended; this constructor
86-
// prevents instantiation and extension.
87-
Feedback._();
88-
84+
abstract final class Feedback {
8985
/// Provides platform-specific feedback for a tap.
9086
///
9187
/// On Android the click system sound is played. On iOS this is a no-op.

packages/flutter/lib/src/material/icons.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:flutter/widgets.dart';
1010
/// A set of platform-adaptive Material Design icons.
1111
///
1212
/// Use [Icons.adaptive] to access a static instance of this class.
13-
class PlatformAdaptiveIcons implements Icons {
13+
final class PlatformAdaptiveIcons implements Icons {
1414
const PlatformAdaptiveIcons._();
1515

1616
static bool _isCupertino() {
@@ -150,11 +150,7 @@ class PlatformAdaptiveIcons implements Icons {
150150
/// * <https://material.io/resources/icons>
151151
/// * [AnimatedIcons], for the list of available animated Material Icons.
152152
@staticIconProvider
153-
class Icons {
154-
// This class is not meant to be instantiated or extended; this constructor
155-
// prevents instantiation and extension.
156-
Icons._();
157-
153+
abstract final class Icons {
158154
/// A set of platform-adaptive Material Design icons.
159155
///
160156
/// Provides a convenient way to show a certain set of platform-appropriate

packages/flutter/lib/src/painting/matrix_utils.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import 'package:vector_math/vector_math_64.dart';
88
import 'basic_types.dart';
99

1010
/// Utility functions for working with matrices.
11-
class MatrixUtils {
12-
// This class is not meant to be instantiated or extended; this constructor
13-
// prevents instantiation and extension.
14-
MatrixUtils._();
15-
11+
abstract final class MatrixUtils {
1612
/// Returns the given [transform] matrix as an [Offset], if the matrix is
1713
/// nothing but a 2D translation.
1814
///

packages/flutter/lib/src/rendering/layout_helper.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ typedef ChildLayouter = Size Function(RenderBox child, BoxConstraints constraint
1717
/// given set of [BoxConstraints].
1818
///
1919
/// All of the functions adhere to the [ChildLayouter] signature.
20-
class ChildLayoutHelper {
21-
// This class is not meant to be instantiated or extended; this constructor
22-
// prevents instantiation and extension.
23-
const ChildLayoutHelper._();
24-
20+
abstract final class ChildLayoutHelper {
2521
/// Returns the [Size] that the [RenderBox] would have if it were to
2622
/// be laid out with the given [BoxConstraints].
2723
///

packages/flutter/lib/src/rendering/selection.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ mixin SelectionRegistrant on Selectable {
206206
}
207207

208208
/// A utility class that provides useful methods for handling selection events.
209-
class SelectionUtils {
210-
SelectionUtils._();
211-
209+
abstract final class SelectionUtils {
212210
/// Determines [SelectionResult] purely based on the target rectangle.
213211
///
214212
/// This method returns [SelectionResult.end] if the `point` is inside the

packages/flutter/lib/src/rendering/viewport.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ enum CacheExtentStyle {
2929
/// content, which can be controlled by a [ViewportOffset]. This interface lets
3030
/// the framework recognize such render objects and interact with them without
3131
/// having specific knowledge of all the various types of viewports.
32-
abstract class RenderAbstractViewport extends RenderObject {
33-
// This class is intended to be used as an interface, and should not be
34-
// extended directly; this constructor prevents instantiation and extension.
35-
RenderAbstractViewport._();
36-
32+
abstract interface class RenderAbstractViewport extends RenderObject {
3733
/// Returns the [RenderAbstractViewport] that most tightly encloses the given
3834
/// render object.
3935
///

packages/flutter/lib/src/semantics/semantics_service.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ export 'dart:ui' show TextDirection;
1717
///
1818
/// When possible, prefer using mechanisms like [Semantics] to implicitly
1919
/// trigger announcements over using this event.
20-
class SemanticsService {
21-
// This class is not meant to be instantiated or extended; this constructor
22-
// prevents instantiation and extension.
23-
SemanticsService._();
24-
20+
abstract final class SemanticsService {
2521
/// Sends a semantic announcement.
2622
///
2723
/// This should be used for announcement that are not seamlessly announced by

packages/flutter/lib/src/services/clipboard.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ class ClipboardData {
2121
}
2222

2323
/// Utility methods for interacting with the system's clipboard.
24-
class Clipboard {
25-
// This class is not meant to be instantiated or extended; this constructor
26-
// prevents instantiation and extension.
27-
Clipboard._();
28-
24+
abstract final class Clipboard {
2925
// Constants for common [getData] [format] types.
3026

3127
/// Plain text data format string.

0 commit comments

Comments
 (0)