diff --git a/dev/conductor/core/bin/packages_autoroller.dart b/dev/conductor/core/bin/packages_autoroller.dart index 138bdf72935..cb39f2c45ae 100644 --- a/dev/conductor/core/bin/packages_autoroller.dart +++ b/dev/conductor/core/bin/packages_autoroller.dart @@ -76,7 +76,7 @@ ${parser.usage} final FrameworkRepository framework = FrameworkRepository( _localCheckouts(token), - mirrorRemote: Remote.mirror(mirrorUrl), + mirrorRemote: const Remote.mirror(mirrorUrl), upstreamRemote: Remote.upstream(upstreamUrl), ); diff --git a/dev/conductor/core/lib/src/repository.dart b/dev/conductor/core/lib/src/repository.dart index d11dc2ddfe3..26d7514cc60 100644 --- a/dev/conductor/core/lib/src/repository.dart +++ b/dev/conductor/core/lib/src/repository.dart @@ -23,25 +23,11 @@ enum RemoteName { } class Remote { - const Remote({ - required RemoteName name, - required this.url, - }) : _name = name, - assert(url != ''); + const Remote({required RemoteName name, required this.url}) + : _name = name, assert(url != ''); - factory Remote.mirror(String url) { - return Remote( - name: RemoteName.mirror, - url: url, - ); - } - - factory Remote.upstream(String url) { - return Remote( - name: RemoteName.upstream, - url: url, - ); - } + const Remote.mirror(String url) : this(name: RemoteName.mirror, url: url); + const Remote.upstream(String url) : this(name: RemoteName.upstream, url: url); final RemoteName _name; diff --git a/dev/devicelab/lib/framework/browser.dart b/dev/devicelab/lib/framework/browser.dart index bec06df2e25..d7ea4d3cc43 100644 --- a/dev/devicelab/lib/framework/browser.dart +++ b/dev/devicelab/lib/framework/browser.dart @@ -422,18 +422,6 @@ Duration _computeAverageDuration(List events) { /// See also: /// * https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview class BlinkTraceEvent { - BlinkTraceEvent._({ - required this.args, - required this.cat, - required this.name, - required this.ph, - this.pid, - this.tid, - this.ts, - this.tts, - this.tdur, - }); - /// Parses an event from its JSON representation. /// /// Sample event encoded as JSON (the data is bogus, this just shows the format): @@ -458,19 +446,16 @@ class BlinkTraceEvent { /// For detailed documentation of the format see: /// /// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview - static BlinkTraceEvent fromJson(Map json) { - return BlinkTraceEvent._( - args: json['args'] as Map, - cat: json['cat'] as String, - name: json['name'] as String, - ph: json['ph'] as String, - pid: _readInt(json, 'pid'), - tid: _readInt(json, 'tid'), - ts: _readInt(json, 'ts'), - tts: _readInt(json, 'tts'), - tdur: _readInt(json, 'tdur'), - ); - } + BlinkTraceEvent.fromJson(Map json) + : args = json['args'] as Map, + cat = json['cat'] as String, + name = json['name'] as String, + ph = json['ph'] as String, + pid = _readInt(json, 'pid'), + tid = _readInt(json, 'tid'), + ts = _readInt(json, 'ts'), + tts = _readInt(json, 'tts'), + tdur = _readInt(json, 'tdur'); /// Event-specific data. final Map args; diff --git a/dev/integration_tests/android_semantics_testing/lib/src/common.dart b/dev/integration_tests/android_semantics_testing/lib/src/common.dart index 3ff25281290..fa9e3f5091f 100644 --- a/dev/integration_tests/android_semantics_testing/lib/src/common.dart +++ b/dev/integration_tests/android_semantics_testing/lib/src/common.dart @@ -22,8 +22,6 @@ import 'constants.dart'; /// /// * [AccessibilityNodeInfo](https://developer.android.com/reference/android/view/accessibility/AccessibilityNodeInfo) class AndroidSemanticsNode { - AndroidSemanticsNode._(this._values); - /// Deserializes a new [AndroidSemanticsNode] from a json map. /// /// The structure of the JSON: @@ -54,9 +52,7 @@ class AndroidSemanticsNode { /// int, /// ] /// } - factory AndroidSemanticsNode.deserialize(String value) { - return AndroidSemanticsNode._(json.decode(value)); - } + AndroidSemanticsNode.deserialize(String value) : _values = json.decode(value); final dynamic _values; final List _children = []; diff --git a/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart b/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart index c064b837ab8..c071004a824 100644 --- a/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart +++ b/dev/integration_tests/flutter_gallery/lib/gallery/demo.dart @@ -183,8 +183,8 @@ class FullScreenCodeDialogState extends State { @override Widget build(BuildContext context) { final SyntaxHighlighterStyle style = Theme.of(context).brightness == Brightness.dark - ? SyntaxHighlighterStyle.darkThemeStyle() - : SyntaxHighlighterStyle.lightThemeStyle(); + ? SyntaxHighlighterStyle.darkThemeStyle + : SyntaxHighlighterStyle.lightThemeStyle; Widget body; if (_exampleCode == null) { diff --git a/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart b/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart index d81430e5f99..9dd635fdf97 100644 --- a/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart +++ b/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart @@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; import 'package:string_scanner/string_scanner.dart'; class SyntaxHighlighterStyle { - SyntaxHighlighterStyle({ + const SyntaxHighlighterStyle({ this.baseStyle, this.numberStyle, this.commentStyle, @@ -17,31 +17,27 @@ class SyntaxHighlighterStyle { this.constantStyle, }); - static SyntaxHighlighterStyle lightThemeStyle() { - return SyntaxHighlighterStyle( - baseStyle: const TextStyle(color: Color(0xFF000000)), - numberStyle: const TextStyle(color: Color(0xFF1565C0)), - commentStyle: const TextStyle(color: Color(0xFF9E9E9E)), - keywordStyle: const TextStyle(color: Color(0xFF9C27B0)), - stringStyle: const TextStyle(color: Color(0xFF43A047)), - punctuationStyle: const TextStyle(color: Color(0xFF000000)), - classStyle: const TextStyle(color: Color(0xFF512DA8)), - constantStyle: const TextStyle(color: Color(0xFF795548)), - ); - } + static const SyntaxHighlighterStyle lightThemeStyle = SyntaxHighlighterStyle( + baseStyle: TextStyle(color: Color(0xFF000000)), + numberStyle: TextStyle(color: Color(0xFF1565C0)), + commentStyle: TextStyle(color: Color(0xFF9E9E9E)), + keywordStyle: TextStyle(color: Color(0xFF9C27B0)), + stringStyle: TextStyle(color: Color(0xFF43A047)), + punctuationStyle: TextStyle(color: Color(0xFF000000)), + classStyle: TextStyle(color: Color(0xFF512DA8)), + constantStyle: TextStyle(color: Color(0xFF795548)), + ); - static SyntaxHighlighterStyle darkThemeStyle() { - return SyntaxHighlighterStyle( - baseStyle: const TextStyle(color: Color(0xFFFFFFFF)), - numberStyle: const TextStyle(color: Color(0xFF1565C0)), - commentStyle: const TextStyle(color: Color(0xFF9E9E9E)), - keywordStyle: const TextStyle(color: Color(0xFF80CBC4)), - stringStyle: const TextStyle(color: Color(0xFF009688)), - punctuationStyle: const TextStyle(color: Color(0xFFFFFFFF)), - classStyle: const TextStyle(color: Color(0xFF009688)), - constantStyle: const TextStyle(color: Color(0xFF795548)), - ); - } + static const SyntaxHighlighterStyle darkThemeStyle = SyntaxHighlighterStyle( + baseStyle: TextStyle(color: Color(0xFFFFFFFF)), + numberStyle: TextStyle(color: Color(0xFF1565C0)), + commentStyle: TextStyle(color: Color(0xFF9E9E9E)), + keywordStyle: TextStyle(color: Color(0xFF80CBC4)), + stringStyle: TextStyle(color: Color(0xFF009688)), + punctuationStyle: TextStyle(color: Color(0xFFFFFFFF)), + classStyle: TextStyle(color: Color(0xFF009688)), + constantStyle: TextStyle(color: Color(0xFF795548)), + ); final TextStyle? baseStyle; final TextStyle? numberStyle; @@ -60,7 +56,7 @@ abstract class SyntaxHighlighter { class DartSyntaxHighlighter extends SyntaxHighlighter { DartSyntaxHighlighter([this._style]) { _spans = <_HighlightSpan>[]; - _style ??= SyntaxHighlighterStyle.darkThemeStyle(); + _style ??= SyntaxHighlighterStyle.darkThemeStyle; } SyntaxHighlighterStyle? _style; diff --git a/dev/tools/gen_defaults/lib/typography_template.dart b/dev/tools/gen_defaults/lib/typography_template.dart index 8e3754ac648..d31e8e32fcd 100644 --- a/dev/tools/gen_defaults/lib/typography_template.dart +++ b/dev/tools/gen_defaults/lib/typography_template.dart @@ -9,9 +9,7 @@ class TypographyTemplate extends TokenTemplate { @override String generate() => ''' -class _M3Typography { - _M3Typography._(); - +abstract final class _M3Typography { ${_textTheme('englishLike', 'alphabetic')} ${_textTheme('dense', 'ideographic')} diff --git a/packages/flutter/lib/src/gestures/recognizer.dart b/packages/flutter/lib/src/gestures/recognizer.dart index d760f488f68..8c732b49603 100644 --- a/packages/flutter/lib/src/gestures/recognizer.dart +++ b/packages/flutter/lib/src/gestures/recognizer.dart @@ -760,15 +760,15 @@ class OffsetPair { /// Creates a [OffsetPair] from [PointerEvent.localPosition] and /// [PointerEvent.position]. - factory OffsetPair.fromEventPosition(PointerEvent event) { - return OffsetPair(local: event.localPosition, global: event.position); - } + OffsetPair.fromEventPosition(PointerEvent event) + : local = event.localPosition, + global = event.position; /// Creates a [OffsetPair] from [PointerEvent.localDelta] and /// [PointerEvent.delta]. - factory OffsetPair.fromEventDelta(PointerEvent event) { - return OffsetPair(local: event.localDelta, global: event.delta); - } + OffsetPair.fromEventDelta(PointerEvent event) + : local = event.localDelta, + global = event.delta; /// A [OffsetPair] where both [Offset]s are [Offset.zero]. static const OffsetPair zero = OffsetPair(local: Offset.zero, global: Offset.zero); diff --git a/packages/flutter/lib/src/material/material_state.dart b/packages/flutter/lib/src/material/material_state.dart index 78f7ba3bffb..29d68629a5a 100644 --- a/packages/flutter/lib/src/material/material_state.dart +++ b/packages/flutter/lib/src/material/material_state.dart @@ -321,12 +321,6 @@ abstract class MaterialStateBorderSide extends BorderSide implements MaterialSta /// const constructors so that they can be used in const expressions. const MaterialStateBorderSide(); - /// Returns a [BorderSide] that's to be used when a Material component is - /// in the specified state. Return null to defer to the default value of the - /// widget or theme. - @override - BorderSide? resolve(Set states); - /// Creates a [MaterialStateBorderSide] from a /// [MaterialPropertyResolver] callback function. /// @@ -364,8 +358,13 @@ abstract class MaterialStateBorderSide extends BorderSide implements MaterialSta /// }), /// ), /// ``` - static MaterialStateBorderSide resolveWith(MaterialPropertyResolver callback) => - _MaterialStateBorderSide(callback); + const factory MaterialStateBorderSide.resolveWith(MaterialPropertyResolver callback) = _MaterialStateBorderSide; + + /// Returns a [BorderSide] that's to be used when a Material component is + /// in the specified state. Return null to defer to the default value of the + /// widget or theme. + @override + BorderSide? resolve(Set states); } /// A [MaterialStateBorderSide] created from a @@ -381,9 +380,7 @@ class _MaterialStateBorderSide extends MaterialStateBorderSide { final MaterialPropertyResolver _resolve; @override - BorderSide? resolve(Set states) { - return _resolve(states); - } + BorderSide? resolve(Set states) => _resolve(states); } /// Defines an [OutlinedBorder] whose value depends on a set of [MaterialState]s @@ -457,8 +454,7 @@ abstract class MaterialStateTextStyle extends TextStyle implements MaterialState /// /// The given callback parameter must return a non-null text style in the default /// state. - static MaterialStateTextStyle resolveWith(MaterialPropertyResolver callback) => - _MaterialStateTextStyle(callback); + const factory MaterialStateTextStyle.resolveWith(MaterialPropertyResolver callback) = _MaterialStateTextStyle; /// Returns a [TextStyle] that's to be used when a Material component is in the /// specified state. @@ -520,8 +516,7 @@ abstract class MaterialStateOutlineInputBorder extends OutlineInputBorder implem /// /// The given callback parameter must return a non-null text style in the default /// state. - static MaterialStateOutlineInputBorder resolveWith(MaterialPropertyResolver callback) => - _MaterialStateOutlineInputBorder(callback); + const factory MaterialStateOutlineInputBorder.resolveWith(MaterialPropertyResolver callback) = _MaterialStateOutlineInputBorder; /// Returns a [InputBorder] that's to be used when a Material component is in the /// specified state. @@ -583,8 +578,7 @@ abstract class MaterialStateUnderlineInputBorder extends UnderlineInputBorder im /// /// The given callback parameter must return a non-null text style in the default /// state. - static MaterialStateUnderlineInputBorder resolveWith(MaterialPropertyResolver callback) => - _MaterialStateUnderlineInputBorder(callback); + const factory MaterialStateUnderlineInputBorder.resolveWith(MaterialPropertyResolver callback) = _MaterialStateUnderlineInputBorder; /// Returns a [InputBorder] that's to be used when a Material component is in the /// specified state. diff --git a/packages/flutter/lib/src/material/time.dart b/packages/flutter/lib/src/material/time.dart index 679e80a2616..2a4711c998b 100644 --- a/packages/flutter/lib/src/material/time.dart +++ b/packages/flutter/lib/src/material/time.dart @@ -64,7 +64,7 @@ class TimeOfDay { /// /// The [hour] is set to the current hour and the [minute] is set to the /// current minute in the local time zone. - factory TimeOfDay.now() { return TimeOfDay.fromDateTime(DateTime.now()); } + TimeOfDay.now() : this.fromDateTime(DateTime.now()); /// The number of hours in one day, i.e. 24. static const int hoursPerDay = 24; diff --git a/packages/flutter/lib/src/material/typography.dart b/packages/flutter/lib/src/material/typography.dart index 948ffc0bd36..6749f109c09 100644 --- a/packages/flutter/lib/src/material/typography.dart +++ b/packages/flutter/lib/src/material/typography.dart @@ -745,9 +745,7 @@ class Typography with Diagnosticable { // Design token database by the script: // dev/tools/gen_defaults/bin/gen_defaults.dart. -class _M3Typography { - _M3Typography._(); - +abstract final class _M3Typography { static const TextTheme englishLike = TextTheme( displayLarge: TextStyle(debugLabel: 'englishLike displayLarge 2021', inherit: false, fontSize: 57.0, fontWeight: FontWeight.w400, letterSpacing: -0.25, height: 1.12, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), displayMedium: TextStyle(debugLabel: 'englishLike displayMedium 2021', inherit: false, fontSize: 45.0, fontWeight: FontWeight.w400, letterSpacing: 0.0, height: 1.16, textBaseline: TextBaseline.alphabetic, leadingDistribution: TextLeadingDistribution.even), diff --git a/packages/flutter/lib/src/rendering/stack.dart b/packages/flutter/lib/src/rendering/stack.dart index 0a6cea78dbd..d315b3a6685 100644 --- a/packages/flutter/lib/src/rendering/stack.dart +++ b/packages/flutter/lib/src/rendering/stack.dart @@ -26,9 +26,11 @@ class RelativeRect { /// Creates a RelativeRect from a Rect and a Size. The Rect (first argument) /// and the RelativeRect (the output) are in the coordinate space of the /// rectangle described by the Size, with 0,0 being at the top left. - factory RelativeRect.fromSize(Rect rect, Size container) { - return RelativeRect.fromLTRB(rect.left, rect.top, container.width - rect.right, container.height - rect.bottom); - } + RelativeRect.fromSize(Rect rect, Size container) + : left = rect.left, + top = rect.top, + right = container.width - rect.right, + bottom = container.height - rect.bottom; /// Creates a RelativeRect from two Rects. The second Rect provides the /// container, the first provides the rectangle, in the same coordinate space, @@ -42,14 +44,11 @@ class RelativeRect { /// If the first rect is actually in the container's coordinate space, then /// use [RelativeRect.fromSize] and pass the container's size as the second /// argument instead. - factory RelativeRect.fromRect(Rect rect, Rect container) { - return RelativeRect.fromLTRB( - rect.left - container.left, - rect.top - container.top, - container.right - rect.right, - container.bottom - rect.bottom, - ); - } + RelativeRect.fromRect(Rect rect, Rect container) + : left = rect.left - container.left, + top = rect.top - container.top, + right = container.right - rect.right, + bottom = container.bottom - rect.bottom; /// Creates a RelativeRect from horizontal position using `start` and `end` /// rather than `left` and `right`. diff --git a/packages/flutter/lib/src/rendering/table_border.dart b/packages/flutter/lib/src/rendering/table_border.dart index 97f2c6b9e47..d0628e3260e 100644 --- a/packages/flutter/lib/src/rendering/table_border.dart +++ b/packages/flutter/lib/src/rendering/table_border.dart @@ -41,19 +41,16 @@ class TableBorder { /// Creates a border for a table where all the interior sides use the same /// styling and all the exterior sides use the same styling. - factory TableBorder.symmetric({ + const TableBorder.symmetric({ BorderSide inside = BorderSide.none, BorderSide outside = BorderSide.none, - }) { - return TableBorder( - top: outside, - right: outside, - bottom: outside, - left: outside, - horizontalInside: inside, - verticalInside: inside, - ); - } + this.borderRadius = BorderRadius.zero, + }) : top = outside, + right = outside, + bottom = outside, + left = outside, + horizontalInside = inside, + verticalInside = inside; /// The top side of this border. final BorderSide top; diff --git a/packages/flutter/lib/src/services/autofill.dart b/packages/flutter/lib/src/services/autofill.dart index 992d72557b6..72ed11205c9 100644 --- a/packages/flutter/lib/src/services/autofill.dart +++ b/packages/flutter/lib/src/services/autofill.dart @@ -13,11 +13,7 @@ export 'text_input.dart' show TextEditingValue, TextInputClient, TextInputConfig /// Each hint is pre-defined on at least one supported platform. See their /// documentation for their availability on each platform, and the platform /// values each autofill hint corresponds to. -class AutofillHints { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - AutofillHints._(); - +abstract final class AutofillHints { /// The input field expects an address locality (city/town). /// /// This hint will be translated to the below values on different platforms: diff --git a/packages/flutter/lib/src/services/live_text.dart b/packages/flutter/lib/src/services/live_text.dart index 413f7f06985..ef58feb3fce 100644 --- a/packages/flutter/lib/src/services/live_text.dart +++ b/packages/flutter/lib/src/services/live_text.dart @@ -12,11 +12,7 @@ import 'system_channels.dart'; /// See also: /// * /// * -class LiveText { - // This class is not meant to be instantiated or extended; this constructor - // prevents instantiation and extension. - LiveText._(); - +abstract final class LiveText { /// Returns true if the Live Text input feature is available on the current device. static Future isLiveTextInputAvailable() async { final bool supportLiveTextInput = diff --git a/packages/flutter/lib/src/services/mouse_cursor.dart b/packages/flutter/lib/src/services/mouse_cursor.dart index a9cd9e94231..bfd900277c8 100644 --- a/packages/flutter/lib/src/services/mouse_cursor.dart +++ b/packages/flutter/lib/src/services/mouse_cursor.dart @@ -399,11 +399,7 @@ class SystemMouseCursor extends MouseCursor { /// The cursors should be named based on the cursors' use cases instead of their /// appearance, because different platforms might (although not commonly) use /// different shapes for the same use case. -class SystemMouseCursors { - // This class only contains static members, and should not be instantiated or - // extended. - SystemMouseCursors._(); - +abstract final class SystemMouseCursors { // The mapping in this class must be kept in sync with the following files in // the engine: // diff --git a/packages/flutter/lib/src/services/text_formatter.dart b/packages/flutter/lib/src/services/text_formatter.dart index af0bf80147f..daaeef1f370 100644 --- a/packages/flutter/lib/src/services/text_formatter.dart +++ b/packages/flutter/lib/src/services/text_formatter.dart @@ -91,6 +91,10 @@ abstract class TextInputFormatter { /// This constructor enables subclasses to provide const constructors so that they can be used in const expressions. const TextInputFormatter(); + /// A shorthand to creating a custom [TextInputFormatter] which formats + /// incoming text input changes with the given function. + const factory TextInputFormatter.withFunction(TextInputFormatFunction formatFunction) = _SimpleTextInputFormatter; + /// Called when text is being typed or cut/copy/pasted in the [EditableText]. /// /// You can override the resulting text based on the previous text value and @@ -102,14 +106,6 @@ abstract class TextInputFormatter { TextEditingValue oldValue, TextEditingValue newValue, ); - - /// A shorthand to creating a custom [TextInputFormatter] which formats - /// incoming text input changes with the given function. - static TextInputFormatter withFunction( - TextInputFormatFunction formatFunction, - ) { - return _SimpleTextInputFormatter(formatFunction); - } } /// Function signature expected for creating custom [TextInputFormatter] @@ -121,7 +117,7 @@ typedef TextInputFormatFunction = TextEditingValue Function( /// Wiring for [TextInputFormatter.withFunction]. class _SimpleTextInputFormatter extends TextInputFormatter { - _SimpleTextInputFormatter(this.formatFunction); + const _SimpleTextInputFormatter(this.formatFunction); final TextInputFormatFunction formatFunction; diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 6dba29d498f..92b450ae522 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -6763,10 +6763,8 @@ class RepaintBoundary extends SingleChildRenderObjectWidget { /// /// The key for the [RepaintBoundary] is derived either from the child's key /// (if the child has a non-null key) or from the given `childIndex`. - factory RepaintBoundary.wrap(Widget child, int childIndex) { - final Key key = child.key != null ? ValueKey(child.key!) : ValueKey(childIndex); - return RepaintBoundary(key: key, child: child); - } + RepaintBoundary.wrap(Widget child, int childIndex) + : super(key: ValueKey(child.key ?? childIndex), child: child); /// Wraps each of the given children in [RepaintBoundary]s. /// @@ -7557,16 +7555,11 @@ class IndexedSemantics extends SingleChildRenderObjectWidget { /// Useful for attaching a key to an existing widget. class KeyedSubtree extends StatelessWidget { /// Creates a widget that builds its child. - const KeyedSubtree({ - super.key, - required this.child, - }); + const KeyedSubtree({super.key, required this.child}); /// Creates a KeyedSubtree for child with a key that's based on the child's existing key or childIndex. - factory KeyedSubtree.wrap(Widget child, int childIndex) { - final Key key = child.key != null ? ValueKey(child.key!) : ValueKey(childIndex); - return KeyedSubtree(key: key, child: child); - } + KeyedSubtree.wrap(this.child, int childIndex) + : super(key: ValueKey(child.key ?? childIndex)); /// The widget below this widget in the tree. /// diff --git a/packages/flutter/lib/src/widgets/media_query.dart b/packages/flutter/lib/src/widgets/media_query.dart index 4845b947484..7333dceebd7 100644 --- a/packages/flutter/lib/src/widgets/media_query.dart +++ b/packages/flutter/lib/src/widgets/media_query.dart @@ -190,7 +190,7 @@ class MediaQueryData { 'This constructor was deprecated in preparation for the upcoming multi-window support. ' 'This feature was deprecated after v3.7.0-32.0.pre.' ) - factory MediaQueryData.fromWindow(ui.FlutterView window) => MediaQueryData.fromView(window); + factory MediaQueryData.fromWindow(ui.FlutterView window) = MediaQueryData.fromView; /// Creates data for a [MediaQuery] based on the given `view`. /// @@ -924,29 +924,23 @@ class MediaQuery extends InheritedModel<_MediaQueryAspect> { /// adds a [Padding] widget. /// * [MediaQueryData.padding], the affected property of the /// [MediaQueryData]. - /// * [removeViewInsets], the same thing but for [MediaQueryData.viewInsets]. - /// * [removeViewPadding], the same thing but for + /// * [MediaQuery.removeViewInsets], the same thing but for [MediaQueryData.viewInsets]. + /// * [MediaQuery.removeViewPadding], the same thing but for /// [MediaQueryData.viewPadding]. - factory MediaQuery.removePadding({ - Key? key, + MediaQuery.removePadding({ + super.key, required BuildContext context, bool removeLeft = false, bool removeTop = false, bool removeRight = false, bool removeBottom = false, - required Widget child, - }) { - return MediaQuery( - key: key, - data: MediaQuery.of(context).removePadding( + required super.child, + }) : data = MediaQuery.of(context).removePadding( removeLeft: removeLeft, removeTop: removeTop, removeRight: removeRight, removeBottom: removeBottom, - ), - child: child, - ); - } + ); /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] /// from the given context, but removes the specified view insets. @@ -966,29 +960,23 @@ class MediaQuery extends InheritedModel<_MediaQueryAspect> { /// /// * [MediaQueryData.viewInsets], the affected property of the /// [MediaQueryData]. - /// * [removePadding], the same thing but for [MediaQueryData.padding]. - /// * [removeViewPadding], the same thing but for + /// * [MediaQuery.removePadding], the same thing but for [MediaQueryData.padding]. + /// * [MediaQuery.removeViewPadding], the same thing but for /// [MediaQueryData.viewPadding]. - factory MediaQuery.removeViewInsets({ - Key? key, + MediaQuery.removeViewInsets({ + super.key, required BuildContext context, bool removeLeft = false, bool removeTop = false, bool removeRight = false, bool removeBottom = false, - required Widget child, - }) { - return MediaQuery( - key: key, - data: MediaQuery.of(context).removeViewInsets( + required super.child, + }) : data = MediaQuery.of(context).removeViewInsets( removeLeft: removeLeft, removeTop: removeTop, removeRight: removeRight, removeBottom: removeBottom, - ), - child: child, - ); - } + ); /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] /// from the given context, but removes the specified view padding. @@ -1008,28 +996,22 @@ class MediaQuery extends InheritedModel<_MediaQueryAspect> { /// /// * [MediaQueryData.viewPadding], the affected property of the /// [MediaQueryData]. - /// * [removePadding], the same thing but for [MediaQueryData.padding]. - /// * [removeViewInsets], the same thing but for [MediaQueryData.viewInsets]. - factory MediaQuery.removeViewPadding({ - Key? key, + /// * [MediaQuery.removePadding], the same thing but for [MediaQueryData.padding]. + /// * [MediaQuery.removeViewInsets], the same thing but for [MediaQueryData.viewInsets]. + MediaQuery.removeViewPadding({ + super.key, required BuildContext context, bool removeLeft = false, bool removeTop = false, bool removeRight = false, bool removeBottom = false, - required Widget child, - }) { - return MediaQuery( - key: key, - data: MediaQuery.of(context).removeViewPadding( + required super.child, + }) : data = MediaQuery.of(context).removeViewPadding( removeLeft: removeLeft, removeTop: removeTop, removeRight: removeRight, removeBottom: removeBottom, - ), - child: child, - ); - } + ); /// Deprecated. Use [MediaQuery.fromView] instead. /// diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index b22d0f2b08b..88b869baf59 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -5647,14 +5647,12 @@ class _NamedRestorationInformation extends _RestorationInformation { required this.restorationScopeId, }) : super(_RouteRestorationType.named); - factory _NamedRestorationInformation.fromSerializableData(List data) { - assert(data.length >= 2); - return _NamedRestorationInformation( - restorationScopeId: data[0]! as int, - name: data[1]! as String, - arguments: data.length > 2 ? data[2] : null, - ); - } + _NamedRestorationInformation.fromSerializableData(List data) + : assert(data.length > 1), + restorationScopeId = data[0]! as int, + name = data[1]! as String, + arguments = data.elementAtOrNull(2), + super(_RouteRestorationType.named); @override List computeSerializableData() { @@ -5685,15 +5683,12 @@ class _AnonymousRestorationInformation extends _RestorationInformation { required this.restorationScopeId, }) : super(_RouteRestorationType.anonymous); - factory _AnonymousRestorationInformation.fromSerializableData(List data) { - assert(data.length > 1); - final RestorableRouteBuilder routeBuilder = ui.PluginUtilities.getCallbackFromHandle(ui.CallbackHandle.fromRawHandle(data[1]! as int))! as RestorableRouteBuilder; - return _AnonymousRestorationInformation( - restorationScopeId: data[0]! as int, - routeBuilder: routeBuilder, - arguments: data.length > 2 ? data[2] : null, - ); - } + _AnonymousRestorationInformation.fromSerializableData(List data) + : assert(data.length > 1), + restorationScopeId = data[0]! as int, + routeBuilder = ui.PluginUtilities.getCallbackFromHandle(ui.CallbackHandle.fromRawHandle(data[1]! as int))! as RestorableRouteBuilder, + arguments = data.elementAtOrNull(2), + super(_RouteRestorationType.anonymous); @override // TODO(goderbauer): remove the kIsWeb check when https://github.com/flutter/flutter/issues/33615 is resolved. diff --git a/packages/flutter/test/rendering/table_border_test.dart b/packages/flutter/test/rendering/table_border_test.dart index 28df5d8b1fb..464c8c5f962 100644 --- a/packages/flutter/test/rendering/table_border_test.dart +++ b/packages/flutter/test/rendering/table_border_test.dart @@ -44,9 +44,9 @@ void main() { }); test('TableBorder.symmetric constructor', () { - final TableBorder border3 = TableBorder.symmetric( - inside: const BorderSide(width: 3.0), - outside: const BorderSide(color: Color(0xFFFF0000)), + const TableBorder border3 = TableBorder.symmetric( + inside: BorderSide(width: 3.0), + outside: BorderSide(color: Color(0xFFFF0000)), ); expect(border3.top, const BorderSide(color: Color(0xFFFF0000))); expect(border3.right, const BorderSide(color: Color(0xFFFF0000))); @@ -56,8 +56,8 @@ void main() { expect(border3.verticalInside, const BorderSide(width: 3.0)); expect(border3.dimensions, const EdgeInsets.symmetric(horizontal: 1.0, vertical: 1.0)); expect(border3.isUniform, isFalse); - expect(border3.scale(0.0), TableBorder.symmetric( - outside: const BorderSide(width: 0.0, color: Color(0xFFFF0000), style: BorderStyle.none), + expect(border3.scale(0.0), const TableBorder.symmetric( + outside: BorderSide(width: 0.0, color: Color(0xFFFF0000), style: BorderStyle.none), )); }); diff --git a/packages/flutter_driver/lib/src/common/layer_tree.dart b/packages/flutter_driver/lib/src/common/layer_tree.dart index 851005f5b3f..18419f24ca9 100644 --- a/packages/flutter_driver/lib/src/common/layer_tree.dart +++ b/packages/flutter_driver/lib/src/common/layer_tree.dart @@ -22,14 +22,12 @@ class LayerTree extends Result { /// Creates a [LayerTree] object with the given string representation. const LayerTree(this.tree); + /// Deserializes the result from JSON. + LayerTree.fromJson(Map json) : tree = json['tree'] as String; + /// String representation of the layer tree. final String? tree; - /// Deserializes the result from JSON. - static LayerTree fromJson(Map json) { - return LayerTree(json['tree'] as String); - } - @override Map toJson() => { 'tree': tree, diff --git a/packages/flutter_driver/lib/src/driver/refresh_rate_summarizer.dart b/packages/flutter_driver/lib/src/driver/refresh_rate_summarizer.dart index bedd529d0bb..9a42500398a 100644 --- a/packages/flutter_driver/lib/src/driver/refresh_rate_summarizer.dart +++ b/packages/flutter_driver/lib/src/driver/refresh_rate_summarizer.dart @@ -11,13 +11,9 @@ const String kUIThreadVsyncProcessEvent = 'VsyncProcessCallback'; /// /// `RefreshRate` is the time between the start of a vsync pulse and the target time of that vsync. class RefreshRateSummary { - /// Creates a [RefreshRateSummary] given the timeline events. - factory RefreshRateSummary({required List vsyncEvents}) { - return RefreshRateSummary._(refreshRates: _computeRefreshRates(vsyncEvents)); - } - - RefreshRateSummary._({required List refreshRates}) { + RefreshRateSummary({required List vsyncEvents}) { + final List refreshRates = _computeRefreshRates(vsyncEvents); _numberOfTotalFrames = refreshRates.length; for (final double refreshRate in refreshRates) { if ((refreshRate - 30).abs() < _kErrorMargin) { diff --git a/packages/flutter_driver/lib/src/driver/timeline.dart b/packages/flutter_driver/lib/src/driver/timeline.dart index cf63935b971..bda77b3a61a 100644 --- a/packages/flutter_driver/lib/src/driver/timeline.dart +++ b/packages/flutter_driver/lib/src/driver/timeline.dart @@ -10,11 +10,7 @@ class Timeline { /// and loaded in Chrome for visual inspection. /// /// See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview - factory Timeline.fromJson(Map json) { - return Timeline._(json, _parseEvents(json)); - } - - Timeline._(this.json, this.events); + Timeline.fromJson(this.json) : events = _parseEvents(json); /// The original timeline JSON. final Map json; diff --git a/packages/flutter_test/lib/src/mock_event_channel.dart b/packages/flutter_test/lib/src/mock_event_channel.dart index da7e46ffe88..8d04217b2f6 100644 --- a/packages/flutter_test/lib/src/mock_event_channel.dart +++ b/packages/flutter_test/lib/src/mock_event_channel.dart @@ -16,14 +16,14 @@ import 'package:flutter/services.dart'; /// - [MockStreamHandlerEventSink.endOfStream] sends an end of stream event. abstract class MockStreamHandler { /// Create a new [MockStreamHandler]. - MockStreamHandler(); + const MockStreamHandler(); /// Create a new inline [MockStreamHandler] with the given [onListen] and /// [onCancel] handlers. - factory MockStreamHandler.inline({ + const factory MockStreamHandler.inline({ required MockStreamHandlerOnListenCallback onListen, MockStreamHandlerOnCancelCallback? onCancel, - }) => _InlineMockStreamHandler(onListen: onListen, onCancel: onCancel); + }) = _InlineMockStreamHandler; /// Handler for the listen event. void onListen(Object? arguments, MockStreamHandlerEventSink events); @@ -39,7 +39,7 @@ typedef MockStreamHandlerOnListenCallback = void Function(Object? arguments, Moc typedef MockStreamHandlerOnCancelCallback = void Function(Object? arguments); class _InlineMockStreamHandler extends MockStreamHandler { - _InlineMockStreamHandler({ + const _InlineMockStreamHandler({ required MockStreamHandlerOnListenCallback onListen, MockStreamHandlerOnCancelCallback? onCancel, }) : _onListenInline = onListen, diff --git a/packages/flutter_tools/lib/src/base/io.dart b/packages/flutter_tools/lib/src/base/io.dart index 4825b94a4fd..9ebe64932a9 100644 --- a/packages/flutter_tools/lib/src/base/io.dart +++ b/packages/flutter_tools/lib/src/base/io.dart @@ -387,9 +387,9 @@ class Stdio { /// An overridable version of io.ProcessInfo. abstract class ProcessInfo { - factory ProcessInfo(FileSystem fs) => _DefaultProcessInfo(fs); + factory ProcessInfo(FileSystem fs) = _DefaultProcessInfo; - factory ProcessInfo.test(FileSystem fs) => _TestProcessInfo(fs); + factory ProcessInfo.test(FileSystem fs) = _TestProcessInfo; int get currentRss; diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 032127ac931..2cc9a61682c 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -25,12 +25,10 @@ typedef ShutdownHook = FutureOr Function(); // for more details. abstract class ShutdownHooks { - factory ShutdownHooks() => _DefaultShutdownHooks(); + factory ShutdownHooks() = _DefaultShutdownHooks; /// Registers a [ShutdownHook] to be executed before the VM exits. - void addShutdownHook( - ShutdownHook shutdownHook - ); + void addShutdownHook(ShutdownHook shutdownHook); @visibleForTesting List get registeredHooks; @@ -139,10 +137,7 @@ abstract class ProcessUtils { factory ProcessUtils({ required ProcessManager processManager, required Logger logger, - }) => _DefaultProcessUtils( - processManager: processManager, - logger: logger, - ); + }) = _DefaultProcessUtils; /// Spawns a child process to run the command [cmd]. /// diff --git a/packages/flutter_tools/lib/src/base/utils.dart b/packages/flutter_tools/lib/src/base/utils.dart index cf49ca162ac..69ee38c28f9 100644 --- a/packages/flutter_tools/lib/src/base/utils.dart +++ b/packages/flutter_tools/lib/src/base/utils.dart @@ -152,9 +152,7 @@ class SettingsFile { } } - factory SettingsFile.parseFromFile(File file) { - return SettingsFile.parse(file.readAsStringSync()); - } + SettingsFile.parseFromFile(File file) : this.parse(file.readAsStringSync()); final Map values = {}; diff --git a/packages/flutter_tools/lib/src/build_system/targets/dart_plugin_registrant.dart b/packages/flutter_tools/lib/src/build_system/targets/dart_plugin_registrant.dart index e18e767854c..3cc4dc21867 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/dart_plugin_registrant.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/dart_plugin_registrant.dart @@ -22,11 +22,7 @@ class DartPluginRegistrantTarget extends Target { /// /// If `project` is unset, a [FlutterProject] based on environment is used. @visibleForTesting - factory DartPluginRegistrantTarget.test(FlutterProject project) { - return DartPluginRegistrantTarget._(project); - } - - DartPluginRegistrantTarget._(this._project); + const DartPluginRegistrantTarget.test(FlutterProject project) : _project = project; final FlutterProject? _project; diff --git a/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter_args.dart b/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter_args.dart index 5943a27d356..b8b88c631a8 100644 --- a/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter_args.dart +++ b/packages/flutter_tools/lib/src/debug_adapters/flutter_adapter_args.dart @@ -42,8 +42,7 @@ class FlutterAttachRequestArguments program = obj['program'] as String?, super.fromMap(); - static FlutterAttachRequestArguments fromJson(Map obj) => - FlutterAttachRequestArguments.fromMap(obj); + factory FlutterAttachRequestArguments.fromJson(Map obj) = FlutterAttachRequestArguments.fromMap; /// Arguments to be passed to the tool that will run [program] (for example, the VM or Flutter tool). final List? toolArgs; @@ -128,6 +127,8 @@ class FlutterLaunchRequestArguments customToolReplacesArgs = obj['customToolReplacesArgs'] as int?, super.fromMap(); + factory FlutterLaunchRequestArguments.fromJson(Map obj) = FlutterLaunchRequestArguments.fromMap; + /// If noDebug is true the launch request should launch the program without enabling debugging. @override final bool? noDebug; @@ -170,7 +171,4 @@ class FlutterLaunchRequestArguments if (customToolReplacesArgs != null) 'customToolReplacesArgs': customToolReplacesArgs, }; - - static FlutterLaunchRequestArguments fromJson(Map obj) => - FlutterLaunchRequestArguments.fromMap(obj); } diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart index d79d5beeff3..135ae769f67 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_pm.dart @@ -167,12 +167,8 @@ class FuchsiaPM { /// server.stop(); /// } class FuchsiaPackageServer { - factory FuchsiaPackageServer( - String repo, String name, String host, int port) { - return FuchsiaPackageServer._(repo, name, host, port); - } - - FuchsiaPackageServer._(this._repo, this.name, this._host, this._port); + FuchsiaPackageServer(String repo, this.name, String host, int port) + : _repo = repo, _host = host, _port = port; static const String deviceHost = 'fuchsia.com'; static const String toolHost = 'flutter-tool'; diff --git a/packages/flutter_tools/lib/src/persistent_tool_state.dart b/packages/flutter_tools/lib/src/persistent_tool_state.dart index 870beee972f..8e3d95a5b82 100644 --- a/packages/flutter_tools/lib/src/persistent_tool_state.dart +++ b/packages/flutter_tools/lib/src/persistent_tool_state.dart @@ -18,19 +18,12 @@ abstract class PersistentToolState { required FileSystem fileSystem, required Logger logger, required Platform platform, - }) => _DefaultPersistentToolState( - fileSystem: fileSystem, - logger: logger, - platform: platform, - ); + }) = _DefaultPersistentToolState; factory PersistentToolState.test({ required Directory directory, required Logger logger, - }) => _DefaultPersistentToolState.test( - directory: directory, - logger: logger, - ); + }) = _DefaultPersistentToolState.test; static PersistentToolState? get instance => context.get(); diff --git a/packages/flutter_tools/lib/src/platform_plugins.dart b/packages/flutter_tools/lib/src/platform_plugins.dart index fdc47378fe1..5efa3e0e3a4 100644 --- a/packages/flutter_tools/lib/src/platform_plugins.dart +++ b/packages/flutter_tools/lib/src/platform_plugins.dart @@ -84,19 +84,14 @@ class AndroidPlugin extends PluginPlatform implements NativeOrDartPlugin { }) : _fileSystem = fileSystem, ffiPlugin = ffiPlugin ?? false; - factory AndroidPlugin.fromYaml(String name, YamlMap yaml, String pluginPath, FileSystem fileSystem) { - assert(validate(yaml)); - return AndroidPlugin( - name: name, - package: yaml['package'] as String?, - pluginClass: yaml[kPluginClass] as String?, - dartPluginClass: yaml[kDartPluginClass] as String?, - ffiPlugin: yaml[kFfiPlugin] as bool?, - defaultPackage: yaml[kDefaultPackage] as String?, - pluginPath: pluginPath, - fileSystem: fileSystem, - ); - } + AndroidPlugin.fromYaml(this.name, YamlMap yaml, this.pluginPath, FileSystem fileSystem) + : assert(validate(yaml)), + package = yaml['package'] as String?, + pluginClass = yaml[kPluginClass] as String?, + dartPluginClass = yaml[kDartPluginClass] as String?, + ffiPlugin = yaml[kFfiPlugin] as bool? ?? false, + defaultPackage = yaml[kDefaultPackage] as String?, + _fileSystem = fileSystem; final FileSystem _fileSystem; @@ -244,18 +239,14 @@ class IOSPlugin extends PluginPlatform implements NativeOrDartPlugin, DarwinPlug }) : ffiPlugin = ffiPlugin ?? false, sharedDarwinSource = sharedDarwinSource ?? false; - factory IOSPlugin.fromYaml(String name, YamlMap yaml) { - assert(validate(yaml)); // TODO(zanderso): https://github.com/flutter/flutter/issues/67241 - return IOSPlugin( - name: name, - classPrefix: '', - pluginClass: yaml[kPluginClass] as String?, - dartPluginClass: yaml[kDartPluginClass] as String?, - ffiPlugin: yaml[kFfiPlugin] as bool?, - defaultPackage: yaml[kDefaultPackage] as String?, - sharedDarwinSource: yaml[kSharedDarwinSource] as bool?, - ); - } + IOSPlugin.fromYaml(this.name, YamlMap yaml) + : assert(validate(yaml)), // TODO(zanderso): https://github.com/flutter/flutter/issues/67241 + classPrefix = '', + pluginClass = yaml[kPluginClass] as String?, + dartPluginClass = yaml[kDartPluginClass] as String?, + ffiPlugin = yaml[kFfiPlugin] as bool? ?? false, + defaultPackage = yaml[kDefaultPackage] as String?, + sharedDarwinSource = yaml[kSharedDarwinSource] as bool? ?? false; static bool validate(YamlMap yaml) { return yaml[kPluginClass] is String || @@ -321,22 +312,14 @@ class MacOSPlugin extends PluginPlatform implements NativeOrDartPlugin, DarwinPl }) : ffiPlugin = ffiPlugin ?? false, sharedDarwinSource = sharedDarwinSource ?? false; - factory MacOSPlugin.fromYaml(String name, YamlMap yaml) { - assert(validate(yaml)); - // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. - String? pluginClass = yaml[kPluginClass] as String?; - if (pluginClass == 'none') { - pluginClass = null; - } - return MacOSPlugin( - name: name, - pluginClass: pluginClass, - dartPluginClass: yaml[kDartPluginClass] as String?, - ffiPlugin: yaml[kFfiPlugin] as bool?, - defaultPackage: yaml[kDefaultPackage] as String?, - sharedDarwinSource: yaml[kSharedDarwinSource] as bool?, - ); - } + MacOSPlugin.fromYaml(this.name, YamlMap yaml) + : assert(validate(yaml)), + // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. + pluginClass = yaml[kPluginClass] == 'none' ? null : yaml[kPluginClass] as String?, + dartPluginClass = yaml[kDartPluginClass] as String?, + ffiPlugin = yaml[kFfiPlugin] as bool? ?? false, + defaultPackage = yaml[kDefaultPackage] as String?, + sharedDarwinSource = yaml[kSharedDarwinSource] as bool? ?? false; static bool validate(YamlMap yaml) { return yaml[kPluginClass] is String || @@ -487,21 +470,13 @@ class LinuxPlugin extends PluginPlatform implements NativeOrDartPlugin { }) : ffiPlugin = ffiPlugin ?? false, assert(pluginClass != null || dartPluginClass != null || (ffiPlugin ?? false) || defaultPackage != null); - factory LinuxPlugin.fromYaml(String name, YamlMap yaml) { - assert(validate(yaml)); - // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. - String? pluginClass = yaml[kPluginClass] as String?; - if (pluginClass == 'none') { - pluginClass = null; - } - return LinuxPlugin( - name: name, - pluginClass: pluginClass, - dartPluginClass: yaml[kDartPluginClass] as String?, - ffiPlugin: yaml[kFfiPlugin] as bool?, - defaultPackage: yaml[kDefaultPackage] as String?, - ); - } + LinuxPlugin.fromYaml(this.name, YamlMap yaml) + : assert(validate(yaml)), + // Treat 'none' as not present. See https://github.com/flutter/flutter/issues/57497. + pluginClass = yaml[kPluginClass] == 'none' ? null : yaml[kPluginClass] as String?, + dartPluginClass = yaml[kDartPluginClass] as String?, + ffiPlugin = yaml[kFfiPlugin] as bool? ?? false, + defaultPackage = yaml[kDefaultPackage] as String?; static bool validate(YamlMap yaml) { return yaml[kPluginClass] is String || diff --git a/packages/flutter_tools/lib/src/pre_run_validator.dart b/packages/flutter_tools/lib/src/pre_run_validator.dart index e08cf1c60c3..9c91d22f5ce 100644 --- a/packages/flutter_tools/lib/src/pre_run_validator.dart +++ b/packages/flutter_tools/lib/src/pre_run_validator.dart @@ -8,9 +8,7 @@ import 'cache.dart'; /// A validator that runs before the tool runs any command. abstract class PreRunValidator { - factory PreRunValidator({ - required FileSystem fileSystem, - }) => _DefaultPreRunValidator(fileSystem: fileSystem); + factory PreRunValidator({required FileSystem fileSystem}) = _DefaultPreRunValidator; void validate(); } diff --git a/packages/flutter_tools/lib/src/proxied_devices/file_transfer.dart b/packages/flutter_tools/lib/src/proxied_devices/file_transfer.dart index 195294a5717..737fcb07ff9 100644 --- a/packages/flutter_tools/lib/src/proxied_devices/file_transfer.dart +++ b/packages/flutter_tools/lib/src/proxied_devices/file_transfer.dart @@ -15,7 +15,7 @@ import '../convert.dart'; /// Adler-32 and MD5 hashes of blocks in files. class BlockHashes { - BlockHashes({ + const BlockHashes({ required this.blockSize, required this.totalSize, required this.adler32, @@ -23,6 +23,13 @@ class BlockHashes { required this.fileMd5, }); + BlockHashes.fromJson(Map obj) + : blockSize = obj['blockSize']! as int, + totalSize = obj['totalSize']! as int, + adler32 = Uint32List.view(base64.decode(obj['adler32']! as String).buffer), + md5 = (obj['md5']! as List).cast(), + fileMd5 = obj['fileMd5']! as String; + /// The block size used to generate the hashes. final int blockSize; @@ -45,16 +52,6 @@ class BlockHashes { 'md5': md5, 'fileMd5': fileMd5, }; - - static BlockHashes fromJson(Map obj) { - return BlockHashes( - blockSize: obj['blockSize']! as int, - totalSize: obj['totalSize']! as int, - adler32: Uint32List.view(base64.decode(obj['adler32']! as String).buffer), - md5: (obj['md5']! as List).cast(), - fileMd5: obj['fileMd5']! as String, - ); - } } /// Converts a stream of bytes, into a stream of bytes of fixed chunk size. diff --git a/packages/flutter_tools/test/general.shard/proxied_devices/proxied_devices_test.dart b/packages/flutter_tools/test/general.shard/proxied_devices/proxied_devices_test.dart index 1199e756942..26c1a7ece3d 100644 --- a/packages/flutter_tools/test/general.shard/proxied_devices/proxied_devices_test.dart +++ b/packages/flutter_tools/test/general.shard/proxied_devices/proxied_devices_test.dart @@ -431,7 +431,7 @@ void main() { testWithoutContext('transfers file to the daemon with delta turned on, file exists on remote', () async { bufferLogger = BufferLogger.test(); final FakeFileTransfer fileTransfer = FakeFileTransfer(); - final BlockHashes blockHashes = BlockHashes( + const BlockHashes blockHashes = BlockHashes( blockSize: 10, totalSize: 30, adler32: [1, 2, 3],