Unnecessary new (#20138)
* enable lint unnecessary_new * fix tests * fix tests * fix tests
This commit is contained in:
committed by
GitHub
parent
d7a0dcaa4a
commit
d927c93310
@@ -13,17 +13,17 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
// First we create a PictureRecorder to record the commands we're going to
|
||||
// feed in the canvas. The PictureRecorder will eventually produce a Picture,
|
||||
// which is an immutable record of those commands.
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
|
||||
// Next, we create a canvas from the recorder. The canvas is an interface
|
||||
// which can receive drawing commands. The canvas interface is modeled after
|
||||
// the SkCanvas interface from Skia. The paintBounds establishes a "cull rect"
|
||||
// for the canvas, which lets the implementation discard any commands that
|
||||
// are entirely outside this rectangle.
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
|
||||
|
||||
final ui.Paint paint = new ui.Paint();
|
||||
canvas.drawPaint(new ui.Paint()..color = const ui.Color(0xFFFFFFFF));
|
||||
final ui.Paint paint = ui.Paint();
|
||||
canvas.drawPaint(ui.Paint()..color = const ui.Color(0xFFFFFFFF));
|
||||
|
||||
final ui.Size size = paintBounds.size;
|
||||
final ui.Offset mid = size.center(ui.Offset.zero);
|
||||
@@ -34,22 +34,22 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(-mid.dx / 2.0, logicalSize.height * 2.0);
|
||||
canvas.clipRect(new ui.Rect.fromLTRB(0.0, -logicalSize.height, logicalSize.width, radius));
|
||||
canvas.clipRect(ui.Rect.fromLTRB(0.0, -logicalSize.height, logicalSize.width, radius));
|
||||
|
||||
canvas.translate(mid.dx, mid.dy);
|
||||
paint.color = const ui.Color.fromARGB(128, 255, 0, 255);
|
||||
canvas.rotate(math.pi/4.0);
|
||||
|
||||
final ui.Gradient yellowBlue = new ui.Gradient.linear(
|
||||
new ui.Offset(-radius, -radius),
|
||||
final ui.Gradient yellowBlue = ui.Gradient.linear(
|
||||
ui.Offset(-radius, -radius),
|
||||
const ui.Offset(0.0, 0.0),
|
||||
<ui.Color>[const ui.Color(0xFFFFFF00), const ui.Color(0xFF0000FF)],
|
||||
);
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-radius, -radius, radius, radius),
|
||||
new ui.Paint()..shader = yellowBlue);
|
||||
canvas.drawRect(ui.Rect.fromLTRB(-radius, -radius, radius, radius),
|
||||
ui.Paint()..shader = yellowBlue);
|
||||
|
||||
// Scale x and y by 0.5.
|
||||
final Float64List scaleMatrix = new Float64List.fromList(<double>[
|
||||
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,
|
||||
@@ -72,12 +72,12 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
|
||||
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
final Float64List deviceTransform = new Float64List(16)
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder = new ui.SceneBuilder()
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
|
||||
@@ -11,24 +11,24 @@ void beginFrame(Duration timeStamp) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
|
||||
|
||||
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder(
|
||||
new ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
final ui.ParagraphBuilder paragraphBuilder = ui.ParagraphBuilder(
|
||||
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)
|
||||
..addText('Hello, world.');
|
||||
final ui.Paragraph paragraph = paragraphBuilder.build()
|
||||
..layout(new ui.ParagraphConstraints(width: logicalSize.width));
|
||||
..layout(ui.ParagraphConstraints(width: logicalSize.width));
|
||||
|
||||
final ui.Rect physicalBounds = ui.Offset.zero & (logicalSize * devicePixelRatio);
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, physicalBounds);
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, physicalBounds);
|
||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
||||
canvas.drawParagraph(paragraph, new ui.Offset(
|
||||
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 = new ui.SceneBuilder()
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
// TODO(abarth): We should be able to add a picture without pushing a
|
||||
// container layer first.
|
||||
..pushClipRect(physicalBounds)
|
||||
|
||||
@@ -20,8 +20,8 @@ void beginFrame(Duration timeStamp) {
|
||||
// PAINT
|
||||
|
||||
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
|
||||
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||
|
||||
// Here we determine the rotation according to the timeStamp given to us by
|
||||
@@ -29,19 +29,19 @@ void beginFrame(Duration timeStamp) {
|
||||
final double t = timeStamp.inMicroseconds / Duration.microsecondsPerMillisecond / 1800.0;
|
||||
canvas.rotate(math.pi * (t % 1.0));
|
||||
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||
canvas.drawRect(ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||
ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||
final ui.Picture picture = recorder.endRecording();
|
||||
|
||||
// COMPOSITE
|
||||
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
final Float64List deviceTransform = new Float64List(16)
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder = new ui.SceneBuilder()
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
|
||||
@@ -12,31 +12,31 @@ import 'dart:ui' as ui;
|
||||
ui.Paragraph paragraph;
|
||||
|
||||
ui.Picture paint(ui.Rect paintBounds) {
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
|
||||
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
|
||||
|
||||
canvas.translate(logicalSize.width / 2.0, logicalSize.height / 2.0);
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||
canvas.drawRect(ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||
ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||
|
||||
// The paint method of Paragraph draws the contents of the paragraph onto the
|
||||
// given canvas.
|
||||
canvas.drawParagraph(paragraph, new 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 = ui.window.devicePixelRatio;
|
||||
final Float64List deviceTransform = new Float64List(16)
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
final ui.SceneBuilder sceneBuilder = new ui.SceneBuilder()
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
@@ -52,18 +52,18 @@ void beginFrame(Duration timeStamp) {
|
||||
|
||||
void main() {
|
||||
// To create a paragraph of text, we use ParagraphBuilder.
|
||||
final ui.ParagraphBuilder builder = new ui.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.
|
||||
new ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
ui.ParagraphStyle(textDirection: ui.TextDirection.ltr),
|
||||
)
|
||||
// We first push a style that turns the text blue.
|
||||
..pushStyle(new ui.TextStyle(color: const ui.Color(0xFF0000FF)))
|
||||
..pushStyle(ui.TextStyle(color: const ui.Color(0xFF0000FF)))
|
||||
..addText('Hello, ')
|
||||
// The next run of text will be bold.
|
||||
..pushStyle(new ui.TextStyle(fontWeight: ui.FontWeight.bold))
|
||||
..pushStyle(ui.TextStyle(fontWeight: ui.FontWeight.bold))
|
||||
..addText('world. ')
|
||||
// The pop() command signals the end of the bold styling.
|
||||
..pop()
|
||||
@@ -84,7 +84,7 @@ void main() {
|
||||
// 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(new ui.ParagraphConstraints(width: 180.0));
|
||||
..layout(ui.ParagraphConstraints(width: 180.0));
|
||||
|
||||
// Finally, we register our beginFrame callback and kick off the first frame.
|
||||
ui.window.onBeginFrame = beginFrame;
|
||||
|
||||
@@ -14,21 +14,21 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
// First we create a PictureRecorder to record the commands we're going to
|
||||
// feed in the canvas. The PictureRecorder will eventually produce a Picture,
|
||||
// which is an immutable record of those commands.
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
|
||||
// Next, we create a canvas from the recorder. The canvas is an interface
|
||||
// which can receive drawing commands. The canvas interface is modeled after
|
||||
// the SkCanvas interface from Skia. The paintBounds establishes a "cull rect"
|
||||
// for the canvas, which lets the implementation discard any commands that
|
||||
// are entirely outside this rectangle.
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, paintBounds);
|
||||
|
||||
// The commands draw a circle in the center of the screen.
|
||||
final ui.Size size = paintBounds.size;
|
||||
canvas.drawCircle(
|
||||
size.center(ui.Offset.zero),
|
||||
size.shortestSide * 0.45,
|
||||
new ui.Paint()..color = color
|
||||
ui.Paint()..color = color
|
||||
);
|
||||
|
||||
// When we're done issuing painting commands, we end the recording an receive
|
||||
@@ -46,7 +46,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
|
||||
// This transform scales the x and y coordinates by the devicePixelRatio.
|
||||
final Float64List deviceTransform = new Float64List(16)
|
||||
final Float64List deviceTransform = Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
@@ -56,7 +56,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
// 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 = new ui.SceneBuilder()
|
||||
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
|
||||
@@ -9,17 +9,17 @@ import 'package:flutter/rendering.dart';
|
||||
import 'src/sector_layout.dart';
|
||||
|
||||
RenderBox buildSectorExample() {
|
||||
final RenderSectorRing rootCircle = new RenderSectorRing(padding: 20.0);
|
||||
rootCircle.add(new RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta: kTwoPi * 0.15));
|
||||
rootCircle.add(new RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta: kTwoPi * 0.4));
|
||||
final RenderSectorSlice stack = new RenderSectorSlice(padding: 2.0);
|
||||
stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20.0));
|
||||
stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20.0));
|
||||
stack.add(new RenderSolidColor(const Color(0xFF00FF00)));
|
||||
final RenderSectorRing rootCircle = RenderSectorRing(padding: 20.0);
|
||||
rootCircle.add(RenderSolidColor(const Color(0xFF00FFFF), desiredDeltaTheta: kTwoPi * 0.15));
|
||||
rootCircle.add(RenderSolidColor(const Color(0xFF0000FF), desiredDeltaTheta: kTwoPi * 0.4));
|
||||
final RenderSectorSlice stack = RenderSectorSlice(padding: 2.0);
|
||||
stack.add(RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20.0));
|
||||
stack.add(RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20.0));
|
||||
stack.add(RenderSolidColor(const Color(0xFF00FF00)));
|
||||
rootCircle.add(stack);
|
||||
return new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle);
|
||||
return RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle);
|
||||
}
|
||||
|
||||
void main() {
|
||||
new RenderingFlutterBinding(root: buildSectorExample());
|
||||
RenderingFlutterBinding(root: buildSectorExample());
|
||||
}
|
||||
|
||||
@@ -10,42 +10,42 @@ import 'package:flutter/rendering.dart';
|
||||
import 'src/solid_color_box.dart';
|
||||
|
||||
void main() {
|
||||
final RenderFlex table = new RenderFlex(direction: Axis.vertical, textDirection: TextDirection.ltr);
|
||||
final RenderFlex table = RenderFlex(direction: Axis.vertical, textDirection: TextDirection.ltr);
|
||||
|
||||
void addAlignmentRow(CrossAxisAlignment crossAxisAlignment) {
|
||||
TextStyle style = const TextStyle(color: Color(0xFF000000));
|
||||
final RenderParagraph paragraph = new RenderParagraph(
|
||||
new TextSpan(style: style, text: '$crossAxisAlignment'),
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
TextSpan(style: style, text: '$crossAxisAlignment'),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
|
||||
final RenderFlex row = new RenderFlex(crossAxisAlignment: crossAxisAlignment, textBaseline: TextBaseline.alphabetic, 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);
|
||||
style = const TextStyle(fontSize: 15.0, color: Color(0xFF000000));
|
||||
row.add(new RenderDecoratedBox(
|
||||
row.add(RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FFFCCCC)),
|
||||
child: new RenderParagraph(
|
||||
new TextSpan(style: style, text: 'foo foo foo'),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
));
|
||||
style = const TextStyle(fontSize: 10.0, color: Color(0xFF000000));
|
||||
row.add(new RenderDecoratedBox(
|
||||
row.add(RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FCCFFCC)),
|
||||
child: new RenderParagraph(
|
||||
new TextSpan(style: style, text: 'foo foo foo'),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
));
|
||||
final RenderFlex subrow = new 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(new RenderDecoratedBox(
|
||||
subrow.add(RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0x7FCCCCFF)),
|
||||
child: new RenderParagraph(
|
||||
new TextSpan(style: style, text: 'foo foo foo foo'),
|
||||
child: RenderParagraph(
|
||||
TextSpan(style: style, text: 'foo foo foo foo'),
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
));
|
||||
subrow.add(new RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
|
||||
subrow.add(RenderSolidColorBox(const Color(0x7FCCFFFF), desiredSize: const Size(30.0, 40.0)));
|
||||
row.add(subrow);
|
||||
table.add(row);
|
||||
final FlexParentData rowParentData = row.parentData;
|
||||
@@ -60,15 +60,15 @@ void main() {
|
||||
|
||||
void addJustificationRow(MainAxisAlignment justify) {
|
||||
const TextStyle style = TextStyle(color: Color(0xFF000000));
|
||||
final RenderParagraph paragraph = new RenderParagraph(
|
||||
new TextSpan(style: style, text: '$justify'),
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
TextSpan(style: style, text: '$justify'),
|
||||
textDirection: TextDirection.ltr,
|
||||
);
|
||||
table.add(new RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
|
||||
final RenderFlex row = new RenderFlex(direction: Axis.horizontal, textDirection: TextDirection.ltr);
|
||||
row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: const Size(80.0, 60.0)));
|
||||
row.add(new RenderSolidColorBox(const Color(0xFFCCFFCC), desiredSize: const Size(64.0, 60.0)));
|
||||
row.add(new RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: const Size(160.0, 60.0)));
|
||||
table.add(RenderPadding(child: paragraph, padding: const EdgeInsets.only(top: 20.0)));
|
||||
final RenderFlex row = RenderFlex(direction: Axis.horizontal, textDirection: TextDirection.ltr);
|
||||
row.add(RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: const Size(80.0, 60.0)));
|
||||
row.add(RenderSolidColorBox(const Color(0xFFCCFFCC), desiredSize: const Size(64.0, 60.0)));
|
||||
row.add(RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: const Size(160.0, 60.0)));
|
||||
row.mainAxisAlignment = justify;
|
||||
table.add(row);
|
||||
final FlexParentData rowParentData = row.parentData;
|
||||
@@ -81,10 +81,10 @@ void main() {
|
||||
addJustificationRow(MainAxisAlignment.spaceBetween);
|
||||
addJustificationRow(MainAxisAlignment.spaceAround);
|
||||
|
||||
final RenderDecoratedBox root = new RenderDecoratedBox(
|
||||
final RenderDecoratedBox root = RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0xFFFFFFFF)),
|
||||
child: new RenderPadding(child: table, padding: const EdgeInsets.symmetric(vertical: 50.0)),
|
||||
child: RenderPadding(child: table, padding: const EdgeInsets.symmetric(vertical: 50.0)),
|
||||
);
|
||||
|
||||
new RenderingFlutterBinding(root: root);
|
||||
RenderingFlutterBinding(root: root);
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ import 'package:flutter/rendering.dart';
|
||||
|
||||
void main() {
|
||||
// We use RenderingFlutterBinding to attach the render tree to the window.
|
||||
new RenderingFlutterBinding(
|
||||
RenderingFlutterBinding(
|
||||
// The root of our render tree is a RenderPositionedBox, which centers its
|
||||
// child both vertically and horizontally.
|
||||
root: new RenderPositionedBox(
|
||||
root: RenderPositionedBox(
|
||||
alignment: Alignment.center,
|
||||
// We use a RenderParagraph to display the text 'Hello, world.' without
|
||||
// any explicit styling.
|
||||
child: new RenderParagraph(
|
||||
child: RenderParagraph(
|
||||
const TextSpan(text: 'Hello, world.'),
|
||||
// The text is in English so we specify the text direction as
|
||||
// left-to-right. If the text had been in Hebrew or Arabic, we would
|
||||
|
||||
@@ -14,17 +14,17 @@ import 'package:flutter/scheduler.dart';
|
||||
class NonStopVSync implements TickerProvider {
|
||||
const NonStopVSync();
|
||||
@override
|
||||
Ticker createTicker(TickerCallback onTick) => new Ticker(onTick);
|
||||
Ticker createTicker(TickerCallback onTick) => Ticker(onTick);
|
||||
}
|
||||
|
||||
void main() {
|
||||
// We first create a render object that represents a green box.
|
||||
final RenderBox green = new RenderDecoratedBox(
|
||||
final RenderBox green = RenderDecoratedBox(
|
||||
decoration: const BoxDecoration(color: Color(0xFF00FF00))
|
||||
);
|
||||
// Second, we wrap that green box in a render object that forces the green box
|
||||
// to have a specific size.
|
||||
final RenderBox square = new RenderConstrainedBox(
|
||||
final RenderBox square = RenderConstrainedBox(
|
||||
additionalConstraints: const BoxConstraints.tightFor(width: 200.0, height: 200.0),
|
||||
child: green
|
||||
);
|
||||
@@ -32,29 +32,29 @@ void main() {
|
||||
// transform before painting its child. Each frame of the animation, we'll
|
||||
// update the transform of this render object to cause the green square to
|
||||
// spin.
|
||||
final RenderTransform spin = new RenderTransform(
|
||||
transform: new Matrix4.identity(),
|
||||
final RenderTransform spin = RenderTransform(
|
||||
transform: Matrix4.identity(),
|
||||
alignment: Alignment.center,
|
||||
child: square
|
||||
);
|
||||
// Finally, we center the spinning green square...
|
||||
final RenderBox root = new RenderPositionedBox(
|
||||
final RenderBox root = RenderPositionedBox(
|
||||
alignment: Alignment.center,
|
||||
child: spin
|
||||
);
|
||||
// and attach it to the window.
|
||||
new RenderingFlutterBinding(root: root);
|
||||
RenderingFlutterBinding(root: root);
|
||||
|
||||
// To make the square spin, we use an animation that repeats every 1800
|
||||
// milliseconds.
|
||||
final AnimationController animation = new AnimationController(
|
||||
final AnimationController animation = AnimationController(
|
||||
duration: const Duration(milliseconds: 1800),
|
||||
vsync: const NonStopVSync(),
|
||||
)..repeat();
|
||||
// The animation will produce a value between 0.0 and 1.0 each frame, but we
|
||||
// want to rotate the square using a value between 0.0 and math.pi. To change
|
||||
// the range of the animation, we use a Tween.
|
||||
final Tween<double> tween = new Tween<double>(begin: 0.0, end: math.pi);
|
||||
final Tween<double> tween = Tween<double>(begin: 0.0, end: math.pi);
|
||||
// We add a listener to the animation, which will be called every time the
|
||||
// animation ticks.
|
||||
animation.addListener(() {
|
||||
@@ -63,6 +63,6 @@ void main() {
|
||||
// of the animation. Setting this value will mark a number of dirty bits
|
||||
// inside the render tree, which cause the render tree to repaint with the
|
||||
// new transform value this frame.
|
||||
spin.transform = new Matrix4.rotationZ(tween.evaluate(animation));
|
||||
spin.transform = Matrix4.rotationZ(tween.evaluate(animation));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class SectorDimensions {
|
||||
SectorConstraints constraints,
|
||||
{ double deltaRadius = 0.0, double deltaTheta = 0.0 }
|
||||
) {
|
||||
return new SectorDimensions(
|
||||
return SectorDimensions(
|
||||
deltaRadius: constraints.constrainDeltaRadius(deltaRadius),
|
||||
deltaTheta: constraints.constrainDeltaTheta(deltaTheta)
|
||||
);
|
||||
@@ -80,7 +80,7 @@ abstract class RenderSector extends RenderObject {
|
||||
@override
|
||||
void setupParentData(RenderObject child) {
|
||||
if (child.parentData is! SectorParentData)
|
||||
child.parentData = new SectorParentData();
|
||||
child.parentData = SectorParentData();
|
||||
}
|
||||
|
||||
// RenderSectors always use SectorParentData subclasses, as they need to be
|
||||
@@ -89,7 +89,7 @@ abstract class RenderSector extends RenderObject {
|
||||
SectorParentData get parentData => super.parentData;
|
||||
|
||||
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
||||
return new SectorDimensions.withConstraints(constraints);
|
||||
return SectorDimensions.withConstraints(constraints);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -124,17 +124,17 @@ abstract class RenderSector extends RenderObject {
|
||||
}
|
||||
|
||||
@override
|
||||
Rect get paintBounds => new Rect.fromLTWH(0.0, 0.0, 2.0 * deltaRadius, 2.0 * deltaRadius);
|
||||
Rect get paintBounds => Rect.fromLTWH(0.0, 0.0, 2.0 * deltaRadius, 2.0 * deltaRadius);
|
||||
|
||||
@override
|
||||
Rect get semanticBounds => new 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(HitTestResult result, { double radius, 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(new HitTestEntry(this));
|
||||
result.add(HitTestEntry(this));
|
||||
return true;
|
||||
}
|
||||
void hitTestChildren(HitTestResult result, { double radius, double theta }) { }
|
||||
@@ -168,13 +168,13 @@ abstract class RenderDecoratedSector extends RenderSector {
|
||||
|
||||
if (_decoration.color != null) {
|
||||
final Canvas canvas = context.canvas;
|
||||
final Paint paint = new Paint()..color = _decoration.color;
|
||||
final Path path = new Path();
|
||||
final Paint paint = Paint()..color = _decoration.color;
|
||||
final Path path = Path();
|
||||
final double outerRadius = parentData.radius + deltaRadius;
|
||||
final Rect outerBounds = new 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 = new 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);
|
||||
@@ -248,7 +248,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
|
||||
void setupParentData(RenderObject child) {
|
||||
// TODO(ianh): avoid code duplication
|
||||
if (child.parentData is! SectorChildListParentData)
|
||||
child.parentData = new SectorChildListParentData();
|
||||
child.parentData = SectorChildListParentData();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -261,7 +261,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
|
||||
double remainingDeltaTheta = math.max(0.0, constraints.maxDeltaTheta - (innerTheta + paddingTheta));
|
||||
RenderSector child = firstChild;
|
||||
while (child != null) {
|
||||
final SectorConstraints innerConstraints = new SectorConstraints(
|
||||
final SectorConstraints innerConstraints = SectorConstraints(
|
||||
maxDeltaRadius: innerDeltaRadius,
|
||||
maxDeltaTheta: remainingDeltaTheta
|
||||
);
|
||||
@@ -275,7 +275,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
|
||||
remainingDeltaTheta -= paddingTheta;
|
||||
}
|
||||
}
|
||||
return new SectorDimensions.withConstraints(constraints,
|
||||
return SectorDimensions.withConstraints(constraints,
|
||||
deltaRadius: outerDeltaRadius,
|
||||
deltaTheta: innerTheta);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ class RenderSectorRing extends RenderSectorWithChildren {
|
||||
double remainingDeltaTheta = constraints.maxDeltaTheta - (innerTheta + paddingTheta);
|
||||
RenderSector child = firstChild;
|
||||
while (child != null) {
|
||||
final SectorConstraints innerConstraints = new SectorConstraints(
|
||||
final SectorConstraints innerConstraints = SectorConstraints(
|
||||
maxDeltaRadius: innerDeltaRadius,
|
||||
maxDeltaTheta: remainingDeltaTheta
|
||||
);
|
||||
@@ -362,7 +362,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
void setupParentData(RenderObject child) {
|
||||
// TODO(ianh): avoid code duplication
|
||||
if (child.parentData is! SectorChildListParentData)
|
||||
child.parentData = new SectorChildListParentData();
|
||||
child.parentData = SectorChildListParentData();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -375,7 +375,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
|
||||
RenderSector child = firstChild;
|
||||
while (child != null) {
|
||||
final SectorConstraints innerConstraints = new SectorConstraints(
|
||||
final SectorConstraints innerConstraints = SectorConstraints(
|
||||
maxDeltaRadius: remainingDeltaRadius,
|
||||
maxDeltaTheta: innerDeltaTheta
|
||||
);
|
||||
@@ -387,7 +387,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
childRadius += padding;
|
||||
remainingDeltaRadius -= padding;
|
||||
}
|
||||
return new SectorDimensions.withConstraints(constraints,
|
||||
return SectorDimensions.withConstraints(constraints,
|
||||
deltaRadius: childRadius - parentData.radius,
|
||||
deltaTheta: outerDeltaTheta);
|
||||
}
|
||||
@@ -404,7 +404,7 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
|
||||
RenderSector child = firstChild;
|
||||
while (child != null) {
|
||||
final SectorConstraints innerConstraints = new SectorConstraints(
|
||||
final SectorConstraints innerConstraints = SectorConstraints(
|
||||
maxDeltaRadius: remainingDeltaRadius,
|
||||
maxDeltaTheta: innerDeltaTheta
|
||||
);
|
||||
@@ -455,7 +455,7 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
@override
|
||||
void setupParentData(RenderObject child) {
|
||||
if (child.parentData is! SectorParentData)
|
||||
child.parentData = new SectorParentData();
|
||||
child.parentData = SectorParentData();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -497,9 +497,9 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
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(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius);
|
||||
final SectorDimensions childDimensions = child.getIntrinsicDimensions(SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius);
|
||||
final double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0;
|
||||
return new Size.square(dimension);
|
||||
return Size.square(dimension);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -513,9 +513,9 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
final double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
|
||||
child.parentData.radius = innerRadius;
|
||||
child.parentData.theta = 0.0;
|
||||
child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
|
||||
child.layout(SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
|
||||
final double dimension = (innerRadius + child.deltaRadius) * 2.0;
|
||||
size = constraints.constrain(new Size(dimension, dimension));
|
||||
size = constraints.constrain(Size(dimension, dimension));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -547,7 +547,7 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
if (theta > child.deltaTheta)
|
||||
return false;
|
||||
child.hitTest(result, radius: radius, theta: theta);
|
||||
result.add(new BoxHitTestEntry(this, position));
|
||||
result.add(BoxHitTestEntry(this, position));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -557,7 +557,7 @@ class RenderSolidColor extends RenderDecoratedSector {
|
||||
RenderSolidColor(this.backgroundColor, {
|
||||
this.desiredDeltaRadius = double.infinity,
|
||||
this.desiredDeltaTheta = kTwoPi
|
||||
}) : super(new BoxDecoration(color: backgroundColor));
|
||||
}) : super(BoxDecoration(color: backgroundColor));
|
||||
|
||||
double desiredDeltaRadius;
|
||||
double desiredDeltaTheta;
|
||||
@@ -565,7 +565,7 @@ class RenderSolidColor extends RenderDecoratedSector {
|
||||
|
||||
@override
|
||||
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
||||
return new SectorDimensions.withConstraints(constraints, deltaTheta: desiredDeltaTheta);
|
||||
return SectorDimensions.withConstraints(constraints, deltaTheta: desiredDeltaTheta);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -579,7 +579,7 @@ class RenderSolidColor extends RenderDecoratedSector {
|
||||
if (event is PointerDownEvent) {
|
||||
decoration = const BoxDecoration(color: Color(0xFFFF0000));
|
||||
} else if (event is PointerUpEvent) {
|
||||
decoration = new BoxDecoration(color: backgroundColor);
|
||||
decoration = BoxDecoration(color: backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class RenderSolidColorBox extends RenderDecoratedBox {
|
||||
final Color backgroundColor;
|
||||
|
||||
RenderSolidColorBox(this.backgroundColor, { this.desiredSize = Size.infinite })
|
||||
: super(decoration: new BoxDecoration(color: backgroundColor));
|
||||
: super(decoration: BoxDecoration(color: backgroundColor));
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
@@ -42,7 +42,7 @@ class RenderSolidColorBox extends RenderDecoratedBox {
|
||||
if (event is PointerDownEvent) {
|
||||
decoration = const BoxDecoration(color: Color(0xFFFF0000));
|
||||
} else if (event is PointerUpEvent) {
|
||||
decoration = new BoxDecoration(color: backgroundColor);
|
||||
decoration = BoxDecoration(color: backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ List<Color> _kColors = <Color>[
|
||||
|
||||
/// A simple model object for a dot that reacts to pointer pressure.
|
||||
class Dot {
|
||||
Dot({ Color color }) : _paint = new Paint()..color = color;
|
||||
Dot({ Color color }) : _paint = Paint()..color = color;
|
||||
|
||||
final Paint _paint;
|
||||
Offset position = Offset.zero;
|
||||
@@ -66,7 +66,7 @@ class RenderDots extends RenderBox {
|
||||
void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
|
||||
if (event is PointerDownEvent) {
|
||||
final Color color = _kColors[event.pointer.remainder(_kColors.length)];
|
||||
_dots[event.pointer] = new Dot(color: color)..update(event);
|
||||
_dots[event.pointer] = Dot(color: color)..update(event);
|
||||
// We call markNeedsPaint to indicate that our painting commands have
|
||||
// changed and that paint needs to be called before displaying a new frame
|
||||
// to the user. It's harmless to call markNeedsPaint multiple times
|
||||
@@ -91,7 +91,7 @@ class RenderDots extends RenderBox {
|
||||
// Passing offset during the render tree's paint walk is an optimization to
|
||||
// avoid having to change the origin of the canvas's coordinate system too
|
||||
// often.
|
||||
canvas.drawRect(offset & size, new Paint()..color = const Color(0xFFFFFFFF));
|
||||
canvas.drawRect(offset & size, Paint()..color = const Color(0xFFFFFFFF));
|
||||
|
||||
// We iterate through our model and paint each dot.
|
||||
for (Dot dot in _dots.values)
|
||||
@@ -101,7 +101,7 @@ class RenderDots extends RenderBox {
|
||||
|
||||
void main() {
|
||||
// Create some styled text to tell the user to interact with the app.
|
||||
final RenderParagraph paragraph = new RenderParagraph(
|
||||
final RenderParagraph paragraph = RenderParagraph(
|
||||
const TextSpan(
|
||||
style: TextStyle(color: Colors.black87),
|
||||
text: 'Touch me!',
|
||||
@@ -111,10 +111,10 @@ void main() {
|
||||
// A stack is a render object that layers its children on top of each other.
|
||||
// The bottom later is our RenderDots object, and on top of that we show the
|
||||
// text.
|
||||
final RenderStack stack = new RenderStack(
|
||||
final RenderStack stack = RenderStack(
|
||||
textDirection: TextDirection.ltr,
|
||||
children: <RenderBox>[
|
||||
new RenderDots(),
|
||||
RenderDots(),
|
||||
paragraph,
|
||||
],
|
||||
);
|
||||
@@ -132,5 +132,5 @@ void main() {
|
||||
..left = 20.0;
|
||||
|
||||
// Finally, we attach the render tree we've built to the screen.
|
||||
new RenderingFlutterBinding(root: stack);
|
||||
RenderingFlutterBinding(root: stack);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class Calculator {
|
||||
// Run the computation associated with this Calculator.
|
||||
void run() {
|
||||
int i = 0;
|
||||
final JsonDecoder decoder = new JsonDecoder(
|
||||
final JsonDecoder decoder = JsonDecoder(
|
||||
(dynamic key, dynamic value) {
|
||||
if (key is int && i++ % _NOTIFY_INTERVAL == 0)
|
||||
onProgressListener(i.toDouble(), _NUM_ITEMS.toDouble());
|
||||
@@ -54,7 +54,7 @@ class Calculator {
|
||||
}
|
||||
|
||||
static String _replicateJson(String data, int count) {
|
||||
final StringBuffer buffer = new StringBuffer()..write('[');
|
||||
final StringBuffer buffer = StringBuffer()..write('[');
|
||||
for (int i = 0; i < count; i++) {
|
||||
buffer.write(data);
|
||||
if (i < count - 1)
|
||||
@@ -88,7 +88,7 @@ class CalculationManager {
|
||||
CalculationManager({ @required this.onProgressListener, @required this.onResultListener })
|
||||
: assert(onProgressListener != null),
|
||||
assert(onResultListener != null),
|
||||
_receivePort = new ReceivePort() {
|
||||
_receivePort = ReceivePort() {
|
||||
_receivePort.listen(_handleMessage);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ class CalculationManager {
|
||||
// loaded.
|
||||
rootBundle.loadString('services/data.json').then<Null>((String data) {
|
||||
if (isRunning) {
|
||||
final CalculationMessage message = new CalculationMessage(data, _receivePort.sendPort);
|
||||
final CalculationMessage message = CalculationMessage(data, _receivePort.sendPort);
|
||||
// Spawn an isolate to JSON-parse the file contents. The JSON parsing
|
||||
// is synchronous, so if done in the main isolate, the UI would block.
|
||||
Isolate.spawn(_calculate, message).then<Null>((Isolate isolate) {
|
||||
@@ -178,7 +178,7 @@ class CalculationManager {
|
||||
// in a separate memory space.
|
||||
static void _calculate(CalculationMessage message) {
|
||||
final SendPort sender = message.sendPort;
|
||||
final Calculator calculator = new Calculator(
|
||||
final Calculator calculator = Calculator(
|
||||
onProgressListener: (double completed, double total) {
|
||||
sender.send(<double>[ completed, total ]);
|
||||
},
|
||||
@@ -199,7 +199,7 @@ class CalculationManager {
|
||||
// the AnimationController for the running animation.
|
||||
class IsolateExampleWidget extends StatefulWidget {
|
||||
@override
|
||||
IsolateExampleState createState() => new IsolateExampleState();
|
||||
IsolateExampleState createState() => IsolateExampleState();
|
||||
}
|
||||
|
||||
// Main application state.
|
||||
@@ -215,11 +215,11 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animation = new AnimationController(
|
||||
_animation = AnimationController(
|
||||
duration: const Duration(milliseconds: 3600),
|
||||
vsync: this,
|
||||
)..repeat();
|
||||
_calculationManager = new CalculationManager(
|
||||
_calculationManager = CalculationManager(
|
||||
onProgressListener: _handleProgressUpdate,
|
||||
onResultListener: _handleResult
|
||||
);
|
||||
@@ -233,32 +233,32 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Material(
|
||||
child: new Column(
|
||||
return Material(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
new RotationTransition(
|
||||
RotationTransition(
|
||||
turns: _animation,
|
||||
child: new Container(
|
||||
child: Container(
|
||||
width: 120.0,
|
||||
height: 120.0,
|
||||
color: const Color(0xFF882222),
|
||||
)
|
||||
),
|
||||
new Opacity(
|
||||
Opacity(
|
||||
opacity: _calculationManager.isRunning ? 1.0 : 0.0,
|
||||
child: new CircularProgressIndicator(
|
||||
child: CircularProgressIndicator(
|
||||
value: _progress
|
||||
)
|
||||
),
|
||||
new Text(_status),
|
||||
new Center(
|
||||
child: new RaisedButton(
|
||||
child: new Text(_label),
|
||||
Text(_status),
|
||||
Center(
|
||||
child: RaisedButton(
|
||||
child: Text(_label),
|
||||
onPressed: _handleButtonPressed
|
||||
)
|
||||
),
|
||||
new Text(_result)
|
||||
Text(_result)
|
||||
]
|
||||
)
|
||||
);
|
||||
@@ -303,5 +303,5 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new MaterialApp(home: new IsolateExampleWidget()));
|
||||
runApp(MaterialApp(home: IsolateExampleWidget()));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class LifecycleWatcher extends StatefulWidget {
|
||||
const LifecycleWatcher({ Key key }) : super(key: key);
|
||||
|
||||
@override
|
||||
_LifecycleWatcherState createState() => new _LifecycleWatcherState();
|
||||
_LifecycleWatcherState createState() => _LifecycleWatcherState();
|
||||
}
|
||||
|
||||
class _LifecycleWatcherState extends State<LifecycleWatcher>
|
||||
@@ -38,7 +38,7 @@ class _LifecycleWatcherState extends State<LifecycleWatcher>
|
||||
Widget build(BuildContext context) {
|
||||
if (_lastLifecycleState == null)
|
||||
return const Text('This widget has not observed any lifecycle changes.');
|
||||
return new Text('The most recent lifecycle state this widget observed was: $_lastLifecycleState.');
|
||||
return Text('The most recent lifecycle state this widget observed was: $_lastLifecycleState.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import '../widgets/gestures.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Tap on center change color', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(new Directionality(
|
||||
await tester.pumpWidget(Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: new GestureDemo(),
|
||||
child: GestureDemo(),
|
||||
));
|
||||
final Finder finder = find.byType(GestureDemo);
|
||||
|
||||
|
||||
@@ -13,6 +13,6 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('Sector Sixes', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(new SectorApp());
|
||||
await tester.pumpWidget(SectorApp());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ class RenderDots extends RenderConstrainedBox {
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
final Canvas canvas = context.canvas;
|
||||
canvas.drawRect(offset & size, new Paint()..color = const Color(0xFF0000FF));
|
||||
canvas.drawRect(offset & size, Paint()..color = const Color(0xFF0000FF));
|
||||
|
||||
final Paint paint = new Paint()..color = const Color(0xFF00FF00);
|
||||
final Paint paint = Paint()..color = const Color(0xFF00FF00);
|
||||
for (Offset point in _dots.values)
|
||||
canvas.drawCircle(point, 50.0, paint);
|
||||
|
||||
@@ -42,7 +42,7 @@ class Dots extends SingleChildRenderObjectWidget {
|
||||
const Dots({ Key key, Widget child }) : super(key: key, child: child);
|
||||
|
||||
@override
|
||||
RenderDots createRenderObject(BuildContext context) => new RenderDots();
|
||||
RenderDots createRenderObject(BuildContext context) => RenderDots();
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -29,12 +29,12 @@ class _GesturePainter extends CustomPainter {
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final Offset center = size.center(Offset.zero) * zoom + offset;
|
||||
final double radius = size.width / 2.0 * zoom;
|
||||
final Gradient gradient = new RadialGradient(
|
||||
final Gradient gradient = RadialGradient(
|
||||
colors: forward ? <Color>[swatch.shade50, swatch.shade900]
|
||||
: <Color>[swatch.shade900, swatch.shade50]
|
||||
);
|
||||
final Paint paint = new Paint()
|
||||
..shader = gradient.createShader(new Rect.fromCircle(
|
||||
final Paint paint = Paint()
|
||||
..shader = gradient.createShader(Rect.fromCircle(
|
||||
center: center,
|
||||
radius: radius,
|
||||
));
|
||||
@@ -56,7 +56,7 @@ class _GesturePainter extends CustomPainter {
|
||||
|
||||
class GestureDemo extends StatefulWidget {
|
||||
@override
|
||||
GestureDemoState createState() => new GestureDemoState();
|
||||
GestureDemoState createState() => GestureDemoState();
|
||||
}
|
||||
|
||||
class GestureDemoState extends State<GestureDemo> {
|
||||
@@ -141,17 +141,17 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Stack(
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: <Widget>[
|
||||
new GestureDetector(
|
||||
GestureDetector(
|
||||
onScaleStart: _scaleEnabled ? _handleScaleStart : null,
|
||||
onScaleUpdate: _scaleEnabled ? _handleScaleUpdate : null,
|
||||
onTap: _tapEnabled ? _handleColorChange : null,
|
||||
onDoubleTap: _doubleTapEnabled ? _handleScaleReset : null,
|
||||
onLongPress: _longPressEnabled ? _handleDirectionChange : null,
|
||||
child: new CustomPaint(
|
||||
painter: new _GesturePainter(
|
||||
child: CustomPaint(
|
||||
painter: _GesturePainter(
|
||||
zoom: _zoom,
|
||||
offset: _offset,
|
||||
swatch: swatch,
|
||||
@@ -163,44 +163,44 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
)
|
||||
)
|
||||
),
|
||||
new Positioned(
|
||||
Positioned(
|
||||
bottom: 0.0,
|
||||
left: 0.0,
|
||||
child: new Card(
|
||||
child: new Container(
|
||||
child: Card(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: new Column(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
new Row(
|
||||
Row(
|
||||
children: <Widget>[
|
||||
new Checkbox(
|
||||
Checkbox(
|
||||
value: _scaleEnabled,
|
||||
onChanged: (bool value) { setState(() { _scaleEnabled = value; }); }
|
||||
),
|
||||
const Text('Scale'),
|
||||
]
|
||||
),
|
||||
new Row(
|
||||
Row(
|
||||
children: <Widget>[
|
||||
new Checkbox(
|
||||
Checkbox(
|
||||
value: _tapEnabled,
|
||||
onChanged: (bool value) { setState(() { _tapEnabled = value; }); }
|
||||
),
|
||||
const Text('Tap'),
|
||||
]
|
||||
),
|
||||
new Row(
|
||||
Row(
|
||||
children: <Widget>[
|
||||
new Checkbox(
|
||||
Checkbox(
|
||||
value: _doubleTapEnabled,
|
||||
onChanged: (bool value) { setState(() { _doubleTapEnabled = value; }); }
|
||||
),
|
||||
const Text('Double Tap'),
|
||||
]
|
||||
),
|
||||
new Row(
|
||||
Row(
|
||||
children: <Widget>[
|
||||
new Checkbox(
|
||||
Checkbox(
|
||||
value: _longPressEnabled,
|
||||
onChanged: (bool value) { setState(() { _longPressEnabled = value; }); }
|
||||
),
|
||||
@@ -219,11 +219,11 @@ class GestureDemoState extends State<GestureDemo> {
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new MaterialApp(
|
||||
theme: new ThemeData.dark(),
|
||||
home: new Scaffold(
|
||||
appBar: new AppBar(title: const Text('Gestures Demo')),
|
||||
body: new GestureDemo()
|
||||
runApp(MaterialApp(
|
||||
theme: ThemeData.dark(),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('Gestures Demo')),
|
||||
body: GestureDemo()
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -11,15 +11,15 @@ class AdaptedListItem extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Row(
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
Container(
|
||||
width: 32.0,
|
||||
height: 32.0,
|
||||
margin: const EdgeInsets.all(8.0),
|
||||
color: Colors.lightBlueAccent.shade100,
|
||||
),
|
||||
new Text(name)
|
||||
Text(name)
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -32,20 +32,20 @@ class AdaptedGridItem extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Card(
|
||||
child: new Column(
|
||||
return Card(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
new Expanded(
|
||||
child: new Container(
|
||||
Expanded(
|
||||
child: Container(
|
||||
color: Colors.lightBlueAccent.shade100,
|
||||
)
|
||||
),
|
||||
new Container(
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 8.0),
|
||||
child: new Row(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Expanded(
|
||||
child: new Text(name)
|
||||
Expanded(
|
||||
child: Text(name)
|
||||
),
|
||||
const IconButton(
|
||||
icon: Icon(Icons.more_vert),
|
||||
@@ -72,14 +72,14 @@ class AdaptiveContainer extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (MediaQuery.of(context).size.width < _kGridViewBreakpoint) {
|
||||
return new ListView(
|
||||
return ListView(
|
||||
itemExtent: _kListItemExtent,
|
||||
children: names.map((String name) => new AdaptedListItem(name: name)).toList(),
|
||||
children: names.map((String name) => AdaptedListItem(name: name)).toList(),
|
||||
);
|
||||
} else {
|
||||
return new GridView.extent(
|
||||
return GridView.extent(
|
||||
maxCrossAxisExtent: _kMaxTileWidth,
|
||||
children: names.map((String name) => new AdaptedGridItem(name: name)).toList(),
|
||||
children: names.map((String name) => AdaptedGridItem(name: name)).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -95,13 +95,13 @@ List<String> _initNames() {
|
||||
final List<String> _kNames = _initNames();
|
||||
|
||||
void main() {
|
||||
runApp(new MaterialApp(
|
||||
runApp(MaterialApp(
|
||||
title: 'Media Query Example',
|
||||
home: new Scaffold(
|
||||
appBar: new AppBar(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Media Query Example')
|
||||
),
|
||||
body: new Material(child: new AdaptiveContainer(names: _kNames))
|
||||
body: Material(child: AdaptiveContainer(names: _kNames))
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -10,21 +10,21 @@ import 'package:flutter/rendering.dart';
|
||||
import '../rendering/src/sector_layout.dart';
|
||||
|
||||
RenderBox initCircle() {
|
||||
return new RenderBoxToRenderSectorAdapter(
|
||||
return RenderBoxToRenderSectorAdapter(
|
||||
innerRadius: 25.0,
|
||||
child: new RenderSectorRing(padding: 0.0)
|
||||
child: RenderSectorRing(padding: 0.0)
|
||||
);
|
||||
}
|
||||
|
||||
class SectorApp extends StatefulWidget {
|
||||
@override
|
||||
SectorAppState createState() => new SectorAppState();
|
||||
SectorAppState createState() => SectorAppState();
|
||||
}
|
||||
|
||||
class SectorAppState extends State<SectorApp> {
|
||||
|
||||
final RenderBoxToRenderSectorAdapter sectors = initCircle();
|
||||
final math.Random rand = new math.Random(1);
|
||||
final math.Random rand = math.Random(1);
|
||||
|
||||
List<double> wantedSectorSizes = <double>[];
|
||||
List<double> actualSectorSizes = <double>[];
|
||||
@@ -60,19 +60,19 @@ class SectorAppState extends State<SectorApp> {
|
||||
actualSectorSizes.removeLast();
|
||||
}
|
||||
while (index < wantedSectorSizes.length) {
|
||||
final Color color = new Color(((0xFF << 24) + rand.nextInt(0xFFFFFF)) | 0x808080);
|
||||
ring.add(new RenderSolidColor(color, desiredDeltaTheta: wantedSectorSizes[index]));
|
||||
final Color color = Color(((0xFF << 24) + rand.nextInt(0xFFFFFF)) | 0x808080);
|
||||
ring.add(RenderSolidColor(color, desiredDeltaTheta: wantedSectorSizes[index]));
|
||||
actualSectorSizes.add(wantedSectorSizes[index]);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
static RenderBox initSector(Color color) {
|
||||
final RenderSectorRing ring = new RenderSectorRing(padding: 1.0);
|
||||
ring.add(new RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kTwoPi * 0.15));
|
||||
ring.add(new RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kTwoPi * 0.15));
|
||||
ring.add(new RenderSolidColor(color, desiredDeltaTheta: kTwoPi * 0.2));
|
||||
return new RenderBoxToRenderSectorAdapter(
|
||||
final RenderSectorRing ring = RenderSectorRing(padding: 1.0);
|
||||
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
|
||||
);
|
||||
@@ -90,36 +90,36 @@ class SectorAppState extends State<SectorApp> {
|
||||
}
|
||||
|
||||
Widget buildBody() {
|
||||
return new Column(
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 25.0),
|
||||
child: new Row(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new RaisedButton(
|
||||
RaisedButton(
|
||||
onPressed: _enabledAdd ? addSector : null,
|
||||
child: new IntrinsicWidth(
|
||||
child: new Row(
|
||||
child: IntrinsicWidth(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
margin: const EdgeInsets.only(right: 10.0),
|
||||
child: new WidgetToRenderBoxAdapter(renderBox: sectorAddIcon)
|
||||
child: WidgetToRenderBoxAdapter(renderBox: sectorAddIcon)
|
||||
),
|
||||
const Text('ADD SECTOR'),
|
||||
]
|
||||
)
|
||||
)
|
||||
),
|
||||
new RaisedButton(
|
||||
RaisedButton(
|
||||
onPressed: _enabledRemove ? removeSector : null,
|
||||
child: new IntrinsicWidth(
|
||||
child: new Row(
|
||||
child: IntrinsicWidth(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
margin: const EdgeInsets.only(right: 10.0),
|
||||
child: new WidgetToRenderBoxAdapter(renderBox: sectorRemoveIcon)
|
||||
child: WidgetToRenderBoxAdapter(renderBox: sectorRemoveIcon)
|
||||
),
|
||||
const Text('REMOVE SECTOR'),
|
||||
]
|
||||
@@ -130,14 +130,14 @@ class SectorAppState extends State<SectorApp> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround
|
||||
)
|
||||
),
|
||||
new Expanded(
|
||||
child: new Container(
|
||||
Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(8.0),
|
||||
decoration: new BoxDecoration(
|
||||
border: new Border.all()
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all()
|
||||
),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: new WidgetToRenderBoxAdapter(
|
||||
child: WidgetToRenderBoxAdapter(
|
||||
renderBox: sectors,
|
||||
onBuild: doUpdates
|
||||
)
|
||||
@@ -150,11 +150,11 @@ class SectorAppState extends State<SectorApp> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new MaterialApp(
|
||||
theme: new ThemeData.light(),
|
||||
return MaterialApp(
|
||||
theme: ThemeData.light(),
|
||||
title: 'Sector Layout',
|
||||
home: new Scaffold(
|
||||
appBar: new AppBar(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Sector Layout in a Widget Tree')
|
||||
),
|
||||
body: buildBody()
|
||||
@@ -164,5 +164,5 @@ class SectorAppState extends State<SectorApp> {
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new SectorApp());
|
||||
runApp(SectorApp());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import '../rendering/src/solid_color_box.dart';
|
||||
|
||||
// Solid colour, RenderObject version
|
||||
void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex = 0 }) {
|
||||
final RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
|
||||
final RenderSolidColorBox child = RenderSolidColorBox(backgroundColor);
|
||||
parent.add(child);
|
||||
final FlexParentData childParentData = child.parentData;
|
||||
childParentData.flex = flex;
|
||||
@@ -23,8 +23,8 @@ class Rectangle extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Expanded(
|
||||
child: new Container(
|
||||
return Expanded(
|
||||
child: Container(
|
||||
color: color,
|
||||
)
|
||||
);
|
||||
@@ -33,27 +33,27 @@ class Rectangle extends StatelessWidget {
|
||||
|
||||
double value;
|
||||
RenderObjectToWidgetElement<RenderBox> element;
|
||||
BuildOwner owner = new BuildOwner();
|
||||
BuildOwner owner = BuildOwner();
|
||||
void attachWidgetTreeToRenderTree(RenderProxyBox container) {
|
||||
element = new RenderObjectToWidgetAdapter<RenderBox>(
|
||||
element = RenderObjectToWidgetAdapter<RenderBox>(
|
||||
container: container,
|
||||
child: new Directionality(
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: new Container(
|
||||
child: Container(
|
||||
height: 300.0,
|
||||
child: new Column(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
const Rectangle(Color(0xFF00FFFF)),
|
||||
new Material(
|
||||
child: new Container(
|
||||
Material(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
margin: const EdgeInsets.all(10.0),
|
||||
child: new Row(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new RaisedButton(
|
||||
child: new Row(
|
||||
RaisedButton(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
new Image.network('https://flutter.io/images/favicon.png'),
|
||||
Image.network('https://flutter.io/images/favicon.png'),
|
||||
const Text('PRESS ME'),
|
||||
],
|
||||
),
|
||||
@@ -62,7 +62,7 @@ void attachWidgetTreeToRenderTree(RenderProxyBox container) {
|
||||
attachWidgetTreeToRenderTree(container);
|
||||
},
|
||||
),
|
||||
new CircularProgressIndicator(value: value),
|
||||
CircularProgressIndicator(value: value),
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
),
|
||||
@@ -92,16 +92,16 @@ void rotate(Duration timeStamp) {
|
||||
|
||||
void main() {
|
||||
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
|
||||
final RenderProxyBox proxy = new RenderProxyBox();
|
||||
final RenderProxyBox proxy = RenderProxyBox();
|
||||
attachWidgetTreeToRenderTree(proxy);
|
||||
|
||||
final RenderFlex flexRoot = new RenderFlex(direction: Axis.vertical);
|
||||
final RenderFlex flexRoot = RenderFlex(direction: Axis.vertical);
|
||||
addFlexChildSolidColor(flexRoot, const Color(0xFFFF00FF), flex: 1);
|
||||
flexRoot.add(proxy);
|
||||
addFlexChildSolidColor(flexRoot, const Color(0xFF0000FF), flex: 1);
|
||||
|
||||
transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.identity(), alignment: Alignment.center);
|
||||
final RenderPadding root = new 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);
|
||||
|
||||
binding.renderView.child = root;
|
||||
binding.addPersistentFrameCallback(rotate);
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
class SpinningSquare extends StatefulWidget {
|
||||
@override
|
||||
_SpinningSquareState createState() => new _SpinningSquareState();
|
||||
_SpinningSquareState createState() => _SpinningSquareState();
|
||||
}
|
||||
|
||||
class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProviderStateMixin {
|
||||
@@ -18,7 +18,7 @@ class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProvid
|
||||
// We use 3600 milliseconds instead of 1800 milliseconds because 0.0 -> 1.0
|
||||
// represents an entire turn of the square whereas in the other examples
|
||||
// we used 0.0 -> math.pi, which is only half a turn.
|
||||
_animation = new AnimationController(
|
||||
_animation = AnimationController(
|
||||
duration: const Duration(milliseconds: 3600),
|
||||
vsync: this,
|
||||
)..repeat();
|
||||
@@ -32,9 +32,9 @@ class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProvid
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new RotationTransition(
|
||||
return RotationTransition(
|
||||
turns: _animation,
|
||||
child: new Container(
|
||||
child: Container(
|
||||
width: 200.0,
|
||||
height: 200.0,
|
||||
color: const Color(0xFF00FF00),
|
||||
@@ -44,5 +44,5 @@ class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProvid
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new Center(child: new SpinningSquare()));
|
||||
runApp(Center(child: SpinningSquare()));
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ final List<List<String>> _kNameLines = _kDialogText
|
||||
.map((String line) => line.split(':'))
|
||||
.toList();
|
||||
|
||||
final TextStyle _kDaveStyle = new TextStyle(color: Colors.indigo.shade400, height: 1.8);
|
||||
final TextStyle _kHalStyle = new TextStyle(color: Colors.red.shade400, fontFamily: 'monospace');
|
||||
final TextStyle _kDaveStyle = TextStyle(color: Colors.indigo.shade400, height: 1.8);
|
||||
final TextStyle _kHalStyle = TextStyle(color: Colors.red.shade400, fontFamily: 'monospace');
|
||||
const TextStyle _kBold = TextStyle(fontWeight: FontWeight.bold);
|
||||
const TextStyle _kUnderline = TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
@@ -34,33 +34,33 @@ const TextStyle _kUnderline = TextStyle(
|
||||
|
||||
Widget toStyledText(String name, String text) {
|
||||
final TextStyle lineStyle = (name == 'Dave') ? _kDaveStyle : _kHalStyle;
|
||||
return new RichText(
|
||||
key: new Key(text),
|
||||
text: new TextSpan(
|
||||
return RichText(
|
||||
key: Key(text),
|
||||
text: TextSpan(
|
||||
style: lineStyle,
|
||||
children: <TextSpan>[
|
||||
new TextSpan(
|
||||
TextSpan(
|
||||
style: _kBold,
|
||||
children: <TextSpan>[
|
||||
new TextSpan(
|
||||
TextSpan(
|
||||
style: _kUnderline,
|
||||
text: name
|
||||
),
|
||||
const TextSpan(text: ':')
|
||||
]
|
||||
),
|
||||
new TextSpan(text: text)
|
||||
TextSpan(text: text)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Widget toPlainText(String name, String text) => new Text(name + ':' + text);
|
||||
Widget toPlainText(String name, String text) => Text(name + ':' + text);
|
||||
|
||||
class SpeakerSeparator extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Container(
|
||||
return Container(
|
||||
constraints: const BoxConstraints.expand(height: 0.0),
|
||||
margin: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 64.0),
|
||||
decoration: const BoxDecoration(
|
||||
@@ -74,7 +74,7 @@ class SpeakerSeparator extends StatelessWidget {
|
||||
|
||||
class StyledTextDemo extends StatefulWidget {
|
||||
@override
|
||||
_StyledTextDemoState createState() => new _StyledTextDemoState();
|
||||
_StyledTextDemoState createState() => _StyledTextDemoState();
|
||||
}
|
||||
|
||||
class _StyledTextDemoState extends State<StyledTextDemo> {
|
||||
@@ -102,14 +102,14 @@ class _StyledTextDemoState extends State<StyledTextDemo> {
|
||||
for (Widget line in lines) {
|
||||
children.add(line);
|
||||
if (line != lines.last)
|
||||
children.add(new SpeakerSeparator());
|
||||
children.add(SpeakerSeparator());
|
||||
}
|
||||
|
||||
return new GestureDetector(
|
||||
return GestureDetector(
|
||||
onTap: _handleTap,
|
||||
child: new Container(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
child: new Column(
|
||||
child: Column(
|
||||
children: children,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start
|
||||
@@ -120,15 +120,15 @@ class _StyledTextDemoState extends State<StyledTextDemo> {
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(new MaterialApp(
|
||||
theme: new ThemeData.light(),
|
||||
home: new Scaffold(
|
||||
appBar: new AppBar(
|
||||
runApp(MaterialApp(
|
||||
theme: ThemeData.light(),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Hal and Dave')
|
||||
),
|
||||
body: new Material(
|
||||
body: Material(
|
||||
color: Colors.grey.shade50,
|
||||
child: new StyledTextDemo()
|
||||
child: StyledTextDemo()
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user