safe_area_test.dart 2.33 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
// 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/rendering.dart';
import 'package:flutter/widgets.dart';

void main() {
  testWidgets('SafeArea - basic', (WidgetTester tester) async {
    await tester.pumpWidget(
      const MediaQuery(
        data: const MediaQueryData(padding: const EdgeInsets.all(20.0)),
        child: const SafeArea(
          left: false,
          child: const Placeholder(),
        ),
      ),
    );
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(0.0, 20.0));
    expect(tester.getBottomRight(find.byType(Placeholder)), const Offset(780.0, 580.0));
  });

  testWidgets('SafeArea - nested', (WidgetTester tester) async {
    await tester.pumpWidget(
      const MediaQuery(
        data: const MediaQueryData(padding: const EdgeInsets.all(20.0)),
        child: const SafeArea(
          top: false,
          child: const SafeArea(
            right: false,
            child: const Placeholder(),
          ),
        ),
      ),
    );
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(20.0, 20.0));
    expect(tester.getBottomRight(find.byType(Placeholder)), const Offset(780.0, 580.0));
  });

  testWidgets('SafeArea - changing', (WidgetTester tester) async {
    final Widget child = const SafeArea(
      bottom: false,
      child: const SafeArea(
        left: false,
        bottom: false,
        child: const Placeholder(),
      ),
    );
    await tester.pumpWidget(
      new MediaQuery(
        data: const MediaQueryData(padding: const EdgeInsets.all(20.0)),
        child: child,
      ),
    );
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(20.0, 20.0));
    expect(tester.getBottomRight(find.byType(Placeholder)), const Offset(780.0, 600.0));
    await tester.pumpWidget(
      new MediaQuery(
        data: const MediaQueryData(padding: const EdgeInsets.only(
          left: 100.0,
          top: 30.0,
          right: 0.0,
          bottom: 40.0,
        )),
        child: child,
      ),
    );
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(100.0, 30.0));
    expect(tester.getBottomRight(find.byType(Placeholder)), const Offset(800.0, 600.0));
  });
}