fix DefaultTextStyle not notifying updates for some changes (#9416)

This commit is contained in:
Dwayne Slater 2017-04-16 22:01:37 -04:00 committed by Adam Barth
parent cc3b91479c
commit 0d152a6ba9
2 changed files with 50 additions and 1 deletions

View File

@ -108,7 +108,13 @@ class DefaultTextStyle extends InheritedWidget {
} }
@override @override
bool updateShouldNotify(DefaultTextStyle old) => style != old.style; bool updateShouldNotify(DefaultTextStyle old) {
return style != old.style ||
textAlign != old.textAlign ||
softWrap != old.softWrap ||
overflow != old.overflow ||
maxLines != old.maxLines;
}
@override @override
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {

View File

@ -0,0 +1,43 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
void main() {
testWidgets('DefaultTextStyle changes propagate to Text', (WidgetTester tester) async {
const Text textWidget = const Text('Hello');
const TextStyle s1 = const TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.w800,
height: 123.0,
);
await tester.pumpWidget(const DefaultTextStyle(
style: s1,
child: textWidget
));
RichText text = tester.firstWidget(find.byType(RichText));
expect(text, isNotNull);
expect(text.text.style, s1);
await tester.pumpWidget(const DefaultTextStyle(
style: s1,
textAlign: TextAlign.justify,
softWrap: false,
overflow: TextOverflow.fade,
maxLines: 3,
child: textWidget
));
text = tester.firstWidget(find.byType(RichText));
expect(text, isNotNull);
expect(text.text.style, s1);
expect(text.textAlign, TextAlign.justify);
expect(text.softWrap, false);
expect(text.overflow, TextOverflow.fade);
expect(text.maxLines, 3);
});
}