app_builder_test.dart 1.95 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 6
// @dart = 2.8

7
import 'package:flutter_test/flutter_test.dart';
8
import 'package:flutter/material.dart';
9 10

void main() {
11
  testWidgets("builder doesn't get called if app doesn't change", (WidgetTester tester) async {
12
    final List<String> log = <String>[];
13 14
    final Widget app = MaterialApp(
      theme: ThemeData(
15 16 17 18 19
        primarySwatch: Colors.green,
      ),
      home: const Placeholder(),
      builder: (BuildContext context, Widget child) {
        log.add('build');
20
        expect(Theme.of(context).primaryColor, Colors.green);
21
        expect(Directionality.of(context), TextDirection.ltr);
Dan Field's avatar
Dan Field committed
22
        expect(child, isA<Navigator>());
23 24 25 26
        return const Placeholder();
      },
    );
    await tester.pumpWidget(
27
      Directionality(
28 29 30 31 32 33
        textDirection: TextDirection.rtl,
        child: app,
      ),
    );
    expect(log, <String>['build']);
    await tester.pumpWidget(
34
      Directionality(
35 36 37 38 39 40 41
        textDirection: TextDirection.ltr,
        child: app,
      ),
    );
    expect(log, <String>['build']);
  });

42
  testWidgets("builder doesn't get called if app doesn't change", (WidgetTester tester) async {
43 44
    final List<String> log = <String>[];
    await tester.pumpWidget(
45 46
      MaterialApp(
        theme: ThemeData(
47 48
          primarySwatch: Colors.yellow,
        ),
49
        home: Builder(
50 51
          builder: (BuildContext context) {
            log.add('build');
52
            expect(Theme.of(context).primaryColor, Colors.yellow);
53 54 55 56 57
            expect(Directionality.of(context), TextDirection.rtl);
            return const Placeholder();
          },
        ),
        builder: (BuildContext context, Widget child) {
58
          return Directionality(
59 60 61 62 63 64 65 66 67
            textDirection: TextDirection.rtl,
            child: child,
          );
        },
      ),
    );
    expect(log, <String>['build']);
  });
}