Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'package:flutter_test/flutter_test.dart'; |
Ian Hickson | 6599271 | 2018-06-19 17:22:56 -0700 | [diff] [blame] | 6 | import 'package:flutter/material.dart'; |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 7 | |
| 8 | void main() { |
Alexandre Ardhuin | f15c887 | 2020-02-11 20:58:27 +0100 | [diff] [blame] | 9 | testWidgets("builder doesn't get called if app doesn't change", (WidgetTester tester) async { |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 10 | final List<String> log = <String>[]; |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 11 | final Widget app = MaterialApp( |
| 12 | theme: ThemeData( |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 13 | primarySwatch: Colors.green, |
| 14 | ), |
| 15 | home: const Placeholder(), |
Greg Spencer | c083f02 | 2020-10-09 14:58:13 -0700 | [diff] [blame] | 16 | builder: (BuildContext context, Widget? child) { |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 17 | log.add('build'); |
Greg Spencer | c083f02 | 2020-10-09 14:58:13 -0700 | [diff] [blame] | 18 | expect(Theme.of(context)!.primaryColor, Colors.green); |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 19 | expect(Directionality.of(context), TextDirection.ltr); |
Dan Field | 8b29933 | 2020-01-27 14:36:02 -0800 | [diff] [blame] | 20 | expect(child, isA<Navigator>()); |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 21 | return const Placeholder(); |
| 22 | }, |
| 23 | ); |
| 24 | await tester.pumpWidget( |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 25 | Directionality( |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 26 | textDirection: TextDirection.rtl, |
| 27 | child: app, |
| 28 | ), |
| 29 | ); |
| 30 | expect(log, <String>['build']); |
| 31 | await tester.pumpWidget( |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 32 | Directionality( |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 33 | textDirection: TextDirection.ltr, |
| 34 | child: app, |
| 35 | ), |
| 36 | ); |
| 37 | expect(log, <String>['build']); |
| 38 | }); |
| 39 | |
Alexandre Ardhuin | f15c887 | 2020-02-11 20:58:27 +0100 | [diff] [blame] | 40 | testWidgets("builder doesn't get called if app doesn't change", (WidgetTester tester) async { |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 41 | final List<String> log = <String>[]; |
| 42 | await tester.pumpWidget( |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 43 | MaterialApp( |
| 44 | theme: ThemeData( |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 45 | primarySwatch: Colors.yellow, |
| 46 | ), |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 47 | home: Builder( |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 48 | builder: (BuildContext context) { |
| 49 | log.add('build'); |
Greg Spencer | c083f02 | 2020-10-09 14:58:13 -0700 | [diff] [blame] | 50 | expect(Theme.of(context)!.primaryColor, Colors.yellow); |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 51 | expect(Directionality.of(context), TextDirection.rtl); |
| 52 | return const Placeholder(); |
| 53 | }, |
| 54 | ), |
Greg Spencer | c083f02 | 2020-10-09 14:58:13 -0700 | [diff] [blame] | 55 | builder: (BuildContext context, Widget? child) { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 56 | return Directionality( |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 57 | textDirection: TextDirection.rtl, |
Greg Spencer | c083f02 | 2020-10-09 14:58:13 -0700 | [diff] [blame] | 58 | child: child!, |
Ian Hickson | c12d120 | 2018-02-01 23:12:52 -0800 | [diff] [blame] | 59 | ); |
| 60 | }, |
| 61 | ), |
| 62 | ); |
| 63 | expect(log, <String>['build']); |
| 64 | }); |
| 65 | } |