Skip to content

Commit f25872a

Browse files
committed
Fix doubles parsing for Windows client
1 parent 2d549ad commit f25872a

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

client/lib/utils/borders.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44

55
import '../models/control.dart';
66
import 'colors.dart';
7+
import 'numbers.dart';
78

89
BorderRadius? parseBorderRadius(Control control, String propName) {
910
var v = control.attrString(propName, null);
@@ -27,10 +28,10 @@ Border? parseBorder(BuildContext context, Control control, String propName) {
2728

2829
BorderRadius borderRadiusFromJSON(Map<String, dynamic> json) {
2930
return BorderRadius.only(
30-
topLeft: Radius.circular(json['tl'] as double),
31-
topRight: Radius.circular(json['tr'] as double),
32-
bottomLeft: Radius.circular(json['bl'] as double),
33-
bottomRight: Radius.circular(json['br'] as double),
31+
topLeft: Radius.circular(parseDouble(json['tl'])),
32+
topRight: Radius.circular(parseDouble(json['tr'])),
33+
bottomLeft: Radius.circular(parseDouble(json['bl'])),
34+
bottomRight: Radius.circular(parseDouble(json['br'])),
3435
);
3536
}
3637

@@ -48,6 +49,6 @@ BorderSide borderSideFromJSON(
4849
color: json['c'] != null
4950
? HexColor.fromString(context, json['c'] as String) ?? Colors.black
5051
: Colors.black,
51-
width: json['w'] ?? 1,
52+
width: parseDouble(json['w'], 1),
5253
style: BorderStyle.solid);
5354
}

client/lib/utils/edge_insets.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:convert';
33
import 'package:flutter/cupertino.dart';
44

55
import '../models/control.dart';
6+
import 'numbers.dart';
67

78
EdgeInsets? parseEdgeInsets(Control control, String propName) {
89
var v = control.attrString(propName, null);
@@ -15,6 +16,6 @@ EdgeInsets? parseEdgeInsets(Control control, String propName) {
1516
}
1617

1718
EdgeInsets edgeInsetsFromJson(Map<String, dynamic> json) {
18-
return EdgeInsets.fromLTRB(json['l'] as double, json['t'] as double,
19-
json['r'] as double, json['b'] as double);
19+
return EdgeInsets.fromLTRB(parseDouble(json['l']), parseDouble(json['t']),
20+
parseDouble(json['r']), parseDouble(json['b']));
2021
}

client/lib/utils/numbers.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
double parseDouble(dynamic v, [double defValue = 0]) {
2+
if (v is double) {
3+
return v;
4+
} else if (v == null) {
5+
return 0;
6+
} else {
7+
return double.tryParse(v.toString()) ?? defValue;
8+
}
9+
}

docs/roadmap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
* [x] TextButton
2626
* [x] IconButton
2727
* Input and selections
28-
* [ ] TextField
29-
* [ ] Dropdown
28+
* [x] TextField
29+
* [x] Dropdown
3030
* [x] Checkbox
3131
* [x] RadioGroup and Radio
3232
* [ ] Slider

0 commit comments

Comments
 (0)