inherited_dependencies_test.dart 1.68 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/src/widgets/basic.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('InheritedWidget dependencies show up in diagnostic properties', (WidgetTester tester) async {
    final GlobalKey key = GlobalKey();
    await tester.pumpWidget(Directionality(
      key: key,
      textDirection: TextDirection.ltr,
      child: Builder(builder: (BuildContext context) {
        Directionality.of(context);
        return const SizedBox();
      }),
    ));
20
    final InheritedElement element = key.currentContext! as InheritedElement;
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
    expect(
      element.toStringDeep(minLevel: DiagnosticLevel.info),
      equalsIgnoringHashCodes(
        'Directionality-[GlobalKey#00000](textDirection: ltr)\n'
        '└Builder(dependencies: [Directionality-[GlobalKey#00000]])\n'
        ' └SizedBox(renderObject: RenderConstrainedBox#00000)\n'
        ''
      ),
    );

    await tester.pumpWidget(Directionality(
      key: key,
      textDirection: TextDirection.rtl,
      child: Builder(builder: (BuildContext context) {
        Directionality.of(context);
        return const SizedBox();
      }),
    ));
    expect(
      element.toStringDeep(minLevel: DiagnosticLevel.info),
      equalsIgnoringHashCodes(
        'Directionality-[GlobalKey#00000](textDirection: rtl)\n'
        '└Builder(dependencies: [Directionality-[GlobalKey#00000]])\n'
        ' └SizedBox(renderObject: RenderConstrainedBox#00000)\n'
        ''
      ),
    );
  });
}