From 633c6c7287ae0e0650f418b8bd923fa9651e1326 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Tue, 13 Jun 2017 15:41:21 -0700 Subject: [PATCH 1/3] Fixing a small problem with the test --- examples/hello_world/hello_world.iml | 3 ++- packages/flutter/flutter.iml | 4 ++-- .../lib/src/material/input_decorator.dart | 2 +- .../flutter/test/material/text_field_test.dart | 10 +++++----- packages/flutter_tools/flutter_tools.iml | 18 +++++++++--------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/examples/hello_world/hello_world.iml b/examples/hello_world/hello_world.iml index 30ca7dd23f133..c82504f3177c9 100644 --- a/examples/hello_world/hello_world.iml +++ b/examples/hello_world/hello_world.iml @@ -7,9 +7,10 @@ + - + \ No newline at end of file diff --git a/packages/flutter/flutter.iml b/packages/flutter/flutter.iml index 32cd5b3f65c03..b34e1f260d4fb 100644 --- a/packages/flutter/flutter.iml +++ b/packages/flutter/flutter.iml @@ -1,5 +1,5 @@ - + @@ -28,4 +28,4 @@ - + \ No newline at end of file diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 30893d9d848d7..662782e81e882 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -459,7 +459,7 @@ class InputDecorator extends StatelessWidget { Widget inputChild; if (!hasInlineLabel && (!isEmpty || hintText == null) && (decoration?.prefixText != null || decoration?.suffixText != null)) { - List rowContents = []; + final List rowContents = []; if (decoration.prefixText != null) { rowContents.add(new Text(decoration.prefixText, style: decoration.prefixStyle ?? hintStyle)); diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 4babb5e62a708..49d4f96f3a48f 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -878,7 +878,7 @@ void main() { // Enter some text, and the prefix should still display. await tester.enterText(find.byKey(secondKey), "Hi"); await tester.pump(); - await tester.pump(new Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); expect(find.text('Prefix'), findsOneWidget); expect(find.text('Suffix'), findsOneWidget); @@ -937,7 +937,7 @@ void main() { // should appear. await tester.enterText(find.byKey(secondKey), "Hi"); await tester.pump(); - await tester.pump(new Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); expect(find.text('Prefix'), findsOneWidget); expect(find.text('Suffix'), findsOneWidget); @@ -945,7 +945,7 @@ void main() { // It's onstage, but animated to zero opacity. expect(find.text('Hint'), findsOneWidget); final Element target = tester.element(find.text('Hint')); - Opacity opacity = target.ancestorWidgetOfExactType(Opacity); + final Opacity opacity = target.ancestorWidgetOfExactType(Opacity); expect(opacity, isNotNull); expect(opacity.opacity, equals(0.0)); @@ -953,7 +953,7 @@ void main() { final Text prefixText = tester.widget(find.text('Prefix')); expect(prefixText.style, hintStyle); final Text suffixText = tester.widget(find.text('Suffix')); - expect(prefixText.style, hintStyle); + expect(suffixText.style, hintStyle); }); testWidgets('TextField prefix and suffix appear correctly with label text', @@ -1014,7 +1014,7 @@ void main() { // remain. await tester.enterText(find.byKey(secondKey), "Hi"); await tester.pump(); - await tester.pump(new Duration(seconds: 1)); + await tester.pump(const Duration(seconds: 1)); expect(find.text('Prefix'), findsOneWidget); expect(find.text('Suffix'), findsOneWidget); diff --git a/packages/flutter_tools/flutter_tools.iml b/packages/flutter_tools/flutter_tools.iml index 14bf54812bf86..22fe5c309c091 100644 --- a/packages/flutter_tools/flutter_tools.iml +++ b/packages/flutter_tools/flutter_tools.iml @@ -7,6 +7,12 @@ + + + + + + @@ -30,16 +36,10 @@ + - - - - - - - - + @@ -48,4 +48,4 @@ - + \ No newline at end of file From 5b86b03eb50a9992ca015f4610180ef4b62c3c4b Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Tue, 13 Jun 2017 18:20:47 -0700 Subject: [PATCH 2/3] Review Changes --- examples/hello_world/hello_world.iml | 1 - packages/flutter/flutter.iml | 2 +- .../lib/src/material/input_decorator.dart | 20 +++++++++++-------- .../test/material/text_field_test.dart | 2 +- packages/flutter_test/flutter_test.iml | 2 +- packages/flutter_tools/flutter_tools.iml | 16 +++++++-------- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/examples/hello_world/hello_world.iml b/examples/hello_world/hello_world.iml index c82504f3177c9..9d5dae19540c2 100644 --- a/examples/hello_world/hello_world.iml +++ b/examples/hello_world/hello_world.iml @@ -7,7 +7,6 @@ - diff --git a/packages/flutter/flutter.iml b/packages/flutter/flutter.iml index b34e1f260d4fb..c40a803190688 100644 --- a/packages/flutter/flutter.iml +++ b/packages/flutter/flutter.iml @@ -1,5 +1,5 @@ - + diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 662782e81e882..668d897a54810 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -40,7 +40,7 @@ class InputDecoration { this.prefixText, this.prefixStyle, this.suffixText, - this.suffixStyle + this.suffixStyle, }) : isCollapsed = false; /// Creates a decoration that is the same size as the input field. @@ -143,7 +143,7 @@ class InputDecoration { /// Optional text prefix to place on the line before the input. /// - /// Uses the [prefixStyle]. Uses [hintStyle] if [prefixStyle] isn't + /// Uses the [prefixStyle]. Uses [hintStyle] if [prefixStyle] isn't /// specified. Prefix is not returned as part of the input. final String prefixText; @@ -154,7 +154,7 @@ class InputDecoration { /// Optional text suffix to place on the line after the input. /// - /// Uses the [suffixStyle]. Uses [hintStyle] if [suffixStyle] isn't + /// Uses the [suffixStyle]. Uses [hintStyle] if [suffixStyle] isn't /// specified. Suffix is not returned as part of the input. final String suffixText; @@ -180,7 +180,7 @@ class InputDecoration { String prefixText, TextStyle prefixStyle, String suffixText, - TextStyle suffixStyle + TextStyle suffixStyle, }) { return new InputDecoration( icon: icon ?? this.icon, @@ -461,13 +461,17 @@ class InputDecorator extends StatelessWidget { (decoration?.prefixText != null || decoration?.suffixText != null)) { final List rowContents = []; if (decoration.prefixText != null) { - rowContents.add(new Text(decoration.prefixText, - style: decoration.prefixStyle ?? hintStyle)); + rowContents.add( + new Text(decoration.prefixText, + style: decoration.prefixStyle ?? hintStyle) + ); } rowContents.add(new Expanded(child: child)); if (decoration.suffixText != null) { - rowContents.add(new Text(decoration.suffixText, - style: decoration.suffixStyle ?? hintStyle)); + rowContents.add( + new Text(decoration.suffixText, + style: decoration.suffixStyle ?? hintStyle) + ); } inputChild = new Row(children: rowContents); } else { diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 49d4f96f3a48f..0b17aa298ad1e 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -1072,7 +1072,7 @@ void main() { newPos = tester.getTopLeft(find.text('Second')); expect(newPos.dy, lessThan(pos.dy)); }); - + testWidgets('No space between Input icon and text', (WidgetTester tester) async { await tester.pumpWidget( const Center( diff --git a/packages/flutter_test/flutter_test.iml b/packages/flutter_test/flutter_test.iml index 55026d78a689a..9b361c06946c4 100644 --- a/packages/flutter_test/flutter_test.iml +++ b/packages/flutter_test/flutter_test.iml @@ -13,4 +13,4 @@ - + \ No newline at end of file diff --git a/packages/flutter_tools/flutter_tools.iml b/packages/flutter_tools/flutter_tools.iml index 22fe5c309c091..367b72461cd70 100644 --- a/packages/flutter_tools/flutter_tools.iml +++ b/packages/flutter_tools/flutter_tools.iml @@ -7,12 +7,6 @@ - - - - - - @@ -36,10 +30,16 @@ - + + + + + + - + + From 2ca1574cc75bbf5847c9aaca5ff1d9b43cece978 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Thu, 15 Jun 2017 12:41:37 -0700 Subject: [PATCH 3/3] Added example for line styles, and enabled line join styles. --- examples/layers/lib/main.dart | 2 +- examples/layers/raw/line_styles.dart | 86 ++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 examples/layers/raw/line_styles.dart diff --git a/examples/layers/lib/main.dart b/examples/layers/lib/main.dart index 864e8f1d287ca..4d6a7d91ff612 100644 --- a/examples/layers/lib/main.dart +++ b/examples/layers/lib/main.dart @@ -4,4 +4,4 @@ import 'package:flutter/widgets.dart'; -void main() => runApp(const Center(child: const Text('flutter run -t xxx/yyy.dart'))); +void main() => runApp(const Center(child: const Text('flutter run -t raw/spinning_square.dart'))); diff --git a/examples/layers/raw/line_styles.dart b/examples/layers/raw/line_styles.dart new file mode 100644 index 0000000000000..1748aaa76e63d --- /dev/null +++ b/examples/layers/raw/line_styles.dart @@ -0,0 +1,86 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This example shows how to perform a simple animation using the raw interface +// to the engine. + +import 'dart:math' as math; +import 'dart:typed_data'; +import 'dart:ui' as ui; + +void beginFrame(Duration timeStamp) { + // The timeStamp argument to beginFrame indicates the timing information we + // should use to clock our animations. It's important to use timeStamp rather + // than reading the system time because we want all the parts of the system to + // coordinate the timings of their animations. If each component read the + // system clock independently, the animations that we processed later would be + // slightly ahead of the animations we processed earlier. + + // PAINT + const double kRadius = 100.0; + const double kTwoPi = math.PI * 2.0; + const double kVerticalOffset = 100.0; + + 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); + canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0); + + // Here we determine the rotation speed according to the timeStamp given to us + // by the engine. + final double t = (timeStamp.inMicroseconds / + Duration.MICROSECONDS_PER_MILLISECOND / + 3200.0) % 1.0; + + final List points = [ + const ui.Offset(kRadius, kVerticalOffset), + const ui.Offset(0.0, kVerticalOffset), + new ui.Offset(kRadius * math.cos(t * kTwoPi), + kRadius * math.sin(t * kTwoPi) + kVerticalOffset), + ]; + + // Try changing values for the stroke style and see what the results are + // for different line drawing primitives. + final ui.Paint paint = new ui.Paint() + ..color = const ui.Color.fromARGB(255, 0, 255, 0) + ..style = ui.PaintingStyle.stroke + ..strokeCap = ui.StrokeCap.butt // Other choices are round and square. + ..strokeJoin = ui.StrokeJoin.miter // Other choices are round and bevel. + ..strokeMiterLimit = 5.0 // Try smaller and larger values greater than zero. + ..strokeWidth = 20.0; + canvas.drawPoints(ui.PointMode.polygon, points, paint); + + final ui.Path path = new ui.Path() + ..moveTo(points[0].dx, points[0].dy - 2 * kVerticalOffset) + ..lineTo(points[1].dx, points[1].dy - 2 * kVerticalOffset) + ..lineTo(points[2].dx, points[2].dy - 2 * kVerticalOffset) + ..close(); + canvas.drawPath(path, paint); + final ui.Picture picture = recorder.endRecording(); + + // COMPOSITE + + final double devicePixelRatio = ui.window.devicePixelRatio; + final Float64List deviceTransform = new Float64List(16) + ..[0] = devicePixelRatio + ..[5] = devicePixelRatio + ..[10] = 1.0 + ..[15] = 1.0; + final ui.SceneBuilder sceneBuilder = new ui.SceneBuilder() + ..pushTransform(deviceTransform) + ..addPicture(ui.Offset.zero, picture) + ..pop(); + ui.window.render(sceneBuilder.build()); + + // After rendering the current frame of the animation, we ask the engine to + // schedule another frame. The engine will call beginFrame again when its time + // to produce the next frame. + ui.window.scheduleFrame(); +} + +void main() { + ui.window.onBeginFrame = beginFrame; + ui.window.scheduleFrame(); +}