app_builder_test.dart 1.78 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/material.dart';
6
import 'package:flutter_test/flutter_test.dart';
7
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
8

9
void main() {
10
  testWidgetsWithLeakTracking("builder doesn't get called if app doesn't change", (WidgetTester tester) async {
11
    final List<String> log = <String>[];
12
    final Widget app = MaterialApp(
13
      home: const Placeholder(),
14
      builder: (BuildContext context, Widget? child) {
15 16
        log.add('build');
        expect(Directionality.of(context), TextDirection.ltr);
17
        expect(child, isA<FocusScope>());
18 19 20 21
        return const Placeholder();
      },
    );
    await tester.pumpWidget(
22
      Directionality(
23 24 25 26 27 28
        textDirection: TextDirection.rtl,
        child: app,
      ),
    );
    expect(log, <String>['build']);
    await tester.pumpWidget(
29
      Directionality(
30 31 32 33 34 35 36
        textDirection: TextDirection.ltr,
        child: app,
      ),
    );
    expect(log, <String>['build']);
  });

37
  testWidgetsWithLeakTracking("builder doesn't get called if app doesn't change", (WidgetTester tester) async {
38 39
    final List<String> log = <String>[];
    await tester.pumpWidget(
40 41
      MaterialApp(
        home: Builder(
42 43 44 45 46 47
          builder: (BuildContext context) {
            log.add('build');
            expect(Directionality.of(context), TextDirection.rtl);
            return const Placeholder();
          },
        ),
48
        builder: (BuildContext context, Widget? child) {
49
          return Directionality(
50
            textDirection: TextDirection.rtl,
51
            child: child!,
52 53 54 55 56 57 58
          );
        },
      ),
    );
    expect(log, <String>['build']);
  });
}