blob: 84f7f4a6b4b70bb435ddb145133ae83816605e17 [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hicksonc12d1202018-02-01 23:12:52 -08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter_test/flutter_test.dart';
Ian Hickson65992712018-06-19 17:22:56 -07006import 'package:flutter/material.dart';
Ian Hicksonc12d1202018-02-01 23:12:52 -08007
8void main() {
Alexandre Ardhuinf15c8872020-02-11 20:58:27 +01009 testWidgets("builder doesn't get called if app doesn't change", (WidgetTester tester) async {
Ian Hicksonc12d1202018-02-01 23:12:52 -080010 final List<String> log = <String>[];
Alexandre Ardhuind927c932018-09-12 08:29:29 +020011 final Widget app = MaterialApp(
12 theme: ThemeData(
Ian Hicksonc12d1202018-02-01 23:12:52 -080013 primarySwatch: Colors.green,
14 ),
15 home: const Placeholder(),
Greg Spencerc083f022020-10-09 14:58:13 -070016 builder: (BuildContext context, Widget? child) {
Ian Hicksonc12d1202018-02-01 23:12:52 -080017 log.add('build');
Greg Spencerc083f022020-10-09 14:58:13 -070018 expect(Theme.of(context)!.primaryColor, Colors.green);
Ian Hicksonc12d1202018-02-01 23:12:52 -080019 expect(Directionality.of(context), TextDirection.ltr);
Dan Field8b299332020-01-27 14:36:02 -080020 expect(child, isA<Navigator>());
Ian Hicksonc12d1202018-02-01 23:12:52 -080021 return const Placeholder();
22 },
23 );
24 await tester.pumpWidget(
Alexandre Ardhuind927c932018-09-12 08:29:29 +020025 Directionality(
Ian Hicksonc12d1202018-02-01 23:12:52 -080026 textDirection: TextDirection.rtl,
27 child: app,
28 ),
29 );
30 expect(log, <String>['build']);
31 await tester.pumpWidget(
Alexandre Ardhuind927c932018-09-12 08:29:29 +020032 Directionality(
Ian Hicksonc12d1202018-02-01 23:12:52 -080033 textDirection: TextDirection.ltr,
34 child: app,
35 ),
36 );
37 expect(log, <String>['build']);
38 });
39
Alexandre Ardhuinf15c8872020-02-11 20:58:27 +010040 testWidgets("builder doesn't get called if app doesn't change", (WidgetTester tester) async {
Ian Hicksonc12d1202018-02-01 23:12:52 -080041 final List<String> log = <String>[];
42 await tester.pumpWidget(
Alexandre Ardhuind927c932018-09-12 08:29:29 +020043 MaterialApp(
44 theme: ThemeData(
Ian Hicksonc12d1202018-02-01 23:12:52 -080045 primarySwatch: Colors.yellow,
46 ),
Alexandre Ardhuind927c932018-09-12 08:29:29 +020047 home: Builder(
Ian Hicksonc12d1202018-02-01 23:12:52 -080048 builder: (BuildContext context) {
49 log.add('build');
Greg Spencerc083f022020-10-09 14:58:13 -070050 expect(Theme.of(context)!.primaryColor, Colors.yellow);
Ian Hicksonc12d1202018-02-01 23:12:52 -080051 expect(Directionality.of(context), TextDirection.rtl);
52 return const Placeholder();
53 },
54 ),
Greg Spencerc083f022020-10-09 14:58:13 -070055 builder: (BuildContext context, Widget? child) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +020056 return Directionality(
Ian Hicksonc12d1202018-02-01 23:12:52 -080057 textDirection: TextDirection.rtl,
Greg Spencerc083f022020-10-09 14:58:13 -070058 child: child!,
Ian Hicksonc12d1202018-02-01 23:12:52 -080059 );
60 },
61 ),
62 );
63 expect(log, <String>['build']);
64 });
65}