shader_mask_test.dart 1.49 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4
// 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.

5
import 'dart:ui' show Shader;
Hans Muller's avatar
Hans Muller committed
6

Adam Barth's avatar
Adam Barth committed
7
import 'package:flutter_test/flutter_test.dart';
8
import 'package:flutter/widgets.dart';
Hans Muller's avatar
Hans Muller committed
9

10
Shader createShader(Rect bounds) {
Hans Muller's avatar
Hans Muller committed
11
  return new LinearGradient(
12 13
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
14 15 16
    colors: <Color>[const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
    stops: <double>[0.1, 0.35]
  ).createShader(bounds);
Hans Muller's avatar
Hans Muller committed
17 18 19 20
}


void main() {
21
  testWidgets('Can be constructed', (WidgetTester tester) async {
22
    final Widget child = new Container(width: 100.0, height: 100.0);
23
    await tester.pumpWidget(new ShaderMask(child: child, shaderCallback: createShader));
Hans Muller's avatar
Hans Muller committed
24
  });
25 26 27 28 29 30 31 32 33

  testWidgets('Bounds rect includes offset', (WidgetTester tester) async {
    Rect shaderBounds;
    Shader recordShaderBounds(Rect bounds) {
      shaderBounds = bounds;
      return createShader(bounds);
    }

    final Widget widget = new Align(
34
      alignment: Alignment.center,
35 36 37 38 39 40 41 42 43 44 45 46 47 48
      child: new SizedBox(
        width: 400.0,
        height: 400.0,
        child: new ShaderMask(
          shaderCallback: recordShaderBounds,
          child: new Container(width: 100.0, height: 100.0)
        ),
      ),
    );
    await tester.pumpWidget(widget);

    // The shader bounds rectangle should reflect the position of the centered SizedBox.
    expect(shaderBounds, equals(new Rect.fromLTWH(200.0, 100.0, 400.0, 400.0)));
  });
Hans Muller's avatar
Hans Muller committed
49
}