@@ -244,12 +244,6 @@ class BoxShadow {
244
244
String toString () => 'BoxShadow($color , $offset , $blurRadius , $spreadRadius )' ;
245
245
}
246
246
247
- // TODO(ianh): We should probably expose something that does this on Rect.
248
- // https://github.com/flutter/flutter/issues/2318
249
- Point _offsetToPoint (Offset offset, Rect rect) {
250
- return new Point (rect.left + offset.dx * rect.width, rect.top + offset.dy * rect.height);
251
- }
252
-
253
247
/// A 2D gradient.
254
248
abstract class Gradient {
255
249
const Gradient ();
@@ -259,8 +253,8 @@ abstract class Gradient {
259
253
/// A 2D linear gradient.
260
254
class LinearGradient extends Gradient {
261
255
const LinearGradient ({
262
- this .begin: const Offset (0.0 , 0.5 ),
263
- this .end: const Offset (1.0 , 0.5 ),
256
+ this .begin: const FractionalOffset (0.0 , 0.5 ),
257
+ this .end: const FractionalOffset (1.0 , 0.5 ),
264
258
this .colors,
265
259
this .stops,
266
260
this .tileMode: TileMode .clamp
@@ -272,15 +266,15 @@ class LinearGradient extends Gradient {
272
266
///
273
267
/// For example, a begin offset of (0.0,0.5) is half way down the
274
268
/// left side of the box.
275
- final Offset begin;
269
+ final FractionalOffset begin;
276
270
277
271
/// The offset from coordinate (0.0,0.0) at which stop 1.0 of the
278
272
/// gradient is placed, in a coordinate space that maps the top left
279
273
/// of the paint box at (0.0,0.0) and the bottom right at (1.0,1.0).
280
274
///
281
275
/// For example, an end offset of (1.0,0.5) is half way down the
282
276
/// right side of the box.
283
- final Offset end;
277
+ final FractionalOffset end;
284
278
285
279
/// The colors the gradient should obtain at each of the stops.
286
280
///
@@ -299,7 +293,7 @@ class LinearGradient extends Gradient {
299
293
@override
300
294
Shader createShader (Rect rect) {
301
295
return new ui.Gradient .linear (
302
- < Point > [_offsetToPoint ( begin, rect), _offsetToPoint ( end, rect)],
296
+ < Point > [begin. withinRect ( rect), end. withinRect ( rect)],
303
297
colors, stops, tileMode
304
298
);
305
299
}
@@ -348,7 +342,7 @@ class LinearGradient extends Gradient {
348
342
/// A 2D radial gradient.
349
343
class RadialGradient extends Gradient {
350
344
const RadialGradient ({
351
- this .center: const Offset (0.5 , 0.5 ),
345
+ this .center: const FractionalOffset (0.5 , 0.5 ),
352
346
this .radius: 0.5 ,
353
347
this .colors,
354
348
this .stops,
@@ -360,7 +354,7 @@ class RadialGradient extends Gradient {
360
354
///
361
355
/// For example, an offset of (0.5,0.5) will place the radial
362
356
/// gradient in the center of the box.
363
- final Offset center;
357
+ final FractionalOffset center;
364
358
365
359
/// The radius of the gradient, as a fraction of the shortest side
366
360
/// of the paint box.
@@ -389,7 +383,7 @@ class RadialGradient extends Gradient {
389
383
@override
390
384
Shader createShader (Rect rect) {
391
385
return new ui.Gradient .radial (
392
- _offsetToPoint ( center, rect),
386
+ center. withinRect ( rect),
393
387
radius * rect.shortestSide,
394
388
colors, stops, tileMode
395
389
);
@@ -645,6 +639,9 @@ class FractionalOffset {
645
639
Offset alongSize (Size other) {
646
640
return new Offset (dx * other.width, dy * other.height);
647
641
}
642
+ Point withinRect (Rect rect) {
643
+ return new Point (rect.left + dx * rect.width, rect.top + dy * rect.height);
644
+ }
648
645
649
646
@override
650
647
bool operator == (dynamic other) {
0 commit comments