custom_paint_test.dart 1.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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';
import 'package:test/test.dart';

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

  List<String> log;
  String name;

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

20
  @override
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  bool shouldRepaint(TestCustomPainter oldPainter) => true;
}

void main() {
  test('Control test for custom painting', () {
    testWidgets((WidgetTester tester) {
      List<String> log = <String>[];
      tester.pumpWidget(new CustomPaint(
        painter: new TestCustomPainter(
          log: log,
          name: 'background'
        ),
        foregroundPainter: new TestCustomPainter(
          log: log,
          name: 'foreground'
        ),
        child: new CustomPaint(
          painter: new TestCustomPainter(
            log: log,
            name: 'child'
          )
        )
      ));

      expect(log, equals(['background', 'child', 'foreground']));
    });
  });
}