icon_button_test.dart 1.38 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2016 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/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('IconButton test constrained size', (WidgetTester tester) async {
10 11
    const double kIconSize = 80.0;

12 13 14 15 16 17
    await tester.pumpWidget(
      new Material(
        child: new Center(
          child: new IconButton(
            padding: EdgeInsets.zero,
            onPressed: () {},
18 19
            icon: new Icon(Icons.ac_unit),
            size: kIconSize,
20 21 22 23 24 25
          )
        )
      )
    );

    RenderBox box = tester.renderObject(find.byType(IconButton));
26 27
    expect(box.size.width, equals(kIconSize));
    expect(box.size.height, equals(kIconSize));
28 29 30 31 32 33 34 35 36 37
  });

  testWidgets('IconButton AppBar size', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Scaffold(
        appBar: new AppBar(
          actions: <Widget>[
            new IconButton(
              padding: EdgeInsets.zero,
              onPressed: () {},
38
              icon: new Icon(Icons.ac_unit),
39 40 41 42 43 44 45 46 47 48 49
            )
          ]
        )
      )
    );

    RenderBox barBox = tester.renderObject(find.byType(AppBar));
    RenderBox iconBox = tester.renderObject(find.byType(IconButton));
    expect(iconBox.size.height, equals(barBox.size.height));
  });
}