custom_paint_test.dart 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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.

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

class TestCustomPainter extends CustomPainter {
  TestCustomPainter({ this.log, this.name });

  List<String> log;
  String name;

14
  @override
15 16 17 18
  void paint(Canvas canvas, Size size) {
    log.add(name);
  }

19
  @override
20 21 22 23
  bool shouldRepaint(TestCustomPainter oldPainter) => true;
}

void main() {
24
  testWidgets('Control test for custom painting', (WidgetTester tester) async {
25
    List<String> log = <String>[];
26
    await tester.pumpWidget(new CustomPaint(
27 28 29 30 31 32 33 34 35
      painter: new TestCustomPainter(
        log: log,
        name: 'background'
      ),
      foregroundPainter: new TestCustomPainter(
        log: log,
        name: 'foreground'
      ),
      child: new CustomPaint(
36 37
        painter: new TestCustomPainter(
          log: log,
38
          name: 'child'
39
        )
40 41
      )
    ));
42

43
    expect(log, equals(<String>['background', 'child', 'foreground']));
44 45
  });
}