baseline_test.dart 1.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// 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_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

void main() {
  testWidgets('Baseline - control test', (WidgetTester tester) async {
    await tester.pumpWidget(
11 12
      const Center(
        child: const DefaultTextStyle(
13
          style: const TextStyle(
14 15 16
            fontFamily: 'Ahem',
            fontSize: 100.0,
          ),
Ian Hickson's avatar
Ian Hickson committed
17
          child: const Text('X', textDirection: TextDirection.ltr),
18 19 20 21 22 23 24 25
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.text('X')).size, const Size(100.0, 100.0));
  });

  testWidgets('Baseline - position test', (WidgetTester tester) async {
    await tester.pumpWidget(
26 27
      const Center(
        child: const Baseline(
28 29
          baseline: 180.0,
          baselineType: TextBaseline.alphabetic,
30
          child: const DefaultTextStyle(
31
            style: const TextStyle(
32 33 34
              fontFamily: 'Ahem',
              fontSize: 100.0,
            ),
Ian Hickson's avatar
Ian Hickson committed
35
            child: const Text('X', textDirection: TextDirection.ltr),
36 37 38 39 40
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.text('X')).size, const Size(100.0, 100.0));
41 42
    expect(tester.renderObject<RenderBox>(find.byType(Baseline)).size,
           within<Size>(from: const Size(100.0, 200.0), distance: 0.001));
43 44
  });
}