rtl_test.dart 3.3 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_test/flutter_test.dart';
import 'package:flutter/widgets.dart';

void main() {
  testWidgets('Padding RTL', (WidgetTester tester) async {
10 11 12
    const Widget child = Padding(
      padding: EdgeInsetsDirectional.only(start: 10.0),
      child: Placeholder(),
13
    );
14
    await tester.pumpWidget(const Directionality(
15 16 17 18
      textDirection: TextDirection.ltr,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(10.0, 0.0));
19
    await tester.pumpWidget(const Directionality(
20 21 22 23
      textDirection: TextDirection.rtl,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(0.0, 0.0));
Ian Hickson's avatar
Ian Hickson committed
24 25 26

    await tester.pumpWidget(
      const Padding(
27
        key: GlobalObjectKey<State<StatefulWidget>>(null),
28
        padding: EdgeInsets.only(left: 1.0),
Ian Hickson's avatar
Ian Hickson committed
29 30 31 32
      ),
    );
    await tester.pumpWidget(const Directionality(
      textDirection: TextDirection.rtl,
33
      child: Padding(
34
        key: GlobalObjectKey<State<StatefulWidget>>(null),
35
        padding: EdgeInsetsDirectional.only(start: 1.0),
Ian Hickson's avatar
Ian Hickson committed
36 37 38 39
      ),
    ));
    await tester.pumpWidget(
      const Padding(
40
        key: GlobalObjectKey<State<StatefulWidget>>(null),
41
        padding: EdgeInsets.only(left: 1.0),
Ian Hickson's avatar
Ian Hickson committed
42 43
      ),
    );
44 45 46
  });

  testWidgets('Container padding/margin RTL', (WidgetTester tester) async {
47
    final Widget child = Container(
48 49 50
      padding: const EdgeInsetsDirectional.only(start: 6.0),
      margin: const EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
      child: const Placeholder(),
51
    );
52
    await tester.pumpWidget(Directionality(
53 54 55 56 57
      textDirection: TextDirection.ltr,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(10.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(780.0, 0.0));
58
    await tester.pumpWidget(Directionality(
59 60 61 62 63 64 65 66
      textDirection: TextDirection.rtl,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(20.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(790.0, 0.0));
  });

  testWidgets('Container padding/margin mixed RTL/absolute', (WidgetTester tester) async {
67
    final Widget child = Container(
68 69 70
      padding: const EdgeInsets.only(left: 6.0),
      margin: const EdgeInsetsDirectional.only(end: 20.0, start: 4.0),
      child: const Placeholder(),
71
    );
72
    await tester.pumpWidget(Directionality(
73 74 75 76 77
      textDirection: TextDirection.ltr,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(10.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(780.0, 0.0));
78
    await tester.pumpWidget(Directionality(
79 80 81 82 83 84 85 86
      textDirection: TextDirection.rtl,
      child: child,
    ));
    expect(tester.getTopLeft(find.byType(Placeholder)), const Offset(26.0, 0.0));
    expect(tester.getTopRight(find.byType(Placeholder)), const Offset(796.0, 0.0));
  });

  testWidgets('EdgeInsetsDirectional without Directionality', (WidgetTester tester) async {
87
    await tester.pumpWidget(const Padding(padding: EdgeInsetsDirectional.only()));
88 89 90
    expect(tester.takeException(), isAssertionError);
  });
}