Specify ifTrue and ifFalse for strut FlagProperty (#40609)

This commit is contained in:
Gary Qian
2019-09-16 14:08:18 -07:00
committed by GitHub
parent b9a34dec7e
commit 67e35d612e
2 changed files with 65 additions and 1 deletions

View File

@@ -597,7 +597,7 @@ class StrutStyle extends Diagnosticable {
));
styles.add(EnumProperty<FontStyle>('${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<strut height forced>', ifFalse: '$prefix<strut height normal>'));
final bool styleSpecified = styles.any((DiagnosticsNode n) => !n.isFiltered(DiagnosticLevel.info));
styles.forEach(properties.add);

View File

@@ -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, <strut height forced>)'),
);
const StrutStyle s2 = StrutStyle(
fontFamily: 'Serif',
fontSize: 14,
forceStrutHeight: false,
);
expect(
s2.toString(),
equals('StrutStyle(family: Serif, size: 14.0, <strut height normal>)'),
);
const StrutStyle s3 = StrutStyle();
expect(
s3.toString(),
equals('StrutStyle'),
);
const StrutStyle s4 = StrutStyle(
forceStrutHeight: false,
);
expect(
s4.toString(),
equals('StrutStyle(<strut height normal>)'),
);
const StrutStyle s5 = StrutStyle(
forceStrutHeight: true,
);
expect(
s5.toString(),
equals('StrutStyle(<strut height forced>)'),
);
});
}