Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -7,10 +7,7 @@ import 'package:flutter/widgets.dart';
|
||||
void main() {
|
||||
runApp(
|
||||
const Center(
|
||||
child: Text(
|
||||
'Instead run:\nflutter run xxx/yyy.dart',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
child: Text('Instead run:\nflutter run xxx/yyy.dart', textDirection: TextDirection.ltr),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
|
||||
// Shifts the coordinate space of and rotates the current transform.
|
||||
canvas.translate(mid.dx, mid.dy);
|
||||
canvas.rotate(math.pi/4);
|
||||
canvas.rotate(math.pi / 4);
|
||||
|
||||
final ui.Gradient yellowBlue = ui.Gradient.linear(
|
||||
ui.Offset(-radius, -radius),
|
||||
@@ -73,10 +73,22 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
|
||||
// Scale x and y by 0.5.
|
||||
final Float64List scaleMatrix = Float64List.fromList(<double>[
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0,
|
||||
0.5,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.5,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
]);
|
||||
canvas.transform(scaleMatrix);
|
||||
|
||||
@@ -105,15 +117,17 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = view.devicePixelRatio;
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
final Float64List deviceTransform =
|
||||
Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder =
|
||||
ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
return sceneBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,27 +16,30 @@ void beginFrame(Duration timeStamp) {
|
||||
|
||||
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
|
||||
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)
|
||||
..addText('Hello, world.');
|
||||
final ui.Paragraph paragraph = paragraphBuilder.build()
|
||||
..layout(ui.ParagraphConstraints(width: logicalSize.width));
|
||||
)..addText('Hello, world.');
|
||||
final ui.Paragraph paragraph =
|
||||
paragraphBuilder.build()..layout(ui.ParagraphConstraints(width: logicalSize.width));
|
||||
|
||||
final ui.Rect physicalBounds = ui.Offset.zero & (logicalSize * devicePixelRatio);
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, physicalBounds);
|
||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
||||
canvas.drawParagraph(paragraph, ui.Offset(
|
||||
(logicalSize.width - paragraph.maxIntrinsicWidth) / 2.0,
|
||||
(logicalSize.height - paragraph.height) / 2.0,
|
||||
));
|
||||
canvas.drawParagraph(
|
||||
paragraph,
|
||||
ui.Offset(
|
||||
(logicalSize.width - paragraph.maxIntrinsicWidth) / 2.0,
|
||||
(logicalSize.height - paragraph.height) / 2.0,
|
||||
),
|
||||
);
|
||||
final ui.Picture picture = recorder.endRecording();
|
||||
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
// TODO(abarth): We should be able to add a picture without pushing a
|
||||
// container layer first.
|
||||
..pushClipRect(physicalBounds)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
final ui.SceneBuilder sceneBuilder =
|
||||
ui.SceneBuilder()
|
||||
// TODO(abarth): We should be able to add a picture without pushing a
|
||||
// container layer first.
|
||||
..pushClipRect(physicalBounds)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
|
||||
view.render(sceneBuilder.build());
|
||||
}
|
||||
|
||||
@@ -41,15 +41,17 @@ void beginFrame(Duration timeStamp) {
|
||||
// COMPOSITE
|
||||
|
||||
final double devicePixelRatio = view.devicePixelRatio;
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
final Float64List deviceTransform =
|
||||
Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder =
|
||||
ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
view.render(sceneBuilder.build());
|
||||
|
||||
// After rendering the current frame of the animation, we ask the engine to
|
||||
|
||||
@@ -29,22 +29,27 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
|
||||
// The paint method of Paragraph draws the contents of the paragraph onto the
|
||||
// given canvas.
|
||||
canvas.drawParagraph(paragraph, ui.Offset(-paragraph.width / 2.0, (paragraph.width / 2.0) - 125.0));
|
||||
canvas.drawParagraph(
|
||||
paragraph,
|
||||
ui.Offset(-paragraph.width / 2.0, (paragraph.width / 2.0) - 125.0),
|
||||
);
|
||||
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = view.devicePixelRatio;
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
final Float64List deviceTransform =
|
||||
Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder =
|
||||
ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
return sceneBuilder.build();
|
||||
}
|
||||
|
||||
@@ -61,42 +66,44 @@ void main() {
|
||||
view = ui.PlatformDispatcher.instance.implicitView!;
|
||||
|
||||
// To create a paragraph of text, we use ParagraphBuilder.
|
||||
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(
|
||||
// The text below has a primary direction of left-to-right.
|
||||
// The embedded text has other directions.
|
||||
// If this was TextDirection.rtl, the "Hello, world" text would end up on
|
||||
// the other side of the right-to-left text.
|
||||
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)
|
||||
// We first push a style that turns the text blue.
|
||||
..pushStyle(ui.TextStyle(color: const ui.Color(0xFF0000FF)))
|
||||
..addText('Hello, ')
|
||||
// The next run of text will be bold.
|
||||
..pushStyle(ui.TextStyle(fontWeight: ui.FontWeight.bold))
|
||||
..addText('world. ')
|
||||
// The pop() command signals the end of the bold styling.
|
||||
..pop()
|
||||
// We add text to the paragraph in logical order. The paragraph object
|
||||
// understands bi-directional text and will compute the visual ordering
|
||||
// during layout.
|
||||
..addText('هذا هو قليلا طويلة من النص الذي يجب التفاف .')
|
||||
// The second pop() removes the blue color.
|
||||
..pop()
|
||||
// We can add more text with the default styling.
|
||||
..addText(' و أكثر قليلا لجعله أطول. ')
|
||||
..addText('สวัสดี');
|
||||
final ui.ParagraphBuilder builder =
|
||||
ui.ParagraphBuilder(
|
||||
// The text below has a primary direction of left-to-right.
|
||||
// The embedded text has other directions.
|
||||
// If this was TextDirection.rtl, the "Hello, world" text would end up on
|
||||
// the other side of the right-to-left text.
|
||||
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)
|
||||
// We first push a style that turns the text blue.
|
||||
..pushStyle(ui.TextStyle(color: const ui.Color(0xFF0000FF)))
|
||||
..addText('Hello, ')
|
||||
// The next run of text will be bold.
|
||||
..pushStyle(ui.TextStyle(fontWeight: ui.FontWeight.bold))
|
||||
..addText('world. ')
|
||||
// The pop() command signals the end of the bold styling.
|
||||
..pop()
|
||||
// We add text to the paragraph in logical order. The paragraph object
|
||||
// understands bi-directional text and will compute the visual ordering
|
||||
// during layout.
|
||||
..addText('هذا هو قليلا طويلة من النص الذي يجب التفاف .')
|
||||
// The second pop() removes the blue color.
|
||||
..pop()
|
||||
// We can add more text with the default styling.
|
||||
..addText(' و أكثر قليلا لجعله أطول. ')
|
||||
..addText('สวัสดี');
|
||||
// When we're done adding styles and text, we build the Paragraph object, at
|
||||
// which time we can apply styling that affects the entire paragraph, such as
|
||||
// left, right, or center alignment. Once built, the contents of the paragraph
|
||||
// cannot be altered, but sizing and positioning information can be updated.
|
||||
paragraph = builder.build()
|
||||
// Next, we supply a width that the text is permitted to occupy and we ask
|
||||
// the paragraph to the visual position of each its glyphs as well as its
|
||||
// overall size, subject to its sizing constraints.
|
||||
..layout(const ui.ParagraphConstraints(width: 180.0));
|
||||
paragraph =
|
||||
builder.build()
|
||||
// Next, we supply a width that the text is permitted to occupy and we ask
|
||||
// the paragraph to the visual position of each its glyphs as well as its
|
||||
// overall size, subject to its sizing constraints.
|
||||
..layout(const ui.ParagraphConstraints(width: 180.0));
|
||||
|
||||
// Finally, we register our beginFrame callback and kick off the first frame.
|
||||
ui.PlatformDispatcher.instance
|
||||
..onBeginFrame = beginFrame
|
||||
..scheduleFrame();
|
||||
..onBeginFrame = beginFrame
|
||||
..scheduleFrame();
|
||||
}
|
||||
|
||||
@@ -49,20 +49,22 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = view.devicePixelRatio;
|
||||
|
||||
// This transform scales the x and y coordinates by the devicePixelRatio.
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final Float64List deviceTransform =
|
||||
Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
|
||||
// We build a very simple scene graph with two nodes. The root node is a
|
||||
// transform that scale its children by the device pixel ratio. This transform
|
||||
// lets us paint in "logical" pixels which are converted to device pixels by
|
||||
// this scaling operation.
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
final ui.SceneBuilder sceneBuilder =
|
||||
ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
|
||||
// When we're done recording the scene, we call build() to obtain an immutable
|
||||
// record of the scene we've recorded.
|
||||
|
||||
@@ -20,32 +20,46 @@ void main() {
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
table.add(RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
|
||||
final RenderFlex row = RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr);
|
||||
final RenderFlex row = RenderFlex(
|
||||
crossAxisAlignment: crossAxisAlignment,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
style = const TextStyle(fontSize: 15.0, color: Color(0xFF000000));
|
||||
row.add(RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FFFCCCC)),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
row.add(
|
||||
RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FFFCCCC)),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
style = const TextStyle(fontSize: 10.0, color: Color(0xFF000000));
|
||||
row.add(RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FCCFFCC)),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
row.add(
|
||||
RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FCCFFCC)),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
),
|
||||
));
|
||||
final RenderFlex subrow = RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr);
|
||||
);
|
||||
final RenderFlex subrow = RenderFlex(
|
||||
crossAxisAlignment: crossAxisAlignment,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
style = const TextStyle(fontSize: 25.0, color: Color(0xFF000000));
|
||||
subrow.add(RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FCCCCFF)),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
subrow.add(
|
||||
RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FCCCCFF)),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
subrow.add(RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
|
||||
row.add(subrow);
|
||||
table.add(row);
|
||||
|
||||
@@ -40,9 +40,7 @@ void main() {
|
||||
child: square,
|
||||
);
|
||||
// Finally, we center the spinning green square...
|
||||
final RenderBox root = RenderPositionedBox(
|
||||
child: spin,
|
||||
);
|
||||
final RenderBox root = RenderPositionedBox(child: spin);
|
||||
// and attach it to the window.
|
||||
ViewRenderingFlutterBinding(root: root);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class ViewRenderingFlutterBinding extends RenderingFlutterBinding {
|
||||
///
|
||||
/// This binding does not automatically schedule any frames. Callers are
|
||||
/// responsible for deciding when to first call [scheduleFrame].
|
||||
ViewRenderingFlutterBinding({ RenderBox? root }) : _root = root;
|
||||
ViewRenderingFlutterBinding({RenderBox? root}) : _root = root;
|
||||
|
||||
@override
|
||||
void initInstances() {
|
||||
|
||||
@@ -17,7 +17,7 @@ class SectorConstraints extends Constraints {
|
||||
}) : assert(maxDeltaRadius >= minDeltaRadius),
|
||||
assert(maxDeltaTheta >= minDeltaTheta);
|
||||
|
||||
const SectorConstraints.tight({ double deltaRadius = 0.0, double deltaTheta = 0.0 })
|
||||
const SectorConstraints.tight({double deltaRadius = 0.0, double deltaTheta = 0.0})
|
||||
: minDeltaRadius = deltaRadius,
|
||||
maxDeltaRadius = deltaRadius,
|
||||
minDeltaTheta = deltaTheta,
|
||||
@@ -53,7 +53,7 @@ class SectorConstraints extends Constraints {
|
||||
}
|
||||
|
||||
class SectorDimensions {
|
||||
const SectorDimensions({ this.deltaRadius = 0.0, this.deltaTheta = 0.0 });
|
||||
const SectorDimensions({this.deltaRadius = 0.0, this.deltaTheta = 0.0});
|
||||
|
||||
factory SectorDimensions.withConstraints(
|
||||
SectorConstraints constraints, {
|
||||
@@ -88,7 +88,6 @@ class SectorParentData extends ParentData {
|
||||
/// * [RenderBox], which is the base class for [RenderObject]s that live in a
|
||||
/// Cartesian coordinate space.
|
||||
abstract class RenderSector extends RenderObject {
|
||||
|
||||
@override
|
||||
void setupParentData(RenderObject child) {
|
||||
if (child.parentData is! SectorParentData) {
|
||||
@@ -137,25 +136,32 @@ abstract class RenderSector extends RenderObject {
|
||||
Rect get paintBounds => Rect.fromLTWH(0.0, 0.0, 2.0 * deltaRadius, 2.0 * deltaRadius);
|
||||
|
||||
@override
|
||||
Rect get semanticBounds => Rect.fromLTWH(-deltaRadius, -deltaRadius, 2.0 * deltaRadius, 2.0 * deltaRadius);
|
||||
Rect get semanticBounds =>
|
||||
Rect.fromLTWH(-deltaRadius, -deltaRadius, 2.0 * deltaRadius, 2.0 * deltaRadius);
|
||||
|
||||
bool hitTest(SectorHitTestResult result, { required double radius, required double theta }) {
|
||||
if (radius < parentData!.radius || radius >= parentData!.radius + deltaRadius ||
|
||||
theta < parentData!.theta || theta >= parentData!.theta + deltaTheta) {
|
||||
bool hitTest(SectorHitTestResult result, {required double radius, required double theta}) {
|
||||
if (radius < parentData!.radius ||
|
||||
radius >= parentData!.radius + deltaRadius ||
|
||||
theta < parentData!.theta ||
|
||||
theta >= parentData!.theta + deltaTheta) {
|
||||
return false;
|
||||
}
|
||||
hitTestChildren(result, radius: radius, theta: theta);
|
||||
result.add(SectorHitTestEntry(this, radius: radius, theta: theta));
|
||||
return true;
|
||||
}
|
||||
void hitTestChildren(SectorHitTestResult result, { required double radius, required double theta }) { }
|
||||
|
||||
void hitTestChildren(
|
||||
SectorHitTestResult result, {
|
||||
required double radius,
|
||||
required double theta,
|
||||
}) {}
|
||||
|
||||
late double deltaRadius;
|
||||
late double deltaTheta;
|
||||
}
|
||||
|
||||
abstract class RenderDecoratedSector extends RenderSector {
|
||||
|
||||
RenderDecoratedSector(BoxDecoration? decoration) : _decoration = decoration;
|
||||
|
||||
BoxDecoration? _decoration;
|
||||
@@ -182,31 +188,47 @@ abstract class RenderDecoratedSector extends RenderSector {
|
||||
final Paint paint = Paint()..color = _decoration!.color!;
|
||||
final Path path = Path();
|
||||
final double outerRadius = parentData!.radius + deltaRadius;
|
||||
final Rect outerBounds = Rect.fromLTRB(offset.dx-outerRadius, offset.dy-outerRadius, offset.dx+outerRadius, offset.dy+outerRadius);
|
||||
final Rect outerBounds = Rect.fromLTRB(
|
||||
offset.dx - outerRadius,
|
||||
offset.dy - outerRadius,
|
||||
offset.dx + outerRadius,
|
||||
offset.dy + outerRadius,
|
||||
);
|
||||
path.arcTo(outerBounds, parentData!.theta, deltaTheta, true);
|
||||
final double innerRadius = parentData!.radius;
|
||||
final Rect innerBounds = Rect.fromLTRB(offset.dx-innerRadius, offset.dy-innerRadius, offset.dx+innerRadius, offset.dy+innerRadius);
|
||||
final Rect innerBounds = Rect.fromLTRB(
|
||||
offset.dx - innerRadius,
|
||||
offset.dy - innerRadius,
|
||||
offset.dx + innerRadius,
|
||||
offset.dy + innerRadius,
|
||||
);
|
||||
path.arcTo(innerBounds, parentData!.theta + deltaTheta, -deltaTheta, false);
|
||||
path.close();
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SectorChildListParentData extends SectorParentData with ContainerParentDataMixin<RenderSector> { }
|
||||
class SectorChildListParentData extends SectorParentData
|
||||
with ContainerParentDataMixin<RenderSector> {}
|
||||
|
||||
class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRenderObjectMixin<RenderSector, SectorChildListParentData> {
|
||||
class RenderSectorWithChildren extends RenderDecoratedSector
|
||||
with ContainerRenderObjectMixin<RenderSector, SectorChildListParentData> {
|
||||
RenderSectorWithChildren(super.decoration);
|
||||
|
||||
@override
|
||||
void hitTestChildren(SectorHitTestResult result, { required double radius, required double theta }) {
|
||||
void hitTestChildren(
|
||||
SectorHitTestResult result, {
|
||||
required double radius,
|
||||
required double theta,
|
||||
}) {
|
||||
RenderSector? child = lastChild;
|
||||
while (child != null) {
|
||||
if (child.hitTest(result, radius: radius, theta: theta)) {
|
||||
return;
|
||||
}
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.previousSibling;
|
||||
}
|
||||
}
|
||||
@@ -216,7 +238,8 @@ class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRende
|
||||
RenderSector? child = lastChild;
|
||||
while (child != null) {
|
||||
visitor(child);
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.previousSibling;
|
||||
}
|
||||
}
|
||||
@@ -269,17 +292,24 @@ class RenderSectorRing extends RenderSectorWithChildren {
|
||||
final double childRadius = radius + padding;
|
||||
final double paddingTheta = math.atan(padding / (radius + outerDeltaRadius));
|
||||
double innerTheta = paddingTheta; // increments with each child
|
||||
double remainingDeltaTheta = math.max(0.0, constraints.maxDeltaTheta - (innerTheta + paddingTheta));
|
||||
double remainingDeltaTheta = math.max(
|
||||
0.0,
|
||||
constraints.maxDeltaTheta - (innerTheta + paddingTheta),
|
||||
);
|
||||
RenderSector? child = firstChild;
|
||||
while (child != null) {
|
||||
final SectorConstraints innerConstraints = SectorConstraints(
|
||||
maxDeltaRadius: innerDeltaRadius,
|
||||
maxDeltaTheta: remainingDeltaTheta,
|
||||
);
|
||||
final SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConstraints, childRadius);
|
||||
final SectorDimensions childDimensions = child.getIntrinsicDimensions(
|
||||
innerConstraints,
|
||||
childRadius,
|
||||
);
|
||||
innerTheta += childDimensions.deltaTheta;
|
||||
remainingDeltaTheta -= childDimensions.deltaTheta;
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.nextSibling;
|
||||
if (child != null) {
|
||||
innerTheta += paddingTheta;
|
||||
@@ -315,7 +345,8 @@ class RenderSectorRing extends RenderSectorWithChildren {
|
||||
child.layout(innerConstraints, parentUsesSize: true);
|
||||
innerTheta += child.deltaTheta;
|
||||
remainingDeltaTheta -= child.deltaTheta;
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.nextSibling;
|
||||
if (child != null) {
|
||||
innerTheta += paddingTheta;
|
||||
@@ -334,21 +365,20 @@ class RenderSectorRing extends RenderSectorWithChildren {
|
||||
RenderSector? child = firstChild;
|
||||
while (child != null) {
|
||||
context.paintChild(child, offset);
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.nextSibling;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
// lays out RenderSector children in a stack
|
||||
|
||||
RenderSectorSlice({
|
||||
BoxDecoration? decoration,
|
||||
double deltaTheta = kTwoPi,
|
||||
double padding = 0.0,
|
||||
}) : _padding = padding, _desiredDeltaTheta = deltaTheta, super(decoration);
|
||||
RenderSectorSlice({BoxDecoration? decoration, double deltaTheta = kTwoPi, double padding = 0.0})
|
||||
: _padding = padding,
|
||||
_desiredDeltaTheta = deltaTheta,
|
||||
super(decoration);
|
||||
|
||||
double _desiredDeltaTheta;
|
||||
double get desiredDeltaTheta => _desiredDeltaTheta;
|
||||
@@ -391,10 +421,14 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
maxDeltaRadius: remainingDeltaRadius,
|
||||
maxDeltaTheta: innerDeltaTheta,
|
||||
);
|
||||
final SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConstraints, childRadius);
|
||||
final SectorDimensions childDimensions = child.getIntrinsicDimensions(
|
||||
innerConstraints,
|
||||
childRadius,
|
||||
);
|
||||
childRadius += childDimensions.deltaRadius;
|
||||
remainingDeltaRadius -= childDimensions.deltaRadius;
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.nextSibling;
|
||||
childRadius += padding;
|
||||
remainingDeltaRadius -= padding;
|
||||
@@ -427,7 +461,8 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
child.layout(innerConstraints, parentUsesSize: true);
|
||||
childRadius += child.deltaRadius;
|
||||
remainingDeltaRadius -= child.deltaRadius;
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.nextSibling;
|
||||
childRadius += padding;
|
||||
remainingDeltaRadius -= padding;
|
||||
@@ -445,15 +480,16 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
while (child != null) {
|
||||
assert(child.parentData is SectorChildListParentData);
|
||||
context.paintChild(child, offset);
|
||||
final SectorChildListParentData childParentData = child.parentData! as SectorChildListParentData;
|
||||
final SectorChildListParentData childParentData =
|
||||
child.parentData! as SectorChildListParentData;
|
||||
child = childParentData.nextSibling;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChildMixin<RenderSector> {
|
||||
RenderBoxToRenderSectorAdapter({ double innerRadius = 0.0, RenderSector? child })
|
||||
class RenderBoxToRenderSectorAdapter extends RenderBox
|
||||
with RenderObjectWithChildMixin<RenderSector> {
|
||||
RenderBoxToRenderSectorAdapter({double innerRadius = 0.0, RenderSector? child})
|
||||
: _innerRadius = innerRadius {
|
||||
this.child = child;
|
||||
}
|
||||
@@ -504,17 +540,17 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
return getIntrinsicDimensions(width: width).height;
|
||||
}
|
||||
|
||||
Size getIntrinsicDimensions({
|
||||
double width = double.infinity,
|
||||
double height = double.infinity,
|
||||
}) {
|
||||
Size getIntrinsicDimensions({double width = double.infinity, double height = double.infinity}) {
|
||||
assert(child is RenderSector);
|
||||
assert(child!.parentData is SectorParentData);
|
||||
if (!width.isFinite && !height.isFinite) {
|
||||
return Size.zero;
|
||||
}
|
||||
final double maxChildDeltaRadius = math.max(0.0, math.min(width, height) / 2.0 - innerRadius);
|
||||
final SectorDimensions childDimensions = child!.getIntrinsicDimensions(SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius);
|
||||
final SectorDimensions childDimensions = child!.getIntrinsicDimensions(
|
||||
SectorConstraints(maxDeltaRadius: maxChildDeltaRadius),
|
||||
innerRadius,
|
||||
);
|
||||
final double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0;
|
||||
return Size.square(dimension);
|
||||
}
|
||||
@@ -528,7 +564,8 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
}
|
||||
assert(child is RenderSector);
|
||||
assert(child!.parentData is SectorParentData);
|
||||
final double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
|
||||
final double maxChildDeltaRadius =
|
||||
math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
|
||||
child!.parentData!.radius = innerRadius;
|
||||
child!.parentData!.theta = 0.0;
|
||||
child!.layout(SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
|
||||
@@ -547,7 +584,7 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
}
|
||||
|
||||
@override
|
||||
bool hitTest(BoxHitTestResult result, { required Offset position }) {
|
||||
bool hitTest(BoxHitTestResult result, {required Offset position}) {
|
||||
if (child == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -636,7 +673,7 @@ class SectorHitTestResult extends HitTestResult {
|
||||
/// A hit test entry used by [RenderSector].
|
||||
class SectorHitTestEntry extends HitTestEntry {
|
||||
/// Creates a box hit test entry.
|
||||
SectorHitTestEntry(RenderSector super.target, { required this.radius, required this.theta });
|
||||
SectorHitTestEntry(RenderSector super.target, {required this.radius, required this.theta});
|
||||
|
||||
@override
|
||||
RenderSector get target => super.target as RenderSector;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
class RenderSolidColorBox extends RenderDecoratedBox {
|
||||
RenderSolidColorBox(this.backgroundColor, { this.desiredSize = Size.infinite })
|
||||
: super(decoration: BoxDecoration(color: backgroundColor));
|
||||
RenderSolidColorBox(this.backgroundColor, {this.desiredSize = Size.infinite})
|
||||
: super(decoration: BoxDecoration(color: backgroundColor));
|
||||
|
||||
final Size desiredSize;
|
||||
final Color backgroundColor;
|
||||
|
||||
@@ -22,7 +22,7 @@ List<Color> _kColors = <Color>[
|
||||
|
||||
/// A simple model object for a dot that reacts to pointer pressure.
|
||||
class Dot {
|
||||
Dot({ required Color color }) : _paint = Paint()..color = color;
|
||||
Dot({required Color color}) : _paint = Paint()..color = color;
|
||||
|
||||
final Paint _paint;
|
||||
Offset position = Offset.zero;
|
||||
@@ -105,10 +105,7 @@ class RenderDots extends RenderBox {
|
||||
void main() {
|
||||
// Create some styled text to tell the user to interact with the app.
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
const TextSpan(
|
||||
style: TextStyle(color: Colors.black87),
|
||||
text: 'Touch me!',
|
||||
),
|
||||
const TextSpan(style: TextStyle(color: Colors.black87), text: 'Touch me!'),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
// A stack is a render object that layers its children on top of each other.
|
||||
@@ -116,10 +113,7 @@ void main() {
|
||||
// text.
|
||||
final RenderStack stack = RenderStack(
|
||||
textDirection: TextDirection.ltr,
|
||||
children: <RenderBox>[
|
||||
RenderDots(),
|
||||
paragraph,
|
||||
],
|
||||
children: <RenderBox>[RenderDots(), paragraph],
|
||||
);
|
||||
// The "parentData" field of a render object is controlled by the render
|
||||
// object's parent render object. Now that we've added the paragraph as a
|
||||
|
||||
@@ -16,7 +16,7 @@ typedef OnResultListener = void Function(String result);
|
||||
// The choice of JSON parsing here is meant as an example that might surface
|
||||
// in real-world applications.
|
||||
class Calculator {
|
||||
Calculator({ required this.onProgressListener, required this.onResultListener, String? data })
|
||||
Calculator({required this.onProgressListener, required this.onResultListener, String? data})
|
||||
: _data = _replicateJson(data, 10000);
|
||||
|
||||
final OnProgressListener onProgressListener;
|
||||
@@ -31,14 +31,12 @@ class Calculator {
|
||||
// Run the computation associated with this Calculator.
|
||||
void run() {
|
||||
int i = 0;
|
||||
final JsonDecoder decoder = JsonDecoder(
|
||||
(dynamic key, dynamic value) {
|
||||
if (key is int && i++ % _NOTIFY_INTERVAL == 0) {
|
||||
onProgressListener(i.toDouble(), _NUM_ITEMS.toDouble());
|
||||
}
|
||||
return value;
|
||||
},
|
||||
);
|
||||
final JsonDecoder decoder = JsonDecoder((dynamic key, dynamic value) {
|
||||
if (key is int && i++ % _NOTIFY_INTERVAL == 0) {
|
||||
onProgressListener(i.toDouble(), _NUM_ITEMS.toDouble());
|
||||
}
|
||||
return value;
|
||||
});
|
||||
try {
|
||||
final List<dynamic> result = decoder.convert(_data) as List<dynamic>;
|
||||
final int n = result.length;
|
||||
@@ -63,11 +61,7 @@ class Calculator {
|
||||
}
|
||||
|
||||
// The current state of the calculation.
|
||||
enum CalculationState {
|
||||
idle,
|
||||
loading,
|
||||
calculating
|
||||
}
|
||||
enum CalculationState { idle, loading, calculating }
|
||||
|
||||
// Structured message to initialize the spawned isolate.
|
||||
class CalculationMessage {
|
||||
@@ -82,7 +76,7 @@ class CalculationMessage {
|
||||
// This class manages these ports and maintains state related to the
|
||||
// progress of the background computation.
|
||||
class CalculationManager {
|
||||
CalculationManager({ required this.onProgressListener, required this.onResultListener })
|
||||
CalculationManager({required this.onProgressListener, required this.onResultListener})
|
||||
: _receivePort = ReceivePort() {
|
||||
_receivePort.listen(_handleMessage);
|
||||
}
|
||||
@@ -175,7 +169,7 @@ class CalculationManager {
|
||||
final SendPort sender = message.sendPort;
|
||||
final Calculator calculator = Calculator(
|
||||
onProgressListener: (double completed, double total) {
|
||||
sender.send(<double>[ completed, total ]);
|
||||
sender.send(<double>[completed, total]);
|
||||
},
|
||||
onResultListener: sender.send,
|
||||
data: message.data,
|
||||
@@ -201,7 +195,6 @@ class IsolateExampleWidget extends StatefulWidget {
|
||||
|
||||
// Main application state.
|
||||
class IsolateExampleState extends State<StatefulWidget> with SingleTickerProviderStateMixin {
|
||||
|
||||
String _status = 'Idle';
|
||||
String _label = 'Start';
|
||||
String _result = ' ';
|
||||
@@ -229,25 +222,14 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
|
||||
children: <Widget>[
|
||||
RotationTransition(
|
||||
turns: _animation,
|
||||
child: Container(
|
||||
width: 120.0,
|
||||
height: 120.0,
|
||||
color: const Color(0xFF882222),
|
||||
),
|
||||
child: Container(width: 120.0, height: 120.0, color: const Color(0xFF882222)),
|
||||
),
|
||||
Opacity(
|
||||
opacity: _calculationManager.isRunning ? 1.0 : 0.0,
|
||||
child: CircularProgressIndicator(
|
||||
value: _progress,
|
||||
),
|
||||
child: CircularProgressIndicator(value: _progress),
|
||||
),
|
||||
Text(_status),
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: _handleButtonPressed,
|
||||
child: Text(_label),
|
||||
),
|
||||
),
|
||||
Center(child: ElevatedButton(onPressed: _handleButtonPressed, child: Text(_label))),
|
||||
Text(_result),
|
||||
],
|
||||
),
|
||||
@@ -273,9 +255,9 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
|
||||
|
||||
String _getStatus(CalculationState state) {
|
||||
return switch (state) {
|
||||
CalculationState.loading => 'Loading...',
|
||||
CalculationState.loading => 'Loading...',
|
||||
CalculationState.calculating => 'In Progress',
|
||||
CalculationState.idle => 'Idle',
|
||||
CalculationState.idle => 'Idle',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class LifecycleWatcher extends StatefulWidget {
|
||||
const LifecycleWatcher({ super.key });
|
||||
const LifecycleWatcher({super.key});
|
||||
|
||||
@override
|
||||
State<LifecycleWatcher> createState() => _LifecycleWatcherState();
|
||||
}
|
||||
|
||||
class _LifecycleWatcherState extends State<LifecycleWatcher>
|
||||
with WidgetsBindingObserver {
|
||||
class _LifecycleWatcherState extends State<LifecycleWatcher> with WidgetsBindingObserver {
|
||||
AppLifecycleState? _lastLifecycleState;
|
||||
|
||||
@override
|
||||
@@ -43,14 +42,11 @@ class _LifecycleWatcherState extends State<LifecycleWatcher>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: LifecycleWatcher(),
|
||||
),
|
||||
child: Center(child: LifecycleWatcher()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@ import '../widgets/gestures.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Tap on center change color', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: GestureDemo(),
|
||||
));
|
||||
await tester.pumpWidget(
|
||||
const Directionality(textDirection: TextDirection.ltr, child: GestureDemo()),
|
||||
);
|
||||
final Finder finder = find.byType(GestureDemo);
|
||||
|
||||
MaterialColor getSwatch() => tester.state<GestureDemoState>(finder).swatch;
|
||||
|
||||
@@ -10,7 +10,9 @@ import '../../../rendering/custom_coordinate_systems.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/custom_coordinate_systems.dart', () {
|
||||
FlutterError.onError = (FlutterErrorDetails details) { throw details.exception; };
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
throw details.exception;
|
||||
};
|
||||
demo.main();
|
||||
expect(SchedulerBinding.instance.hasScheduledFrame, true);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,9 @@ import '../../../rendering/flex_layout.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/flex_layout.dart', () {
|
||||
FlutterError.onError = (FlutterErrorDetails details) { throw details.exception; };
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
throw details.exception;
|
||||
};
|
||||
demo.main();
|
||||
expect(SchedulerBinding.instance.hasScheduledFrame, true);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,9 @@ import '../../../rendering/hello_world.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/hello_world.dart', () {
|
||||
FlutterError.onError = (FlutterErrorDetails details) { throw details.exception; };
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
throw details.exception;
|
||||
};
|
||||
demo.main();
|
||||
expect(SchedulerBinding.instance.hasScheduledFrame, true);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,9 @@ import '../../../rendering/spinning_square.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/spinning_square.dart', () {
|
||||
FlutterError.onError = (FlutterErrorDetails details) { throw details.exception; };
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
throw details.exception;
|
||||
};
|
||||
demo.main();
|
||||
expect(SchedulerBinding.instance.hasScheduledFrame, true);
|
||||
});
|
||||
|
||||
@@ -10,7 +10,9 @@ import '../../../rendering/touch_input.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for rendering/touch_input.dart', () {
|
||||
FlutterError.onError = (FlutterErrorDetails details) { throw details.exception; };
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
throw details.exception;
|
||||
};
|
||||
demo.main();
|
||||
expect(SchedulerBinding.instance.hasScheduledFrame, true);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,9 @@ import '../../../widgets/spinning_mixed.dart' as demo;
|
||||
|
||||
void main() {
|
||||
test('layers smoketest for widgets/spinning_mixed.dart', () {
|
||||
FlutterError.onError = (FlutterErrorDetails details) { throw details.exception; };
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
throw details.exception;
|
||||
};
|
||||
demo.main();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class RenderDots extends RenderConstrainedBox {
|
||||
}
|
||||
|
||||
class Dots extends SingleChildRenderObjectWidget {
|
||||
const Dots({ super.key, super.child });
|
||||
const Dots({super.key, super.child});
|
||||
|
||||
@override
|
||||
RenderDots createRenderObject(BuildContext context) => RenderDots();
|
||||
@@ -50,11 +50,7 @@ void main() {
|
||||
runApp(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Dots(
|
||||
child: Center(
|
||||
child: Text('Touch me!'),
|
||||
),
|
||||
),
|
||||
child: Dots(child: Center(child: Text('Touch me!'))),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,28 +30,26 @@ class _GesturePainter extends CustomPainter {
|
||||
final Offset center = size.center(Offset.zero) * zoom + offset;
|
||||
final double radius = size.width / 2.0 * zoom;
|
||||
final Gradient gradient = RadialGradient(
|
||||
colors: forward
|
||||
? <Color>[swatch.shade50, swatch.shade900]
|
||||
: <Color>[swatch.shade900, swatch.shade50],
|
||||
colors:
|
||||
forward
|
||||
? <Color>[swatch.shade50, swatch.shade900]
|
||||
: <Color>[swatch.shade900, swatch.shade50],
|
||||
);
|
||||
final Paint paint = Paint()
|
||||
..shader = gradient.createShader(Rect.fromCircle(
|
||||
center: center,
|
||||
radius: radius,
|
||||
));
|
||||
final Paint paint =
|
||||
Paint()..shader = gradient.createShader(Rect.fromCircle(center: center, radius: radius));
|
||||
canvas.drawCircle(center, radius, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_GesturePainter oldPainter) {
|
||||
return oldPainter.zoom != zoom
|
||||
|| oldPainter.offset != offset
|
||||
|| oldPainter.swatch != swatch
|
||||
|| oldPainter.forward != forward
|
||||
|| oldPainter.scaleEnabled != scaleEnabled
|
||||
|| oldPainter.tapEnabled != tapEnabled
|
||||
|| oldPainter.doubleTapEnabled != doubleTapEnabled
|
||||
|| oldPainter.longPressEnabled != longPressEnabled;
|
||||
return oldPainter.zoom != zoom ||
|
||||
oldPainter.offset != offset ||
|
||||
oldPainter.swatch != swatch ||
|
||||
oldPainter.forward != forward ||
|
||||
oldPainter.scaleEnabled != scaleEnabled ||
|
||||
oldPainter.tapEnabled != tapEnabled ||
|
||||
oldPainter.doubleTapEnabled != doubleTapEnabled ||
|
||||
oldPainter.longPressEnabled != longPressEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +61,6 @@ class GestureDemo extends StatefulWidget {
|
||||
}
|
||||
|
||||
class GestureDemoState extends State<GestureDemo> {
|
||||
|
||||
late Offset _startingFocalPoint;
|
||||
|
||||
late Offset _previousOffset;
|
||||
@@ -180,7 +177,11 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: _scaleEnabled,
|
||||
onChanged: (bool? value) { setState(() { _scaleEnabled = value!; }); },
|
||||
onChanged: (bool? value) {
|
||||
setState(() {
|
||||
_scaleEnabled = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
const Text('Scale'),
|
||||
],
|
||||
@@ -189,7 +190,11 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: _tapEnabled,
|
||||
onChanged: (bool? value) { setState(() { _tapEnabled = value!; }); },
|
||||
onChanged: (bool? value) {
|
||||
setState(() {
|
||||
_tapEnabled = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
const Text('Tap'),
|
||||
],
|
||||
@@ -198,7 +203,11 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: _doubleTapEnabled,
|
||||
onChanged: (bool? value) { setState(() { _doubleTapEnabled = value!; }); },
|
||||
onChanged: (bool? value) {
|
||||
setState(() {
|
||||
_doubleTapEnabled = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
const Text('Double Tap'),
|
||||
],
|
||||
@@ -207,7 +216,11 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: _longPressEnabled,
|
||||
onChanged: (bool? value) { setState(() { _longPressEnabled = value!; }); },
|
||||
onChanged: (bool? value) {
|
||||
setState(() {
|
||||
_longPressEnabled = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
const Text('Long Press'),
|
||||
],
|
||||
@@ -223,11 +236,10 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(MaterialApp(
|
||||
theme: ThemeData.dark(),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('Gestures Demo')),
|
||||
body: const GestureDemo(),
|
||||
runApp(
|
||||
MaterialApp(
|
||||
theme: ThemeData.dark(),
|
||||
home: Scaffold(appBar: AppBar(title: const Text('Gestures Demo')), body: const GestureDemo()),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AdaptedListItem extends StatelessWidget {
|
||||
const AdaptedListItem({ super.key, required this.name });
|
||||
const AdaptedListItem({super.key, required this.name});
|
||||
|
||||
final String name;
|
||||
|
||||
@@ -26,7 +26,7 @@ class AdaptedListItem extends StatelessWidget {
|
||||
}
|
||||
|
||||
class AdaptedGridItem extends StatelessWidget {
|
||||
const AdaptedGridItem({ super.key, required this.name });
|
||||
const AdaptedGridItem({super.key, required this.name});
|
||||
|
||||
final String name;
|
||||
|
||||
@@ -35,22 +35,13 @@ class AdaptedGridItem extends StatelessWidget {
|
||||
return Card(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Container(
|
||||
color: Colors.lightBlueAccent.shade100,
|
||||
),
|
||||
),
|
||||
Expanded(child: Container(color: Colors.lightBlueAccent.shade100)),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 8.0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(name),
|
||||
),
|
||||
const IconButton(
|
||||
icon: Icon(Icons.more_vert),
|
||||
onPressed: null,
|
||||
),
|
||||
Expanded(child: Text(name)),
|
||||
const IconButton(icon: Icon(Icons.more_vert), onPressed: null),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -65,7 +56,7 @@ const double _kMaxTileWidth = 150.0;
|
||||
const double _kGridViewBreakpoint = 450.0;
|
||||
|
||||
class AdaptiveContainer extends StatelessWidget {
|
||||
const AdaptiveContainer({ super.key, required this.names });
|
||||
const AdaptiveContainer({super.key, required this.names});
|
||||
|
||||
final List<String> names;
|
||||
|
||||
@@ -90,13 +81,13 @@ List<String> _initNames() => List<String>.generate(30, (int i) => 'Item $i');
|
||||
final List<String> _kNames = _initNames();
|
||||
|
||||
void main() {
|
||||
runApp(MaterialApp(
|
||||
title: 'Media Query Example',
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Media Query Example'),
|
||||
runApp(
|
||||
MaterialApp(
|
||||
title: 'Media Query Example',
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('Media Query Example')),
|
||||
body: Material(child: AdaptiveContainer(names: _kNames)),
|
||||
),
|
||||
body: Material(child: AdaptiveContainer(names: _kNames)),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,7 @@ import 'package:flutter/material.dart';
|
||||
import '../rendering/src/sector_layout.dart';
|
||||
|
||||
RenderBoxToRenderSectorAdapter initCircle() {
|
||||
return RenderBoxToRenderSectorAdapter(
|
||||
innerRadius: 25.0,
|
||||
child: RenderSectorRing(),
|
||||
);
|
||||
return RenderBoxToRenderSectorAdapter(innerRadius: 25.0, child: RenderSectorRing());
|
||||
}
|
||||
|
||||
class SectorApp extends StatefulWidget {
|
||||
@@ -23,13 +20,13 @@ class SectorApp extends StatefulWidget {
|
||||
}
|
||||
|
||||
class SectorAppState extends State<SectorApp> {
|
||||
|
||||
final RenderBoxToRenderSectorAdapter sectors = initCircle();
|
||||
final math.Random rand = math.Random(1);
|
||||
|
||||
List<double> wantedSectorSizes = <double>[];
|
||||
List<double> actualSectorSizes = <double>[];
|
||||
double get currentTheta => wantedSectorSizes.fold<double>(0.0, (double total, double value) => total + value);
|
||||
double get currentTheta =>
|
||||
wantedSectorSizes.fold<double>(0.0, (double total, double value) => total + value);
|
||||
|
||||
void addSector() {
|
||||
final double currentTheta = this.currentTheta;
|
||||
@@ -54,7 +51,9 @@ class SectorAppState extends State<SectorApp> {
|
||||
|
||||
void doUpdates() {
|
||||
int index = 0;
|
||||
while (index < actualSectorSizes.length && index < wantedSectorSizes.length && actualSectorSizes[index] == wantedSectorSizes[index]) {
|
||||
while (index < actualSectorSizes.length &&
|
||||
index < wantedSectorSizes.length &&
|
||||
actualSectorSizes[index] == wantedSectorSizes[index]) {
|
||||
index += 1;
|
||||
}
|
||||
final RenderSectorRing ring = sectors.child! as RenderSectorRing;
|
||||
@@ -75,11 +74,9 @@ class SectorAppState extends State<SectorApp> {
|
||||
ring.add(RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kTwoPi * 0.15));
|
||||
ring.add(RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kTwoPi * 0.15));
|
||||
ring.add(RenderSolidColor(color, desiredDeltaTheta: kTwoPi * 0.2));
|
||||
return RenderBoxToRenderSectorAdapter(
|
||||
innerRadius: 5.0,
|
||||
child: ring,
|
||||
);
|
||||
return RenderBoxToRenderSectorAdapter(innerRadius: 5.0, child: ring);
|
||||
}
|
||||
|
||||
RenderBoxToRenderSectorAdapter sectorAddIcon = initSector(const Color(0xFF00DD00));
|
||||
RenderBoxToRenderSectorAdapter sectorRemoveIcon = initSector(const Color(0xFFDD0000));
|
||||
|
||||
@@ -154,9 +151,7 @@ class SectorAppState extends State<SectorApp> {
|
||||
Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(8.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(),
|
||||
),
|
||||
decoration: BoxDecoration(border: Border.all()),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: WidgetToRenderBoxAdapter(
|
||||
renderBox: sectors,
|
||||
@@ -177,9 +172,7 @@ class SectorAppState extends State<SectorApp> {
|
||||
theme: ThemeData.light(),
|
||||
title: 'Sector Layout',
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Sector Layout in a Widget Tree'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Sector Layout in a Widget Tree')),
|
||||
body: buildBody(),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:flutter/rendering.dart';
|
||||
import '../rendering/src/solid_color_box.dart';
|
||||
|
||||
// Solid color, RenderObject version
|
||||
void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex = 0 }) {
|
||||
void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, {int flex = 0}) {
|
||||
final RenderSolidColorBox child = RenderSolidColorBox(backgroundColor);
|
||||
parent.add(child);
|
||||
final FlexParentData childParentData = child.parentData! as FlexParentData;
|
||||
@@ -17,17 +17,13 @@ void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex
|
||||
|
||||
// Solid color, Widget version
|
||||
class Rectangle extends StatelessWidget {
|
||||
const Rectangle(this.color, { super.key });
|
||||
const Rectangle(this.color, {super.key});
|
||||
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
color: color,
|
||||
),
|
||||
);
|
||||
return Expanded(child: Container(color: color));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,12 +48,7 @@ void attachWidgetTreeToRenderTree(RenderProxyBox container) {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
ElevatedButton(
|
||||
child: const Row(
|
||||
children: <Widget>[
|
||||
FlutterLogo(),
|
||||
Text('PRESS ME'),
|
||||
],
|
||||
),
|
||||
child: const Row(children: <Widget>[FlutterLogo(), Text('PRESS ME')]),
|
||||
onPressed: () {
|
||||
value = value == null ? 0.1 : (value! + 0.1) % 1.0;
|
||||
attachWidgetTreeToRenderTree(container);
|
||||
@@ -81,7 +72,8 @@ late RenderTransform transformBox;
|
||||
|
||||
void rotate(Duration timeStamp) {
|
||||
timeBase ??= timeStamp;
|
||||
final double delta = (timeStamp - timeBase!).inMicroseconds.toDouble() / Duration.microsecondsPerSecond; // radians
|
||||
final double delta =
|
||||
(timeStamp - timeBase!).inMicroseconds.toDouble() / Duration.microsecondsPerSecond; // radians
|
||||
|
||||
transformBox.setIdentity();
|
||||
transformBox.rotateZ(delta);
|
||||
@@ -99,15 +91,19 @@ void main() {
|
||||
flexRoot.add(proxy);
|
||||
addFlexChildSolidColor(flexRoot, const Color(0xFF0000FF), flex: 1);
|
||||
|
||||
transformBox = RenderTransform(child: flexRoot, transform: Matrix4.identity(), alignment: Alignment.center);
|
||||
final RenderPadding root = RenderPadding(padding: const EdgeInsets.all(80.0), child: transformBox);
|
||||
transformBox = RenderTransform(
|
||||
child: flexRoot,
|
||||
transform: Matrix4.identity(),
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
final RenderPadding root = RenderPadding(
|
||||
padding: const EdgeInsets.all(80.0),
|
||||
child: transformBox,
|
||||
);
|
||||
|
||||
// TODO(goderbauer): Create a window if embedder doesn't provide an implicit view to draw into.
|
||||
assert(binding.platformDispatcher.implicitView != null);
|
||||
final RenderView view = RenderView(
|
||||
view: binding.platformDispatcher.implicitView!,
|
||||
child: root,
|
||||
);
|
||||
final RenderView view = RenderView(view: binding.platformDispatcher.implicitView!, child: root);
|
||||
final PipelineOwner pipelineOwner = PipelineOwner()..rootNode = view;
|
||||
binding.rootPipelineOwner.adoptChild(pipelineOwner);
|
||||
binding.addRenderView(view);
|
||||
|
||||
@@ -30,11 +30,7 @@ class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProvid
|
||||
Widget build(BuildContext context) {
|
||||
return RotationTransition(
|
||||
turns: _animation,
|
||||
child: Container(
|
||||
width: 200.0,
|
||||
height: 200.0,
|
||||
color: const Color(0xFF00FF00),
|
||||
),
|
||||
child: Container(width: 200.0, height: 200.0, color: const Color(0xFF00FF00)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@ Dave: What are you talking about, HAL?
|
||||
HAL: This mission is too important for me to allow you to jeopardize it.''';
|
||||
|
||||
// [["Dave", "Open the pod bay..."] ...]
|
||||
final List<List<String>> _kNameLines = _kDialogText
|
||||
.split('\n')
|
||||
.map<List<String>>((String line) => line.split(':'))
|
||||
.toList();
|
||||
final List<List<String>> _kNameLines =
|
||||
_kDialogText.split('\n').map<List<String>>((String line) => line.split(':')).toList();
|
||||
|
||||
final TextStyle _kDaveStyle = TextStyle(color: Colors.indigo.shade400, height: 1.8);
|
||||
final TextStyle _kHalStyle = TextStyle(color: Colors.red.shade400, fontFamily: 'monospace');
|
||||
@@ -41,13 +39,7 @@ Widget toStyledText(String name, String text) {
|
||||
children: <TextSpan>[
|
||||
TextSpan(
|
||||
style: _kBold,
|
||||
children: <TextSpan>[
|
||||
TextSpan(
|
||||
style: _kUnderline,
|
||||
text: name,
|
||||
),
|
||||
const TextSpan(text: ':'),
|
||||
],
|
||||
children: <TextSpan>[TextSpan(style: _kUnderline, text: name), const TextSpan(text: ':')],
|
||||
),
|
||||
TextSpan(text: text),
|
||||
],
|
||||
@@ -66,9 +58,7 @@ class SpeakerSeparator extends StatelessWidget {
|
||||
constraints: const BoxConstraints.expand(height: 0.0),
|
||||
margin: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 64.0),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Color.fromARGB(24, 0, 0, 0)),
|
||||
),
|
||||
border: Border(bottom: BorderSide(color: Color.fromARGB(24, 0, 0, 0))),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -99,13 +89,14 @@ class _StyledTextDemoState extends State<StyledTextDemo> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _kNameLines
|
||||
.map<Widget>((List<String> nameAndText) => _toText(nameAndText[0], nameAndText[1]))
|
||||
.expand((Widget line) => <Widget>[
|
||||
line,
|
||||
const SpeakerSeparator(),
|
||||
])
|
||||
.toList()..removeLast(),
|
||||
children:
|
||||
_kNameLines
|
||||
.map<Widget>(
|
||||
(List<String> nameAndText) => _toText(nameAndText[0], nameAndText[1]),
|
||||
)
|
||||
.expand((Widget line) => <Widget>[line, const SpeakerSeparator()])
|
||||
.toList()
|
||||
..removeLast(),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -113,16 +104,13 @@ class _StyledTextDemoState extends State<StyledTextDemo> {
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(MaterialApp(
|
||||
theme: ThemeData.light(),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Hal and Dave'),
|
||||
),
|
||||
body: Material(
|
||||
color: Colors.grey.shade50,
|
||||
child: const StyledTextDemo(),
|
||||
runApp(
|
||||
MaterialApp(
|
||||
theme: ThemeData.light(),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('Hal and Dave')),
|
||||
body: Material(color: Colors.grey.shade50, child: const StyledTextDemo()),
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user