From 67e35d612e7a2a2a4306e14a4226622207453886 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Mon, 16 Sep 2019 14:08:18 -0700 Subject: [PATCH] Specify ifTrue and ifFalse for strut FlagProperty (#40609) --- .../flutter/lib/src/painting/strut_style.dart | 2 +- .../test/painting/strut_style_test.dart | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 packages/flutter/test/painting/strut_style_test.dart diff --git a/packages/flutter/lib/src/painting/strut_style.dart b/packages/flutter/lib/src/painting/strut_style.dart index dcec0bb8aa..e697ca974c 100644 --- a/packages/flutter/lib/src/painting/strut_style.dart +++ b/packages/flutter/lib/src/painting/strut_style.dart @@ -597,7 +597,7 @@ class StrutStyle extends Diagnosticable { )); styles.add(EnumProperty('${prefix}style', fontStyle, defaultValue: null)); styles.add(DoubleProperty('${prefix}height', height, unit: 'x', defaultValue: null)); - styles.add(FlagProperty('${prefix}forceStrutHeight', value: forceStrutHeight, defaultValue: null)); + styles.add(FlagProperty('${prefix}forceStrutHeight', value: forceStrutHeight, defaultValue: null, ifTrue: '$prefix', ifFalse: '$prefix')); final bool styleSpecified = styles.any((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info)); styles.forEach(properties.add); diff --git a/packages/flutter/test/painting/strut_style_test.dart b/packages/flutter/test/painting/strut_style_test.dart new file mode 100644 index 0000000000..24e720a15f --- /dev/null +++ b/packages/flutter/test/painting/strut_style_test.dart @@ -0,0 +1,64 @@ +// Copyright 2016 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/painting.dart'; +import '../flutter_test_alternative.dart'; + +void main() { + test('StrutStyle diagnostics test', () { + const StrutStyle s0 = StrutStyle( + fontFamily: 'Serif', + fontSize: 14, + ); + expect( + s0.toString(), + equals('StrutStyle(family: Serif, size: 14.0)'), + ); + + const StrutStyle s1 = StrutStyle( + fontFamily: 'Serif', + fontSize: 14, + forceStrutHeight: true, + ); + expect(s1.fontFamily, 'Serif'); + expect(s1.fontSize, 14.0); + expect(s1, equals(s1)); + expect( + s1.toString(), + equals('StrutStyle(family: Serif, size: 14.0, )'), + ); + + const StrutStyle s2 = StrutStyle( + fontFamily: 'Serif', + fontSize: 14, + forceStrutHeight: false, + ); + expect( + s2.toString(), + equals('StrutStyle(family: Serif, size: 14.0, )'), + ); + + const StrutStyle s3 = StrutStyle(); + expect( + s3.toString(), + equals('StrutStyle'), + ); + + const StrutStyle s4 = StrutStyle( + forceStrutHeight: false, + ); + expect( + s4.toString(), + equals('StrutStyle()'), + ); + + const StrutStyle s5 = StrutStyle( + forceStrutHeight: true, + ); + expect( + s5.toString(), + equals('StrutStyle()'), + ); + }); +}