Skip to content

Commit ccb30ca

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer_testing: Move Flutter rendering and widgets mocks to multi-line strings
Work towards #61597 Change-Id: I3ddd08896c91f297d4a993fb39f75e8777cd4cea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466980 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 3649f59 commit ccb30ca

19 files changed

+848
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final renderingLibrary = MockLibraryUnit('lib/rendering.dart', r'''
8+
export 'painting.dart';
9+
export 'src/rendering/flex.dart';
10+
export 'src/rendering/paragraph.dart';
11+
''');
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final renderingFlexLibrary = MockLibraryUnit('lib/src/rendering/flex.dart', r'''
8+
enum CrossAxisAlignment { start, end, center, stretch, baseline }
9+
10+
enum MainAxisAlignment {
11+
start,
12+
end,
13+
center,
14+
spaceBetween,
15+
spaceAround,
16+
spaceEvenly,
17+
}
18+
19+
enum MainAxisSize { min, max }
20+
''');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final widgetsLibrary = MockLibraryUnit('lib/widgets.dart', r'''
8+
export 'foundation.dart' show UniqueKey;
9+
export 'src/widgets/async.dart';
10+
export 'src/widgets/basic.dart';
11+
export 'src/widgets/container.dart';
12+
export 'src/widgets/framework.dart';
13+
export 'src/widgets/gesture_detector.dart';
14+
export 'src/widgets/icon.dart';
15+
export 'src/widgets/navigator.dart';
16+
export 'src/widgets/placeholder.dart';
17+
export 'src/widgets/text.dart';
18+
export 'src/widgets/ticker_provider.dart';
19+
export 'src/widgets/value_listenable_builder.dart';
20+
export 'src/widgets/widget_inspector.dart';
21+
''');
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final widgetsAsyncLibrary = MockLibraryUnit('lib/src/widgets/async.dart', r'''
8+
import 'framework.dart';
9+
10+
typedef AsyncWidgetBuilder<T> =
11+
Widget Function(BuildContext context, AsyncSnapshot<T> snapshot);
12+
13+
@immutable
14+
class AsyncSnapshot<T> {}
15+
16+
class StreamBuilder<T> extends StreamBuilderBase<T, AsyncSnapshot<T>> {
17+
final T? initialData;
18+
19+
final Widget Function(BuildContext, AsyncSnapshot<T>) builder;
20+
21+
const StreamBuilder({
22+
super.key,
23+
this.initialData,
24+
required super.stream,
25+
required this.builder,
26+
});
27+
}
28+
''');
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final widgetsBasicLibrary = MockLibraryUnit('lib/src/widgets/basic.dart', r'''
8+
import 'package:flutter/rendering.dart';
9+
10+
import 'framework.dart';
11+
12+
export 'package:flutter/animation.dart';
13+
export 'package:flutter/painting.dart';
14+
export 'package:flutter/rendering.dart';
15+
16+
class Align extends SingleChildRenderObjectWidget {
17+
final AlignmentGeometry alignment;
18+
19+
final double? widthFactor;
20+
21+
final double? heightFactor;
22+
23+
const Align({
24+
super.key,
25+
this.alignment = Alignment.center,
26+
this.widthFactor,
27+
this.heightFactor,
28+
super.child,
29+
}) : assert(widthFactor == null || widthFactor >= 0.0),
30+
assert(heightFactor == null || heightFactor >= 0.0);
31+
}
32+
33+
class AspectRatio extends SingleChildRenderObjectWidget {
34+
const AspectRatio({super.key, required double aspectRatio, super.child})
35+
: assert(aspectRatio > 0.0);
36+
}
37+
38+
class Center extends Align {
39+
const Center({super.key, super.widthFactor, super.heightFactor, super.child});
40+
}
41+
42+
class SizedBox extends SingleChildRenderObjectWidget {
43+
const SizedBox({super.key, this.width, this.height, super.child});
44+
45+
const SizedBox.expand({super.key, super.child})
46+
: width = double.infinity,
47+
height = double.infinity;
48+
49+
const SizedBox.shrink({super.key, super.child}) : width = 0.0, height = 0.0;
50+
51+
SizedBox.fromSize({super.key, super.child, Size? size});
52+
53+
final double? width;
54+
55+
final double? height;
56+
}
57+
58+
class ClipRect extends SingleChildRenderObjectWidget {
59+
const ClipRect({
60+
super.key,
61+
CustomClipper clipper,
62+
Clip clipBehavior = Clip.hardEdge,
63+
super.child,
64+
});
65+
}
66+
67+
class ColoredBox extends SingleChildRenderObjectWidget {
68+
const ColoredBox({required Color color, super.child, super.key});
69+
}
70+
71+
class Column extends Flex {
72+
const Column({
73+
super.key,
74+
super.mainAxisAlignment,
75+
super.mainAxisSize,
76+
super.crossAxisAlignment,
77+
super.textDirection,
78+
super.verticalDirection,
79+
super.textBaseline,
80+
super.spacing,
81+
super.children,
82+
}) : super(direction: Axis.vertical);
83+
}
84+
85+
class Expanded extends Flexible {
86+
const Expanded({super.key, super.flex, required super.child})
87+
: super(fit: FlexFit.tight);
88+
}
89+
90+
class Flexible extends ParentDataWidget<FlexParentData> {
91+
const Flexible({
92+
super.key,
93+
int flex = 1,
94+
FlexFit fit = FlexFit.loose,
95+
required super.child,
96+
});
97+
}
98+
99+
class Flex extends MultiChildRenderObjectWidget {
100+
const Flex({
101+
super.key,
102+
required Axis direction,
103+
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
104+
MainAxisSize mainAxisSize = MainAxisSize.max,
105+
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
106+
TextDirection? textDirection,
107+
VerticalDirection verticalDirection = VerticalDirection.down,
108+
TextBaseline? textBaseline,
109+
Clip clipBehavior = Clip.none,
110+
double spacing = 0.0,
111+
super.children,
112+
}) : assert(
113+
!identical(crossAxisAlignment, CrossAxisAlignment.baseline) ||
114+
textBaseline != null,
115+
'textBaseline is required if you specify the crossAxisAlignment with CrossAxisAlignment.baseline',
116+
);
117+
}
118+
119+
class Padding extends SingleChildRenderObjectWidget {
120+
final EdgeInsetsGeometry padding;
121+
122+
const Padding({super.key, required this.padding, super.child});
123+
}
124+
125+
class Row extends Flex {
126+
const Row({
127+
super.key,
128+
super.mainAxisAlignment,
129+
super.mainAxisSize,
130+
super.crossAxisAlignment,
131+
super.textDirection,
132+
super.verticalDirection,
133+
super.textBaseline,
134+
super.spacing,
135+
super.children,
136+
}) : super(direction: Axis.horizontal);
137+
}
138+
139+
class Stack extends MultiChildRenderObjectWidget {
140+
const Stack({
141+
super.key,
142+
AlignmentGeometry alignment = AlignmentDirectional.topStart,
143+
TextDirection? textDirection,
144+
StackFit fit = StackFit.loose,
145+
Clip clipBehavior = Clip.hardEdge,
146+
super.children,
147+
});
148+
}
149+
150+
class Transform extends SingleChildRenderObjectWidget {
151+
const Transform({
152+
super.key,
153+
required Matrix4 transform,
154+
Offset? origin,
155+
AlignmentGeometry? alignment,
156+
bool transformHitTests = true,
157+
FilterQuality? filterQuality,
158+
super.child,
159+
});
160+
}
161+
162+
class Builder extends StatelessWidget {
163+
final Widget Function(BuildContext) builder;
164+
165+
const Builder({super.key, required this.builder});
166+
}
167+
168+
class SliverPadding extends SingleChildRenderObjectWidget {
169+
const SliverPadding({super.key, required EdgeInsetsGeometry padding, Widget? sliver})
170+
: super(child: sliver);
171+
}
172+
173+
class SliverToBoxAdapter extends SingleChildRenderObjectWidget {
174+
const SliverToBoxAdapter({super.key, super.child});
175+
}
176+
''');
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final widgetsContainerLibrary = MockLibraryUnit(
8+
'lib/src/widgets/container.dart',
9+
r'''
10+
import 'package:flutter/painting.dart';
11+
import 'package:ui/ui.dart';
12+
13+
import 'framework.dart';
14+
15+
class Container extends StatelessWidget {
16+
final Widget? child;
17+
18+
final AlignmentGeometry? alignment;
19+
20+
final EdgeInsetsGeometry? padding;
21+
22+
final Decoration? decoration;
23+
24+
final Decoration? foregroundDecoration;
25+
26+
final EdgeInsetsGeometry? margin;
27+
28+
Container({
29+
super.key,
30+
this.alignment,
31+
this.padding,
32+
Color? color,
33+
this.decoration,
34+
this.foregroundDecoration,
35+
double? width,
36+
double? height,
37+
BoxConstraints? constraints,
38+
this.margin,
39+
Matrix4? transform,
40+
AlignmentGeometry? transformAlignment,
41+
this.child,
42+
Clip clipBehavior = Clip.none,
43+
});
44+
45+
@override
46+
Widget build(BuildContext context) => throw 0;
47+
}
48+
49+
class DecoratedBox extends SingleChildRenderObjectWidget {
50+
const DecoratedBox({
51+
super.key,
52+
required Decoration decoration,
53+
DecorationPosition position = DecorationPosition.background,
54+
super.child,
55+
});
56+
}
57+
''',
58+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer_testing/src/mock_packages/mock_library.dart';
6+
7+
final widgetsDecoratedSliverLibrary = MockLibraryUnit(
8+
'lib/src/widgets/decorated_sliver.dart',
9+
r'''
10+
class DecoratedSliver extends SingleChildRenderObjectWidget {
11+
const DecoratedSliver({
12+
super.key,
13+
required Decoration decoration,
14+
DecorationPosition position = DecorationPosition.background,
15+
Widget? sliver,
16+
}) : super(child: sliver);
17+
}
18+
''',
19+
);

0 commit comments

Comments
 (0)