Add missing parameter to TableBorder.symmetric, and improve class constructors (#144279)

Originally, my aim was just to refactor (as per usual), but while messing around with the `TableBorder.symmetric` constructor, I realized that `borderRadius` was missing!

This pull request makes a few class constructors more efficient, and it fixes #144277 by adding the missing parameter.

<br>
This commit is contained in:
Nate 2024-03-04 13:20:19 -07:00 committed by GitHub
parent 1d7f4a9afa
commit 1a0dc8f1e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 195 additions and 356 deletions

View file

@ -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),
);

View file

@ -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;

View file

@ -422,18 +422,6 @@ Duration _computeAverageDuration(List<BlinkTraceEvent> 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<String, dynamic> json) {
return BlinkTraceEvent._(
args: json['args'] as Map<String, dynamic>,
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<String, dynamic> json)
: args = json['args'] as Map<String, dynamic>,
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<String, dynamic> args;

View file

@ -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<AndroidSemanticsNode> _children = <AndroidSemanticsNode>[];

View file

@ -183,8 +183,8 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
@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) {

View file

@ -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;

View file

@ -9,9 +9,7 @@ class TypographyTemplate extends TokenTemplate {
@override
String generate() => '''
class _M3Typography {
_M3Typography._();
abstract final class _M3Typography {
${_textTheme('englishLike', 'alphabetic')}
${_textTheme('dense', 'ideographic')}

View file

@ -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);

View file

@ -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<MaterialState> states);
/// Creates a [MaterialStateBorderSide] from a
/// [MaterialPropertyResolver<BorderSide?>] callback function.
///
@ -364,8 +358,13 @@ abstract class MaterialStateBorderSide extends BorderSide implements MaterialSta
/// }),
/// ),
/// ```
static MaterialStateBorderSide resolveWith(MaterialPropertyResolver<BorderSide?> callback) =>
_MaterialStateBorderSide(callback);
const factory MaterialStateBorderSide.resolveWith(MaterialPropertyResolver<BorderSide?> 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<MaterialState> states);
}
/// A [MaterialStateBorderSide] created from a
@ -381,9 +380,7 @@ class _MaterialStateBorderSide extends MaterialStateBorderSide {
final MaterialPropertyResolver<BorderSide?> _resolve;
@override
BorderSide? resolve(Set<MaterialState> states) {
return _resolve(states);
}
BorderSide? resolve(Set<MaterialState> 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<TextStyle> callback) =>
_MaterialStateTextStyle(callback);
const factory MaterialStateTextStyle.resolveWith(MaterialPropertyResolver<TextStyle> 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<InputBorder> callback) =>
_MaterialStateOutlineInputBorder(callback);
const factory MaterialStateOutlineInputBorder.resolveWith(MaterialPropertyResolver<InputBorder> 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<InputBorder> callback) =>
_MaterialStateUnderlineInputBorder(callback);
const factory MaterialStateUnderlineInputBorder.resolveWith(MaterialPropertyResolver<InputBorder> callback) = _MaterialStateUnderlineInputBorder;
/// Returns a [InputBorder] that's to be used when a Material component is in the
/// specified state.

View file

@ -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;

View file

@ -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),

View file

@ -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`.

View file

@ -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;

View file

@ -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:

View file

@ -12,11 +12,7 @@ import 'system_channels.dart';
/// See also:
/// * <https://developer.apple.com/documentation/uikit/uiresponder/3778577-capturetextfromcamera>
/// * <https://support.apple.com/guide/iphone/use-live-text-iphcf0b71b0e/ios>
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<bool> isLiveTextInputAvailable() async {
final bool supportLiveTextInput =

View file

@ -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:
//

View file

@ -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;

View file

@ -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<Key>(child.key!) : ValueKey<int>(childIndex);
return RepaintBoundary(key: key, child: child);
}
RepaintBoundary.wrap(Widget child, int childIndex)
: super(key: ValueKey<Object>(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<Key>(child.key!) : ValueKey<int>(childIndex);
return KeyedSubtree(key: key, child: child);
}
KeyedSubtree.wrap(this.child, int childIndex)
: super(key: ValueKey<Object>(child.key ?? childIndex));
/// The widget below this widget in the tree.
///

View file

@ -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.
///

View file

@ -5647,14 +5647,12 @@ class _NamedRestorationInformation extends _RestorationInformation {
required this.restorationScopeId,
}) : super(_RouteRestorationType.named);
factory _NamedRestorationInformation.fromSerializableData(List<Object?> 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<Object?> data)
: assert(data.length > 1),
restorationScopeId = data[0]! as int,
name = data[1]! as String,
arguments = data.elementAtOrNull(2),
super(_RouteRestorationType.named);
@override
List<Object> computeSerializableData() {
@ -5685,15 +5683,12 @@ class _AnonymousRestorationInformation extends _RestorationInformation {
required this.restorationScopeId,
}) : super(_RouteRestorationType.anonymous);
factory _AnonymousRestorationInformation.fromSerializableData(List<Object?> data) {
assert(data.length > 1);
final RestorableRouteBuilder<Object?> 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<Object?> 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.

View file

@ -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),
));
});

View file

@ -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<String, dynamic> json) : tree = json['tree'] as String;
/// String representation of the layer tree.
final String? tree;
/// Deserializes the result from JSON.
static LayerTree fromJson(Map<String, dynamic> json) {
return LayerTree(json['tree'] as String);
}
@override
Map<String, dynamic> toJson() => <String, dynamic>{
'tree': tree,

View file

@ -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<TimelineEvent> vsyncEvents}) {
return RefreshRateSummary._(refreshRates: _computeRefreshRates(vsyncEvents));
}
RefreshRateSummary._({required List<double> refreshRates}) {
RefreshRateSummary({required List<TimelineEvent> vsyncEvents}) {
final List<double> refreshRates = _computeRefreshRates(vsyncEvents);
_numberOfTotalFrames = refreshRates.length;
for (final double refreshRate in refreshRates) {
if ((refreshRate - 30).abs() < _kErrorMargin) {

View file

@ -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<String, dynamic> json) {
return Timeline._(json, _parseEvents(json));
}
Timeline._(this.json, this.events);
Timeline.fromJson(this.json) : events = _parseEvents(json);
/// The original timeline JSON.
final Map<String, dynamic> json;

View file

@ -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,

View file

@ -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;

View file

@ -25,12 +25,10 @@ typedef ShutdownHook = FutureOr<void> 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<ShutdownHook> 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].
///

View file

@ -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<String, String> values = <String, String>{};

View file

@ -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;

View file

@ -42,8 +42,7 @@ class FlutterAttachRequestArguments
program = obj['program'] as String?,
super.fromMap();
static FlutterAttachRequestArguments fromJson(Map<String, Object?> obj) =>
FlutterAttachRequestArguments.fromMap(obj);
factory FlutterAttachRequestArguments.fromJson(Map<String, Object?> obj) = FlutterAttachRequestArguments.fromMap;
/// Arguments to be passed to the tool that will run [program] (for example, the VM or Flutter tool).
final List<String>? toolArgs;
@ -128,6 +127,8 @@ class FlutterLaunchRequestArguments
customToolReplacesArgs = obj['customToolReplacesArgs'] as int?,
super.fromMap();
factory FlutterLaunchRequestArguments.fromJson(Map<String, Object?> 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<String, Object?> obj) =>
FlutterLaunchRequestArguments.fromMap(obj);
}

View file

@ -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';

View file

@ -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<PersistentToolState>();

View file

@ -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 ||

View file

@ -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();
}

View file

@ -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<String, Object?> 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<Object?>).cast<String>(),
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<String, Object?> 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<Object?>).cast<String>(),
fileMd5: obj['fileMd5']! as String,
);
}
}
/// Converts a stream of bytes, into a stream of bytes of fixed chunk size.

View file

@ -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: <int>[1, 2, 3],