mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix double.infinity serialization (#40099)
This commit is contained in:
parent
477ae6b8ce
commit
663d0b13bc
@ -2669,7 +2669,11 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
|
||||
json['defaultLevel'] = describeEnum(_defaultLevel);
|
||||
if (value is Diagnosticable || value is DiagnosticsNode)
|
||||
json['isDiagnosticableValue'] = true;
|
||||
if (value is num || value is String || value is bool || value == null)
|
||||
if (v is num)
|
||||
// Workaround for https://github.com/flutter/flutter/issues/39937#issuecomment-529558033.
|
||||
// JSON.stringify replaces infinity and NaN with null.
|
||||
json['value'] = v.isFinite ? v : v.toString();
|
||||
if (value is String || value is bool || value == null)
|
||||
json['value'] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
@ -1050,6 +1050,15 @@ void main() {
|
||||
validateDoublePropertyJsonSerialization(doubleWithUnit);
|
||||
});
|
||||
|
||||
test('double.infinity serialization test', () {
|
||||
final DoubleProperty infProperty1 = DoubleProperty('double1', double.infinity);
|
||||
validateDoublePropertyJsonSerialization(infProperty1);
|
||||
expect(infProperty1.toString(), equals('double1: Infinity'));
|
||||
|
||||
final DoubleProperty infProperty2 = DoubleProperty('double2', double.negativeInfinity);
|
||||
validateDoublePropertyJsonSerialization(infProperty2);
|
||||
expect(infProperty2.toString(), equals('double2: -Infinity'));
|
||||
});
|
||||
|
||||
test('unsafe double property test', () {
|
||||
final DoubleProperty safe = DoubleProperty.lazy(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user