From 6cdfa1195c490023e2b8580769e6940a60b0584f Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Fri, 10 May 2024 17:50:56 +0200 Subject: [PATCH 1/5] refactor parseInt --- packages/flet/lib/src/controls/linechart.dart | 1 + .../flet/lib/src/controls/scrollable_control.dart | 2 +- packages/flet/lib/src/utils/animations.dart | 3 ++- packages/flet/lib/src/utils/buttons.dart | 2 +- packages/flet/lib/src/utils/charts.dart | 11 +++++++++-- packages/flet/lib/src/utils/numbers.dart | 2 +- packages/flet/lib/src/utils/text.dart | 2 +- packages/flet_video/lib/src/video.dart | 4 ++-- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/flet/lib/src/controls/linechart.dart b/packages/flet/lib/src/controls/linechart.dart index bf650fb62..0379071f6 100644 --- a/packages/flet/lib/src/controls/linechart.dart +++ b/packages/flet/lib/src/controls/linechart.dart @@ -450,6 +450,7 @@ class _LineChartControlState extends State { dashArray: dashPattern != null ? (json.decode(dashPattern) as List) .map((e) => parseInt(e)) + .whereNotNull() .toList() : null, shadow: shadow.isNotEmpty diff --git a/packages/flet/lib/src/controls/scrollable_control.dart b/packages/flet/lib/src/controls/scrollable_control.dart index e3dd41692..c97843f39 100644 --- a/packages/flet/lib/src/controls/scrollable_control.dart +++ b/packages/flet/lib/src/controls/scrollable_control.dart @@ -91,7 +91,7 @@ class _ScrollableControlState extends State var params = Map.from(mj["p"] as Map); if (name == "scroll_to") { - var duration = parseInt(params["duration"]); + var duration = parseInt(params["duration"], 0)!; var curve = params["curve"] != null ? parseCurve(params["curve"] as String) : Curves.ease; diff --git a/packages/flet/lib/src/utils/animations.dart b/packages/flet/lib/src/utils/animations.dart index a623e50de..4fc452bb2 100644 --- a/packages/flet/lib/src/utils/animations.dart +++ b/packages/flet/lib/src/utils/animations.dart @@ -18,7 +18,8 @@ ImplicitAnimationDetails? parseAnimation(Control control, String propName) { ImplicitAnimationDetails animationFromJSON(dynamic json) { if (json is int) { return ImplicitAnimationDetails( - duration: Duration(milliseconds: parseInt(json)), curve: Curves.linear); + duration: Duration(milliseconds: parseInt(json, 0)!), + curve: Curves.linear); } else if (json is bool && json == true) { return ImplicitAnimationDetails( duration: const Duration(milliseconds: 1000), curve: Curves.linear); diff --git a/packages/flet/lib/src/utils/buttons.dart b/packages/flet/lib/src/utils/buttons.dart index d9e18e66c..07b97f9b9 100644 --- a/packages/flet/lib/src/utils/buttons.dart +++ b/packages/flet/lib/src/utils/buttons.dart @@ -72,7 +72,7 @@ ButtonStyle? buttonStyleFromJSON(ThemeData theme, Map json, elevation: getMaterialStateProperty( json["elevation"], (jv) => parseDouble(jv), defaultElevation), animationDuration: json["animation_duration"] != null - ? Duration(milliseconds: parseInt(json["animation_duration"])) + ? Duration(milliseconds: parseInt(json["animation_duration"], 0)!) : null, padding: getMaterialStateProperty( json["padding"], (jv) => edgeInsetsFromJson(jv), defaultPadding), diff --git a/packages/flet/lib/src/utils/charts.dart b/packages/flet/lib/src/utils/charts.dart index 19a3a7bd4..15fae7d5c 100644 --- a/packages/flet/lib/src/utils/charts.dart +++ b/packages/flet/lib/src/utils/charts.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:collection/collection.dart'; import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; @@ -67,7 +68,10 @@ FlLine? parseSelectedFlLine(ThemeData theme, Control control, String propName, : defaultGetPointColor(color, gradient, 0), strokeWidth: j['width'] != null ? parseDouble(j['width'], 3) : 3, dashArray: j['dash_pattern'] != null - ? (j['dash_pattern'] as List).map((e) => parseInt(e)).toList() + ? (j['dash_pattern'] as List) + .map((e) => parseInt(e)) + .whereNotNull() + .toList() : null); } @@ -82,7 +86,10 @@ FlLine? flineFromJSON(theme, j) { : Colors.black, strokeWidth: j['width'] != null ? parseDouble(j['width'], 1) : 2, dashArray: j['dash_pattern'] != null - ? (j['dash_pattern'] as List).map((e) => parseInt(e)).toList() + ? (j['dash_pattern'] as List) + .map((e) => parseInt(e)) + .whereNotNull() + .toList() : null); } diff --git a/packages/flet/lib/src/utils/numbers.dart b/packages/flet/lib/src/utils/numbers.dart index 2c5597085..9b60df23e 100644 --- a/packages/flet/lib/src/utils/numbers.dart +++ b/packages/flet/lib/src/utils/numbers.dart @@ -8,7 +8,7 @@ double parseDouble(dynamic v, [double defValue = 0]) { } } -int parseInt(dynamic v, [int defValue = 0]) { +int? parseInt(dynamic v, [int? defValue]) { if (v is int) { return v; } else if (v == null) { diff --git a/packages/flet/lib/src/utils/text.dart b/packages/flet/lib/src/utils/text.dart index 29a0659ef..2d860e982 100644 --- a/packages/flet/lib/src/utils/text.dart +++ b/packages/flet/lib/src/utils/text.dart @@ -165,7 +165,7 @@ TextStyle textStyleFromJson(ThemeData theme, Map json) { } List decorations = []; - var decor = parseInt(json["decoration"]); + var decor = parseInt(json["decoration"], 0)!; if (decor & 0x1 > 0) { decorations.add(TextDecoration.underline); } diff --git a/packages/flet_video/lib/src/video.dart b/packages/flet_video/lib/src/video.dart index cf6834f3a..87caa360a 100644 --- a/packages/flet_video/lib/src/video.dart +++ b/packages/flet_video/lib/src/video.dart @@ -217,7 +217,7 @@ class _VideoControlState extends State with FletStoreMixin { break; case "jump_to": debugPrint("Video.jump($hashCode)"); - await player.jump(parseInt(args["media_index"], 0)); + await player.jump(parseInt(args["media_index"], 0)!); break; case "playlist_add": debugPrint("Video.add($hashCode)"); @@ -234,7 +234,7 @@ class _VideoControlState extends State with FletStoreMixin { break; case "playlist_remove": debugPrint("Video.remove($hashCode)"); - await player.remove(parseInt(args["media_index"], 0)); + await player.remove(parseInt(args["media_index"], 0)!); break; case "is_playing": debugPrint("Video.isPlaying($hashCode)"); From dbf093eef214806e6c3021776ce322a5822539d3 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Fri, 10 May 2024 18:34:05 +0200 Subject: [PATCH 2/5] refactor parseDouble --- client/pubspec.lock | 12 +- packages/flet/lib/src/controls/canvas.dart | 61 ++++--- .../lib/src/controls/scrollable_control.dart | 4 +- packages/flet/lib/src/controls/text.dart | 4 +- packages/flet/lib/src/utils/alignment.dart | 2 +- packages/flet/lib/src/utils/borders.dart | 12 +- packages/flet/lib/src/utils/buttons.dart | 2 +- packages/flet/lib/src/utils/charts.dart | 20 +- packages/flet/lib/src/utils/colors.dart | 2 +- packages/flet/lib/src/utils/dismissible.dart | 2 +- packages/flet/lib/src/utils/drawing.dart | 27 +-- packages/flet/lib/src/utils/edge_insets.dart | 18 +- packages/flet/lib/src/utils/gradient.dart | 14 +- packages/flet/lib/src/utils/images.dart | 10 +- packages/flet/lib/src/utils/menu.dart | 2 +- packages/flet/lib/src/utils/numbers.dart | 2 +- packages/flet/lib/src/utils/responsive.dart | 2 +- packages/flet/lib/src/utils/shadows.dart | 7 +- packages/flet/lib/src/utils/text.dart | 4 +- packages/flet/lib/src/utils/theme.dart | 172 +++++++----------- packages/flet/lib/src/utils/transforms.dart | 15 +- packages/flet_video/lib/src/utils/video.dart | 4 +- 22 files changed, 187 insertions(+), 211 deletions(-) diff --git a/client/pubspec.lock b/client/pubspec.lock index 679983a9c..07dcc41da 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -137,6 +137,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" + cross_file: + dependency: transitive + description: + name: cross_file + sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32" + url: "https://pub.dev" + source: hosted + version: "0.3.4+1" crypto: dependency: transitive description: @@ -197,10 +205,10 @@ packages: dependency: transitive description: name: file_picker - sha256: "4e42aacde3b993c5947467ab640882c56947d9d27342a5b6f2895b23956954a6" + sha256: d1d0ac3966b36dc3e66eeefb40280c17feb87fa2099c6e22e6a1fc959327bd03 url: "https://pub.dev" source: hosted - version: "6.1.1" + version: "8.0.0+1" fixnum: dependency: transitive description: diff --git a/packages/flet/lib/src/controls/canvas.dart b/packages/flet/lib/src/controls/canvas.dart index db3c7f2e9..8704a4d33 100644 --- a/packages/flet/lib/src/controls/canvas.dart +++ b/packages/flet/lib/src/controls/canvas.dart @@ -345,56 +345,63 @@ class FletCustomPainter extends CustomPainter { for (var elem in (j as List)) { var type = elem["type"]; if (type == "moveto") { - path.moveTo(parseDouble(elem["x"]), parseDouble(elem["y"])); + path.moveTo(parseDouble(elem["x"], 0)!, parseDouble(elem["y"], 0)!); } else if (type == "lineto") { - path.lineTo(parseDouble(elem["x"]), parseDouble(elem["y"])); + path.lineTo(parseDouble(elem["x"], 0)!, parseDouble(elem["y"], 0)!); } else if (type == "arc") { path.addArc( - Rect.fromLTWH(parseDouble(elem["x"]), parseDouble(elem["y"]), - parseDouble(elem["width"]), parseDouble(elem["height"])), - parseDouble(elem["start_angle"]), - parseDouble(elem["sweep_angle"])); + Rect.fromLTWH( + parseDouble(elem["x"], 0)!, + parseDouble(elem["y"], 0)!, + parseDouble(elem["width"], 0)!, + parseDouble(elem["height"], 0)!), + parseDouble(elem["start_angle"], 0)!, + parseDouble(elem["sweep_angle"], 0)!); } else if (type == "arcto") { - path.arcToPoint(Offset(parseDouble(elem["x"]), parseDouble(elem["y"])), - radius: Radius.circular(parseDouble(elem["radius"])), - rotation: parseDouble(elem["rotation"]), + path.arcToPoint( + Offset(parseDouble(elem["x"], 0)!, parseDouble(elem["y"], 0)!), + radius: Radius.circular(parseDouble(elem["radius"], 0)!), + rotation: parseDouble(elem["rotation"], 0)!, largeArc: parseBool(elem["large_arc"]), clockwise: parseBool(elem["clockwise"])); } else if (type == "oval") { path.addOval(Rect.fromLTWH( - parseDouble(elem["x"]), - parseDouble(elem["y"]), - parseDouble(elem["width"]), - parseDouble(elem["height"]))); + parseDouble(elem["x"], 0)!, + parseDouble(elem["y"], 0)!, + parseDouble(elem["width"], 0)!, + parseDouble(elem["height"], 0)!)); } else if (type == "rect") { var borderRadius = elem["border_radius"] != null ? borderRadiusFromJSON(elem["border_radius"]) : null; path.addRRect(RRect.fromRectAndCorners( - Rect.fromLTWH(parseDouble(elem["x"]), parseDouble(elem["y"]), - parseDouble(elem["width"]), parseDouble(elem["height"])), + Rect.fromLTWH( + parseDouble(elem["x"], 0)!, + parseDouble(elem["y"], 0)!, + parseDouble(elem["width"], 0)!, + parseDouble(elem["height"], 0)!), topLeft: borderRadius?.topLeft ?? Radius.zero, topRight: borderRadius?.topRight ?? Radius.zero, bottomLeft: borderRadius?.bottomLeft ?? Radius.zero, bottomRight: borderRadius?.bottomRight ?? Radius.zero)); } else if (type == "conicto") { path.conicTo( - parseDouble(elem["cp1x"]), - parseDouble(elem["cp1y"]), - parseDouble(elem["x"]), - parseDouble(elem["y"]), - parseDouble(elem["w"])); + parseDouble(elem["cp1x"], 0)!, + parseDouble(elem["cp1y"], 0)!, + parseDouble(elem["x"], 0)!, + parseDouble(elem["y"], 0)!, + parseDouble(elem["w"], 0)!); } else if (type == "cubicto") { path.cubicTo( - parseDouble(elem["cp1x"]), - parseDouble(elem["cp1y"]), - parseDouble(elem["cp2x"]), - parseDouble(elem["cp2y"]), - parseDouble(elem["x"]), - parseDouble(elem["y"])); + parseDouble(elem["cp1x"], 0)!, + parseDouble(elem["cp1y"], 0)!, + parseDouble(elem["cp2x"], 0)!, + parseDouble(elem["cp2y"], 0)!, + parseDouble(elem["x"], 0)!, + parseDouble(elem["y"], 0)!); } else if (type == "subpath") { path.addPath(buildPath(elem["elements"]), - Offset(parseDouble(elem["x"]), parseDouble(elem["y"]))); + Offset(parseDouble(elem["x"], 0)!, parseDouble(elem["y"], 0)!)); } else if (type == "close") { path.close(); } diff --git a/packages/flet/lib/src/controls/scrollable_control.dart b/packages/flet/lib/src/controls/scrollable_control.dart index c97843f39..f7a400e79 100644 --- a/packages/flet/lib/src/controls/scrollable_control.dart +++ b/packages/flet/lib/src/controls/scrollable_control.dart @@ -111,7 +111,7 @@ class _ScrollableControlState extends State }); } else if (params["offset"] != null) { WidgetsBinding.instance.addPostFrameCallback((_) { - var offset = parseDouble(params["offset"]); + var offset = parseDouble(params["offset"], 0)!; if (offset < 0) { offset = _controller.position.maxScrollExtent + offset + 1; } @@ -127,7 +127,7 @@ class _ScrollableControlState extends State }); } else if (params["delta"] != null) { WidgetsBinding.instance.addPostFrameCallback((_) { - var delta = parseDouble(params["delta"]); + var delta = parseDouble(params["delta"], 0)!; var offset = _controller.position.pixels + delta; if (duration < 1) { _controller.jumpTo(offset); diff --git a/packages/flet/lib/src/controls/text.dart b/packages/flet/lib/src/controls/text.dart index 54d82172b..bbdcf9aa6 100644 --- a/packages/flet/lib/src/controls/text.dart +++ b/packages/flet/lib/src/controls/text.dart @@ -70,8 +70,8 @@ class TextControl extends StatelessWidget with FletStoreMixin { List variations = []; if (fontWeight.startsWith("w")) { - variations - .add(FontVariation('wght', parseDouble(fontWeight.substring(1)))); + variations.add( + FontVariation('wght', parseDouble(fontWeight.substring(1), 0)!)); } style = (style ?? const TextStyle()).copyWith( diff --git a/packages/flet/lib/src/utils/alignment.dart b/packages/flet/lib/src/utils/alignment.dart index 457ce084e..d3b689ad6 100644 --- a/packages/flet/lib/src/utils/alignment.dart +++ b/packages/flet/lib/src/utils/alignment.dart @@ -61,5 +61,5 @@ Alignment? parseAlignment(Control control, String propName) { } Alignment alignmentFromJson(Map json) { - return Alignment(parseDouble(json['x']), parseDouble(json['y'])); + return Alignment(parseDouble(json['x'], 0)!, parseDouble(json['y'], 0)!); } diff --git a/packages/flet/lib/src/utils/borders.dart b/packages/flet/lib/src/utils/borders.dart index 6897feeac..56cbaef57 100644 --- a/packages/flet/lib/src/utils/borders.dart +++ b/packages/flet/lib/src/utils/borders.dart @@ -59,13 +59,13 @@ OutlinedBorder? parseOutlinedBorder(Control control, String propName) { BorderRadius borderRadiusFromJSON(dynamic json) { if (json is int || json is double) { - return BorderRadius.all(Radius.circular(parseDouble(json))); + return BorderRadius.all(Radius.circular(parseDouble(json, 0)!)); } return BorderRadius.only( - topLeft: Radius.circular(parseDouble(json['tl'])), - topRight: Radius.circular(parseDouble(json['tr'])), - bottomLeft: Radius.circular(parseDouble(json['bl'])), - bottomRight: Radius.circular(parseDouble(json['br'])), + topLeft: Radius.circular(parseDouble(json['tl'], 0)!), + topRight: Radius.circular(parseDouble(json['tr'], 0)!), + bottomLeft: Radius.circular(parseDouble(json['bl'], 0)!), + bottomRight: Radius.circular(parseDouble(json['br'], 0)!), ); } @@ -91,7 +91,7 @@ BorderSide? borderSideFromJSON(ThemeData? theme, dynamic json, defaultSideColor ?? Colors.black : Colors.black, - width: parseDouble(json['w'], 1), + width: parseDouble(json['w'], 1)!, style: BorderStyle.solid) : null; } diff --git a/packages/flet/lib/src/utils/buttons.dart b/packages/flet/lib/src/utils/buttons.dart index 07b97f9b9..ef4c27293 100644 --- a/packages/flet/lib/src/utils/buttons.dart +++ b/packages/flet/lib/src/utils/buttons.dart @@ -70,7 +70,7 @@ ButtonStyle? buttonStyleFromJSON(ThemeData theme, Map json, (jv) => HexColor.fromString(theme, jv as String), defaultSurfaceTintColor), elevation: getMaterialStateProperty( - json["elevation"], (jv) => parseDouble(jv), defaultElevation), + json["elevation"], (jv) => parseDouble(jv, 0)!, defaultElevation), animationDuration: json["animation_duration"] != null ? Duration(milliseconds: parseInt(json["animation_duration"], 0)!) : null, diff --git a/packages/flet/lib/src/utils/charts.dart b/packages/flet/lib/src/utils/charts.dart index 15fae7d5c..1dda2b4e1 100644 --- a/packages/flet/lib/src/utils/charts.dart +++ b/packages/flet/lib/src/utils/charts.dart @@ -66,7 +66,7 @@ FlLine? parseSelectedFlLine(ThemeData theme, Control control, String propName, color: j['color'] != null ? HexColor.fromString(theme, j['color'] as String) ?? Colors.black : defaultGetPointColor(color, gradient, 0), - strokeWidth: j['width'] != null ? parseDouble(j['width'], 3) : 3, + strokeWidth: parseDouble(j['width'], 2)!, dashArray: j['dash_pattern'] != null ? (j['dash_pattern'] as List) .map((e) => parseInt(e)) @@ -84,7 +84,7 @@ FlLine? flineFromJSON(theme, j) { color: j['color'] != null ? HexColor.fromString(theme, j['color'] as String) ?? Colors.black : Colors.black, - strokeWidth: j['width'] != null ? parseDouble(j['width'], 1) : 2, + strokeWidth: parseDouble(j['width'], 2)!, dashArray: j['dash_pattern'] != null ? (j['dash_pattern'] as List) .map((e) => parseInt(e)) @@ -148,35 +148,31 @@ FlDotPainter? chartDotPainterFromJSON( ? HexColor.fromString(theme, json['color'] as String) ?? Colors.green : defaultGetPointColor(barColor, barGradient, percentage), - radius: json["radius"] != null ? parseDouble(json["radius"]) : null, + radius: parseDouble(json["radius"]), strokeColor: json['stroke_color'] != null ? HexColor.fromString(theme, json['color'] as String) ?? const Color.fromRGBO(76, 175, 80, 1) : defaultGetDotStrokeColor(barColor, barGradient, percentage), - strokeWidth: json["stroke_width"] != null - ? parseDouble(json["stroke_width"]) - : 1.0); + strokeWidth: parseDouble(json["stroke_width"], 1.0)!); } else if (type == "square") { return FlDotSquarePainter( color: json['color'] != null ? HexColor.fromString(theme, json['color'] as String) ?? Colors.green : defaultGetPointColor(barColor, barGradient, percentage), - size: json["size"] != null ? parseDouble(json["size"]) : 4.0, + size: parseDouble(json["size"], 4.0)!, strokeColor: json['stroke_color'] != null ? HexColor.fromString(theme, json['color'] as String) ?? const Color.fromRGBO(76, 175, 80, 1) : defaultGetDotStrokeColor(barColor, barGradient, percentage), - strokeWidth: json["stroke_width"] != null - ? parseDouble(json["stroke_width"]) - : 1.0); + strokeWidth: parseDouble(json["stroke_width"], 1.0)!); } else if (type == "cross") { return FlDotCrossPainter( color: json['color'] != null ? HexColor.fromString(theme, json['color'] as String) ?? Colors.green : defaultGetDotStrokeColor(barColor, barGradient, percentage), - size: json["size"] != null ? parseDouble(json["size"]) : 8.0, - width: json["width"] != null ? parseDouble(json["width"]) : 2.0, + size: parseDouble(json["size"], 8.0)!, + width: parseDouble(json["width"], 2.0)!, ); } return null; diff --git a/packages/flet/lib/src/utils/colors.dart b/packages/flet/lib/src/utils/colors.dart index 3c984338e..281572a13 100644 --- a/packages/flet/lib/src/utils/colors.dart +++ b/packages/flet/lib/src/utils/colors.dart @@ -156,7 +156,7 @@ extension HexColor on Color { } if (color != null && colorOpacity != null) { - color = color.withOpacity(parseDouble(colorOpacity)); + color = color.withOpacity(parseDouble(colorOpacity, 1.0)!); } return color; diff --git a/packages/flet/lib/src/utils/dismissible.dart b/packages/flet/lib/src/utils/dismissible.dart index 94d0168ec..9722b4c8b 100644 --- a/packages/flet/lib/src/utils/dismissible.dart +++ b/packages/flet/lib/src/utils/dismissible.dart @@ -13,7 +13,7 @@ Map? parseDismissThresholds( } final j1 = json.decode(v); - return getDismissThresholds(j1, (jv) => parseDouble(jv)); + return getDismissThresholds(j1, (jv) => parseDouble(jv, 0)!); } Map? getDismissThresholds( diff --git a/packages/flet/lib/src/utils/drawing.dart b/packages/flet/lib/src/utils/drawing.dart index ee31d5e02..c41273679 100644 --- a/packages/flet/lib/src/utils/drawing.dart +++ b/packages/flet/lib/src/utils/drawing.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:ui' as ui; +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import '../models/control.dart'; @@ -29,7 +30,10 @@ List? parsePaintStrokeDashPattern(Control control, String propName) { final j1 = json.decode(v); return j1["stroke_dash_pattern"] != null - ? (j1["stroke_dash_pattern"] as List).map((e) => parseDouble(e)).toList() + ? (j1["stroke_dash_pattern"] as List) + .map((e) => parseDouble(e)) + .whereNotNull() + .toList() : null; } @@ -54,12 +58,9 @@ Paint paintFromJSON(ThemeData? theme, Map json) { if (json["gradient"] != null) { paint.shader = paintGradientFromJSON(theme, json["gradient"]); } - if (json["stroke_miter_limit"] != null) { - paint.strokeMiterLimit = parseDouble(json["stroke_miter_limit"]); - } - if (json["stroke_width"] != null) { - paint.strokeWidth = parseDouble(json["stroke_width"]); - } + paint.strokeMiterLimit = parseDouble(json["stroke_miter_limit"], 4)!; + paint.strokeWidth = parseDouble(json["stroke_width"], 0)!; + if (json["stroke_cap"] != null) { paint.strokeCap = StrokeCap.values.firstWhere( (e) => e.name.toLowerCase() == json["stroke_cap"].toLowerCase(), @@ -91,13 +92,13 @@ ui.Gradient? paintGradientFromJSON( } else if (type == "radial") { return ui.Gradient.radial( offsetFromJson(json["center"])!, - parseDouble(json["radius"]), + parseDouble(json["radius"], 0)!, parseColors(theme, json["colors"]), parseStops(json["color_stops"]), parseTileMode(json["tile_mode"]), null, offsetFromJson(json["focal"]), - parseDouble(json["focal_radius"]), + parseDouble(json["focal_radius"], 0)!, ); } else if (type == "sweep") { Offset center = offsetFromJson(json["center"])!; @@ -106,8 +107,8 @@ ui.Gradient? paintGradientFromJSON( parseColors(theme, json["colors"]), parseStops(json["color_stops"]), parseTileMode(json["tile_mode"]), - parseDouble(json["start_angle"]), - parseDouble(json["end_angle"]), + parseDouble(json["start_angle"], 0)!, + parseDouble(json["end_angle"], 0)!, parseRotationToMatrix4( json["rotation"], Rect.fromCircle(center: center, radius: 10))); } @@ -118,8 +119,8 @@ Offset? offsetFromJson(dynamic json) { if (json == null) { return null; } else if (json is List && json.length > 1) { - return Offset(parseDouble(json[0]), parseDouble(json[1])); + return Offset(parseDouble(json[0], 0)!, parseDouble(json[1], 0)!); } else { - return Offset(parseDouble(json["x"]), parseDouble(json["y"])); + return Offset(parseDouble(json["x"], 0)!, parseDouble(json["y"], 0)!); } } diff --git a/packages/flet/lib/src/utils/edge_insets.dart b/packages/flet/lib/src/utils/edge_insets.dart index ea7ea133d..d606f26df 100644 --- a/packages/flet/lib/src/utils/edge_insets.dart +++ b/packages/flet/lib/src/utils/edge_insets.dart @@ -17,10 +17,13 @@ EdgeInsets? parseEdgeInsets(Control control, String propName) { EdgeInsets edgeInsetsFromJson(dynamic json) { if (json is int || json is double) { - return EdgeInsets.all(parseDouble(json)); + return EdgeInsets.all(parseDouble(json, 0)!); } - return EdgeInsets.fromLTRB(parseDouble(json['l']), parseDouble(json['t']), - parseDouble(json['r']), parseDouble(json['b'])); + return EdgeInsets.fromLTRB( + parseDouble(json['l'], 0)!, + parseDouble(json['t'], 0)!, + parseDouble(json['r'], 0)!, + parseDouble(json['b'], 0)!); } EdgeInsetsDirectional? parseEdgeInsetsDirectional( @@ -36,8 +39,11 @@ EdgeInsetsDirectional? parseEdgeInsetsDirectional( EdgeInsetsDirectional edgeInsetsDirectionalFromJson(dynamic json) { if (json is int || json is double) { - return EdgeInsetsDirectional.all(parseDouble(json)); + return EdgeInsetsDirectional.all(parseDouble(json, 0)!); } - return EdgeInsetsDirectional.fromSTEB(parseDouble(json['l']), - parseDouble(json['t']), parseDouble(json['r']), parseDouble(json['b'])); + return EdgeInsetsDirectional.fromSTEB( + parseDouble(json['l'], 0)!, + parseDouble(json['t'], 0)!, + parseDouble(json['r'], 0)!, + parseDouble(json['b'], 0)!); } diff --git a/packages/flet/lib/src/utils/gradient.dart b/packages/flet/lib/src/utils/gradient.dart index 95e491373..26503641d 100644 --- a/packages/flet/lib/src/utils/gradient.dart +++ b/packages/flet/lib/src/utils/gradient.dart @@ -33,8 +33,8 @@ Gradient? gradientFromJSON(ThemeData? theme, Map json) { colors: parseColors(theme, json["colors"]), stops: parseStops(json["stops"]), center: alignmentFromJson(json["center"]), - radius: parseDouble(json["radius"]), - focalRadius: parseDouble(json["focal_radius"]), + radius: parseDouble(json["radius"], 0.5)!, + focalRadius: parseDouble(json["focal_radius"], 0)!, focal: json["focal"] != null ? alignmentFromJson(json["focal"]) : null, tileMode: parseTileMode(json["tile_mode"]), transform: parseRotation(json["rotation"])); @@ -42,8 +42,8 @@ Gradient? gradientFromJSON(ThemeData? theme, Map json) { return SweepGradient( colors: parseColors(theme, json["colors"]), center: alignmentFromJson(json["center"]), - startAngle: parseDouble(json["start_angle"]), - endAngle: parseDouble(json["end_angle"]), + startAngle: parseDouble(json["start_angle"], 0)!, + endAngle: parseDouble(json["end_angle"], 0)!, stops: parseStops(json["stops"]), tileMode: parseTileMode(json["tile_mode"]), transform: parseRotation(json["rotation"])); @@ -65,7 +65,7 @@ List? parseStops(dynamic jv) { if (list.isEmpty) { return null; } - return list.map((v) => parseDouble(v)).toList(); + return list.map((v) => parseDouble(v, 0)!).toList(); } TileMode parseTileMode(dynamic jv) { @@ -80,14 +80,14 @@ GradientRotation? parseRotation(dynamic jv) { if (jv == null) { return null; } - return GradientRotation(parseDouble(jv)); + return GradientRotation(parseDouble(jv, 0)!); } Float64List? parseRotationToMatrix4(dynamic jv, Rect bounds) { if (jv == null) { return null; } - return GradientRotation(parseDouble(jv)).transform(bounds).storage; + return GradientRotation(parseDouble(jv, 0)!).transform(bounds).storage; } extension GradientExtension on Gradient { diff --git a/packages/flet/lib/src/utils/images.dart b/packages/flet/lib/src/utils/images.dart index f545dad0d..089ed1252 100644 --- a/packages/flet/lib/src/utils/images.dart +++ b/packages/flet/lib/src/utils/images.dart @@ -38,13 +38,13 @@ ImageFilter blurImageFilterFromJSON(dynamic json) { double sigmaY = 0.0; TileMode tileMode = TileMode.clamp; if (json is int || json is double) { - sigmaX = sigmaY = parseDouble(json); + sigmaX = sigmaY = parseDouble(json, 0)!; } else if (json is List && json.length > 1) { - sigmaX = parseDouble(json[0]); - sigmaY = parseDouble(json[1]); + sigmaX = parseDouble(json[0], 0)!; + sigmaY = parseDouble(json[1], 0)!; } else { - sigmaX = parseDouble(json["sigma_x"]); - sigmaY = parseDouble(json["sigma_y"]); + sigmaX = parseDouble(json["sigma_x"], 0)!; + sigmaY = parseDouble(json["sigma_y"], 0)!; tileMode = parseTileMode(json["tile_mode"]); } diff --git a/packages/flet/lib/src/utils/menu.dart b/packages/flet/lib/src/utils/menu.dart index 507c9d66e..af2e2d6c2 100644 --- a/packages/flet/lib/src/utils/menu.dart +++ b/packages/flet/lib/src/utils/menu.dart @@ -66,7 +66,7 @@ MenuStyle? menuStyleFromJSON(ThemeData theme, Map json, (jv) => HexColor.fromString(theme, jv as String), defaultSurfaceTintColor), elevation: getMaterialStateProperty( - json["elevation"], (jv) => parseDouble(jv), defaultElevation), + json["elevation"], (jv) => parseDouble(jv, 0)!, defaultElevation), padding: getMaterialStateProperty( json["padding"], (jv) => edgeInsetsFromJson(jv), defaultPadding), side: getMaterialStateProperty( diff --git a/packages/flet/lib/src/utils/numbers.dart b/packages/flet/lib/src/utils/numbers.dart index 9b60df23e..5f15d5ed7 100644 --- a/packages/flet/lib/src/utils/numbers.dart +++ b/packages/flet/lib/src/utils/numbers.dart @@ -1,4 +1,4 @@ -double parseDouble(dynamic v, [double defValue = 0]) { +double? parseDouble(dynamic v, [double? defValue]) { if (v is double) { return v; } else if (v == null) { diff --git a/packages/flet/lib/src/utils/responsive.dart b/packages/flet/lib/src/utils/responsive.dart index 9fab84762..bd442d13e 100644 --- a/packages/flet/lib/src/utils/responsive.dart +++ b/packages/flet/lib/src/utils/responsive.dart @@ -21,7 +21,7 @@ Map parseResponsiveNumber( } Map responsiveNumberFromJson(Map json) { - return json.map((key, value) => MapEntry(key, parseDouble(value))); + return json.map((key, value) => MapEntry(key, parseDouble(value, 0)!)); } double getBreakpointNumber(Map responsiveNumber, double width, diff --git a/packages/flet/lib/src/utils/shadows.dart b/packages/flet/lib/src/utils/shadows.dart index 4d22df509..3851f32f4 100644 --- a/packages/flet/lib/src/utils/shadows.dart +++ b/packages/flet/lib/src/utils/shadows.dart @@ -37,9 +37,6 @@ BoxShadow boxShadowFromJSON(ThemeData theme, dynamic json) { ? BlurStyle.values .firstWhere((e) => e.name.toLowerCase() == json["blur_style"]) : BlurStyle.normal, - blurRadius: - json["blur_radius"] != null ? parseDouble(json["blur_radius"]) : 0.0, - spreadRadius: json["spread_radius"] != null - ? parseDouble(json["spread_radius"]) - : 0.0); + blurRadius: parseDouble(json["blur_radius"], 0)!, + spreadRadius: parseDouble(json["spread_radius"], 0)!); } diff --git a/packages/flet/lib/src/utils/text.dart b/packages/flet/lib/src/utils/text.dart index 2d860e982..de69f67af 100644 --- a/packages/flet/lib/src/utils/text.dart +++ b/packages/flet/lib/src/utils/text.dart @@ -161,7 +161,9 @@ TextStyle textStyleFromJson(ThemeData theme, Map json) { List? variations; if (fontWeight != null && fontWeight.startsWith("w")) { - variations = [FontVariation('wght', parseDouble(fontWeight.substring(1)))]; + variations = [ + FontVariation('wght', parseDouble(fontWeight.substring(1), 0)!) + ]; } List decorations = []; diff --git a/packages/flet/lib/src/utils/theme.dart b/packages/flet/lib/src/utils/theme.dart index 86eed8c0e..ea8073d82 100644 --- a/packages/flet/lib/src/utils/theme.dart +++ b/packages/flet/lib/src/utils/theme.dart @@ -266,18 +266,13 @@ ScrollbarThemeData? parseScrollBarTheme( thumbColor: getMaterialStateProperty( j["thumb_color"], (jv) => HexColor.fromString(theme, jv as String)), thickness: getMaterialStateProperty( - j["thickness"], (jv) => parseDouble(jv)), - radius: - j["radius"] != null ? Radius.circular(parseDouble(j["radius"])) : null, - crossAxisMargin: j["cross_axis_margin"] != null - ? parseDouble(j["cross_axis_margin"]) - : null, - mainAxisMargin: j["main_axis_margin"] != null - ? parseDouble(j["main_axis_margin"]) - : null, - minThumbLength: j["min_thumb_length"] != null - ? parseDouble(j["min_thumb_length"]) + j["thickness"], (jv) => parseDouble(jv, 0)!), + radius: j["radius"] != null + ? Radius.circular(parseDouble(j["radius"], 0)!) : null, + crossAxisMargin: parseDouble(j["cross_axis_margin"]), + mainAxisMargin: parseDouble(j["main_axis_margin"]), + minThumbLength: parseDouble(j["min_thumb_length"]), interactive: j["interactive"] != null ? parseBool(j["interactive"]) : null, ); } @@ -322,8 +317,7 @@ TabBarTheme? parseTabBarTheme(ThemeData theme, Map? j) { labelPadding: j["label_padding"] != null ? edgeInsetsFromJson(j["label_padding"]) : null, - dividerHeight: - j["divider_height"] != null ? parseDouble(j["divider_height"]) : null, + dividerHeight: parseDouble(j["divider_height"]), labelStyle: j["label_text_style"] != null ? textStyleFromJson(theme, j["label_text_style"]) : null, @@ -375,7 +369,7 @@ DialogTheme? parseDialogTheme(ThemeData theme, Map? j) { shadowColor: HexColor.fromString(theme, j["shadow_color"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), iconColor: HexColor.fromString(theme, j["icon_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, titleTextStyle: parseTextStyle("title_text_style"), contentTextStyle: parseTextStyle("content_text_style"), @@ -398,13 +392,12 @@ BottomSheetThemeData? parseBottomSheetTheme( shadowColor: HexColor.fromString(theme, j["shadow_color"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), dragHandleColor: HexColor.fromString(theme, j["drag_handle_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, showDragHandle: j["show_drag_handle"] != null ? parseBool(j["show_drag_handle"]) : null, modalBackgroundColor: HexColor.fromString(theme, j["modal_bgcolor"]), - modalElevation: - j["modal_elevation"] != null ? parseDouble(j["modal_elevation"]) : null, + modalElevation: parseDouble(j["modal_elevation"]), clipBehavior: j["clip_behavior"] != null ? Clip.values.firstWhereOrNull( (c) => c.name.toLowerCase() == j["clip_behavior"].toLowerCase()) @@ -421,7 +414,7 @@ CardTheme? parseCardTheme(ThemeData theme, Map? j) { color: HexColor.fromString(theme, j["color"]), shadowColor: HexColor.fromString(theme, j["shadow_color"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, clipBehavior: j["clip_behavior"] != null ? Clip.values.firstWhereOrNull( @@ -444,7 +437,7 @@ ChipThemeData? parseChipTheme(ThemeData theme, Map? j) { backgroundColor: HexColor.fromString(theme, j["bgcolor"]), shadowColor: HexColor.fromString(theme, j["shadow_color"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, padding: j["padding"] != null ? edgeInsetsFromJson(j["padding"]) : null, labelPadding: j["label_padding"] != null @@ -468,8 +461,7 @@ ChipThemeData? parseChipTheme(ThemeData theme, Map? j) { selectedShadowColor: HexColor.fromString(theme, j["selected_shadow_color"]), showCheckmark: j["show_checkmark"] != null ? parseBool(j["show_checkmark"]) : null, - pressElevation: - j["click_elevation"] != null ? parseDouble(j["click_elevation"]) : null, + pressElevation: parseDouble(j["click_elevation"]), ); } @@ -488,17 +480,11 @@ FloatingActionButtonThemeData? parseFloatingActionButtonTheme( focusColor: HexColor.fromString(theme, j["focus_color"]), foregroundColor: HexColor.fromString(theme, j["foreground_color"]), splashColor: HexColor.fromString(theme, j["splash_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, - focusElevation: - j["focus_elevation"] != null ? parseDouble(j["focus_elevation"]) : null, - hoverElevation: - j["hover_elevation"] != null ? parseDouble(j["hover_elevation"]) : null, - highlightElevation: j["highlight_elevation"] != null - ? parseDouble(j["highlight_elevation"]) - : null, - disabledElevation: j["disabled_elevation"] != null - ? parseDouble(j["disabled_elevation"]) - : null, + elevation: parseDouble(j["elevation"]), + focusElevation: parseDouble(j["focus_elevation"]), + hoverElevation: parseDouble(j["hover_elevation"]), + highlightElevation: parseDouble(j["highlight_elevation"]), + disabledElevation: parseDouble(j["disabled_elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, enableFeedback: j["enable_feedback"] != null ? parseBool(j["enable_feedback"]) : null, @@ -506,12 +492,10 @@ FloatingActionButtonThemeData? parseFloatingActionButtonTheme( ? edgeInsetsFromJson(j["extended_padding"]) : null, extendedTextStyle: parseTextStyle("extended_text_style"), - extendedIconLabelSpacing: j["extended_icon_label_spacing"] != null - ? parseDouble(j["extended_icon_label_spacing"]) - : null, + extendedIconLabelSpacing: parseDouble(j["extended_icon_label_spacing"]), mouseCursor: getMaterialStateProperty( j["mouse_cursor"], (jv) => parseMouseCursor(jv)), - iconSize: j["icon_size"] != null ? parseDouble(j["icon_size"]) : null, + iconSize: parseDouble(j["icon_size"]), ); } @@ -526,23 +510,20 @@ NavigationRailThemeData? parseNavigationRailTheme( return theme.navigationRailTheme.copyWith( backgroundColor: HexColor.fromString(theme, j["bgcolor"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), indicatorColor: HexColor.fromString(theme, j["indicator_color"]), unselectedLabelTextStyle: parseTextStyle("unselected_label_text_style"), selectedLabelTextStyle: parseTextStyle("selected_label_text_style"), - minWidth: j["min_width"] != null ? parseDouble(j["min_width"]) : null, + minWidth: parseDouble(j["min_width"]), labelType: j["label_type"] != null ? NavigationRailLabelType.values .firstWhereOrNull((c) => c.name == j["label_type"]) : null, - groupAlignment: - j["group_alignment"] != null ? parseDouble(j["group_alignment"]) : null, + groupAlignment: parseDouble(j["group_alignment"]), indicatorShape: j["indicator_shape"] != null ? outlinedBorderFromJSON(j["indicator_shape"]) : null, - minExtendedWidth: j["min_extended_width"] != null - ? parseDouble(j["min_extended_width"]) - : null, + minExtendedWidth: parseDouble(j["min_extended_width"]), useIndicator: j["use_indicator"] != null ? parseBool(j["use_indicator"]) : null, ); @@ -565,16 +546,12 @@ AppBarTheme? parseAppBarTheme(ThemeData theme, Map? j) { titleTextStyle: parseTextStyle("title_text_style"), toolbarTextStyle: parseTextStyle("toolbar_text_style"), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), centerTitle: j["center_title"] != null ? parseBool(j["center_title"]) : null, - titleSpacing: - j["title_spacing"] != null ? parseDouble(j["title_spacing"]) : null, - scrolledUnderElevation: j["scroll_elevation"] != null - ? parseDouble(j["scroll_elevation"]) - : null, - toolbarHeight: - j["toolbar_height"] != null ? parseDouble(j["toolbar_height"]) : null, + titleSpacing: parseDouble(j["title_spacing"]), + scrolledUnderElevation: parseDouble(j["scroll_elevation"]), + toolbarHeight: parseDouble(j["toolbar_height"]), ); } @@ -588,8 +565,8 @@ BottomAppBarTheme? parseBottomAppBarTheme( color: HexColor.fromString(theme, j["color"]), shadowColor: HexColor.fromString(theme, j["shadow_color"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, - height: j["height"] != null ? parseDouble(j["height"]) : null, + elevation: parseDouble(j["elevation"]), + height: parseDouble(j["height"]), padding: j["padding"] != null ? edgeInsetsFromJson(j["padding"]) : null, //shape: ); @@ -603,8 +580,7 @@ RadioThemeData? parseRadioTheme(ThemeData theme, Map? j) { return theme.radioTheme.copyWith( fillColor: getMaterialStateProperty( j["fill_color"], (jv) => HexColor.fromString(theme, jv as String)), - splashRadius: - j["splash_radius"] != null ? parseDouble(j["splash_radius"]) : null, + splashRadius: parseDouble(j["splash_radius"]), overlayColor: getMaterialStateProperty( j["overlay_color"], (jv) => HexColor.fromString(theme, jv as String)), visualDensity: j["visual_density"] != null @@ -624,8 +600,7 @@ CheckboxThemeData? parseCheckboxTheme( return theme.checkboxTheme.copyWith( fillColor: getMaterialStateProperty( j["fill_color"], (jv) => HexColor.fromString(theme, jv as String)), - splashRadius: - j["splash_radius"] != null ? parseDouble(j["splash_radius"]) : null, + splashRadius: parseDouble(j["splash_radius"]), overlayColor: getMaterialStateProperty( j["overlay_color"], (jv) => HexColor.fromString(theme, jv as String)), visualDensity: j["visual_density"] != null @@ -658,8 +633,8 @@ BadgeThemeData? parseBadgeTheme(ThemeData theme, Map? j) { j["alignment"] != null ? alignmentFromJson(j["alignment"]) : null, textColor: HexColor.fromString(theme, j["text_color"]), offset: j["offset"] != null ? offsetFromJson(j["offset"]) : null, - smallSize: j["small_size"] != null ? parseDouble(j["small_size"]) : null, - largeSize: j["large_size"] != null ? parseDouble(j["large_size"]) : null, + smallSize: parseDouble(j["small_size"]), + largeSize: parseDouble(j["large_size"]), ); } @@ -684,7 +659,7 @@ SwitchThemeData? parseSwitchTheme(ThemeData theme, Map? j) { (jv) => HexColor.fromString(theme, jv as String), null), trackOutlineWidth: getMaterialStateProperty( - j["track_outline_width"], (jv) => parseDouble(jv)), + j["track_outline_width"], (jv) => parseDouble(jv, 0)!), mouseCursor: getMaterialStateProperty( j["mouse_cursor"], (jv) => parseMouseCursor(jv)), ); @@ -697,12 +672,10 @@ DividerThemeData? parseDividerTheme(ThemeData theme, Map? j) { return theme.dividerTheme.copyWith( color: HexColor.fromString(theme, j["color"]), - space: j["space"] != null ? parseDouble(j["space"]) : null, - thickness: j["thickness"] != null ? parseDouble(j["thickness"]) : null, - indent: - j["leading_indent"] != null ? parseDouble(j["leading_indent"]) : null, - endIndent: - j["trailing_indent"] != null ? parseDouble(j["trailing_indent"]) : null, + space: parseDouble(j["space"]), + thickness: parseDouble(j["thickness"]), + indent: parseDouble(j["leading_indent"]), + endIndent: parseDouble(j["trailing_indent"]), ); } @@ -725,14 +698,14 @@ SnackBarThemeData? parseSnackBarTheme( HexColor.fromString(theme, j["disabled_action_text_color"]), disabledActionBackgroundColor: HexColor.fromString(theme, j["disabled_action_bgcolor"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, behavior: j["behavior"] != null ? SnackBarBehavior.values.firstWhereOrNull( (c) => c.name.toLowerCase() == j["behavior"].toLowerCase()) : null, contentTextStyle: parseTextStyle("content_text_style"), - width: j["width"] != null ? parseDouble(j["width"]) : null, + width: parseDouble(j["width"]), insetPadding: j["inset_padding"] != null ? edgeInsetsFromJson(j["inset_padding"]) : null, @@ -742,9 +715,7 @@ SnackBarThemeData? parseSnackBarTheme( : null, showCloseIcon: j["show_close_icon"] != null ? parseBool(j["show_close_icon"]) : null, - actionOverflowThreshold: j["action_overflow_threshold"] != null - ? parseDouble(j["action_overflow_threshold"]) - : null, + actionOverflowThreshold: parseDouble(j["action_overflow_threshold"]), ); } @@ -760,7 +731,7 @@ MaterialBannerThemeData? parseBannerTheme( return theme.bannerTheme.copyWith( backgroundColor: HexColor.fromString(theme, j["bgcolor"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), dividerColor: HexColor.fromString(theme, j["divider_color"]), padding: j["padding"] != null ? edgeInsetsFromJson(j["padding"]) : null, leadingPadding: j["leading_padding"] != null @@ -784,7 +755,7 @@ DatePickerThemeData? parseDatePickerTheme( return theme.datePickerTheme.copyWith( backgroundColor: HexColor.fromString(theme, j["bgcolor"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), dividerColor: HexColor.fromString(theme, j["divider_color"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), shadowColor: HexColor.fromString(theme, j["shadow_color"]), @@ -801,9 +772,7 @@ DatePickerThemeData? parseDatePickerTheme( dayForegroundColor: getMaterialStateProperty( j["day_foreground_color"], (jv) => HexColor.fromString(theme, jv as String)), - rangePickerElevation: j["range_picker_elevation"] != null - ? parseDouble(j["range_picker_elevation"]) - : null, + rangePickerElevation: parseDouble(j["range_picker_elevation"]), todayBackgroundColor: getMaterialStateProperty( j["today_bgcolor"], (jv) => HexColor.fromString(theme, jv as String)), headerForegroundColor: @@ -861,7 +830,7 @@ TimePickerThemeData? parseTimePickerTheme( return theme.timePickerTheme.copyWith( backgroundColor: HexColor.fromString(theme, j["bgcolor"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), padding: j["padding"] != null ? edgeInsetsFromJson(j["padding"]) : null, shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, dayPeriodBorderSide: j["day_period_border_side"] != null @@ -938,20 +907,14 @@ ListTileThemeData? parseListTileTheme( : null, titleTextStyle: parseTextStyle("title_text_style"), subtitleTextStyle: parseTextStyle("subtitle_text_style"), - minVerticalPadding: j["min_vertical_padding"] != null - ? parseDouble(j["min_vertical_padding"]) - : null, + minVerticalPadding: parseDouble(j["min_vertical_padding"]), enableFeedback: j["enable_feedback"] != null ? parseBool(j["enable_feedback"]) : null, dense: j["dense"] != null ? parseBool(j["dense"]) : null, // style: - horizontalTitleGap: j["horizontal_spacing"] != null - ? parseDouble(j["horizontal_spacing"]) - : null, + horizontalTitleGap: parseDouble(j["horizontal_spacing"]), // titleAlignment: j["title_alignment"] != null ? alignmentFromJson(j["title_alignment"]) : null, - minLeadingWidth: j["min_leading_width"] != null - ? parseDouble(j["min_leading_width"]) - : null, + minLeadingWidth: parseDouble(j["min_leading_width"]), leadingAndTrailingTextStyle: parseTextStyle("leading_and_trailing_text_style"), ); @@ -968,7 +931,7 @@ TooltipThemeData? parseTooltipTheme(ThemeData theme, Map? j) { return theme.tooltipTheme.copyWith( enableFeedback: j["enable_feedback"] != null, - height: j["height"] != null ? parseDouble(j["height"]) : null, + height: parseDouble(j["height"]), excludeFromSemantics: j["exclude_from_semantics"] != null ? parseBool(j["exclude_from_semantics"]) : null, @@ -1023,9 +986,7 @@ ProgressIndicatorThemeData? parseProgressIndicatorTheme( circularTrackColor: HexColor.fromString(theme, j["circular_track_color"]), linearTrackColor: HexColor.fromString(theme, j["linear_track_color"]), refreshBackgroundColor: HexColor.fromString(theme, j["refresh_bgcolor"]), - linearMinHeight: j["linear_min_height"] != null - ? parseDouble(j["linear_min_height"]) - : null, + linearMinHeight: parseDouble(j["linear_min_height"]), ); } @@ -1048,8 +1009,8 @@ PopupMenuThemeData? parsePopupMenuTheme( labelTextStyle: getMaterialStateProperty( j["label_text_style"], (jv) => parseTextStyle(jv)), enableFeedback: parseBool(j["enable_feedback"], true), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, - iconSize: j["icon_size"] != null ? parseDouble(j["icon_size"]) : null, + elevation: parseDouble(j["elevation"]), + iconSize: parseDouble(j["icon_size"]), position: j["menu_position"] != null ? PopupMenuPosition.values.firstWhereOrNull( (c) => c.name.toLowerCase() == j["menu_position"].toLowerCase()) @@ -1076,7 +1037,7 @@ SearchBarThemeData? parseSearchBarTheme( shadowColor: getMaterialStateProperty( j["shadow_color"], (jv) => HexColor.fromString(theme, jv as String)), elevation: getMaterialStateProperty( - j["elevation"], (jv) => parseDouble(jv)), + j["elevation"], (jv) => parseDouble(jv, 0)!), backgroundColor: getMaterialStateProperty( j["bgcolor"], (jv) => HexColor.fromString(theme, jv as String)), overlayColor: getMaterialStateProperty( @@ -1110,7 +1071,7 @@ SearchViewThemeData? parseSearchViewTheme( backgroundColor: HexColor.fromString(theme, j["bgcolor"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), dividerColor: HexColor.fromString(theme, j["divider_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), headerHintStyle: parseTextStyle("header_hint_text_style"), headerTextStyle: parseTextStyle("header_text_style"), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, @@ -1134,7 +1095,7 @@ BottomNavigationBarThemeData? parseBottomNavigationBarTheme( backgroundColor: HexColor.fromString(theme, j["bgcolor"]), selectedItemColor: HexColor.fromString(theme, j["selected_item_color"]), unselectedItemColor: HexColor.fromString(theme, j["unselected_item_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), enableFeedback: parseBool(j["enable_feedback"], true), showSelectedLabels: j["show_selected_labels"] != null ? parseBool(j["show_selected_labels"]) @@ -1162,9 +1123,9 @@ NavigationDrawerThemeData? parseNavigationDrawerTheme( shadowColor: HexColor.fromString(theme, j["shadow_color"]), surfaceTintColor: HexColor.fromString(theme, j["surface_tint_color"]), indicatorColor: HexColor.fromString(theme, j["indicator_color"]), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, + elevation: parseDouble(j["elevation"]), //indicatorSize: , - tileHeight: j["tile_height"] != null ? parseDouble(j["tile_height"]) : null, + tileHeight: parseDouble(j["tile_height"]), labelTextStyle: getMaterialStateProperty( j["label_text_style"], (jv) => parseTextStyle(jv)), indicatorShape: j["indicator_shape"] != null @@ -1190,8 +1151,8 @@ NavigationBarThemeData? parseNavigationBarTheme( indicatorColor: HexColor.fromString(theme, j["indicator_color"]), overlayColor: getMaterialStateProperty( j["overlay_color"], (jv) => HexColor.fromString(theme, jv as String)), - elevation: j["elevation"] != null ? parseDouble(j["elevation"]) : null, - height: j["height"] != null ? parseDouble(j["height"]) : null, + elevation: parseDouble(j["elevation"]), + height: parseDouble(j["height"]), labelTextStyle: getMaterialStateProperty( j["label_text_style"], (jv) => parseTextStyle(jv)), indicatorShape: j["indicator_shape"] != null @@ -1224,13 +1185,12 @@ IconThemeData? parseIconTheme(ThemeData theme, Map? j) { return theme.iconTheme.copyWith( color: HexColor.fromString(theme, j["color"]), applyTextScaling: parseBool(j["apply_text_scaling"]), - fill: j["fill"] != null ? parseDouble(j["fill"]) : null, - opacity: j["opacity"] != null ? parseDouble(j["opacity"]) : null, - size: j["size"] != null ? parseDouble(j["size"]) : null, - opticalSize: - j["optical_size"] != null ? parseDouble(j["optical_size"]) : null, - grade: j["grade"] != null ? parseDouble(j["grade"]) : null, - weight: j["weight"] != null ? parseDouble(j["weight"]) : null, + fill: parseDouble(j["fill"]), + opacity: parseDouble(j["opacity"]), + size: parseDouble(j["size"]), + opticalSize: parseDouble(j["optical_size"]), + grade: parseDouble(j["grade"]), + weight: parseDouble(j["weight"]), shadows: j["shadows"] != null ? boxShadowsFromJSON(theme, j["shadows"]) : null, ); diff --git a/packages/flet/lib/src/utils/transforms.dart b/packages/flet/lib/src/utils/transforms.dart index ccfc9b106..632de0521 100644 --- a/packages/flet/lib/src/utils/transforms.dart +++ b/packages/flet/lib/src/utils/transforms.dart @@ -19,7 +19,7 @@ RotationDetails? parseRotate(Control control, String propName) { RotationDetails rotateFromJSON(dynamic json) { if (json is int || json is double) { return RotationDetails( - angle: parseDouble(json), alignment: Alignment.center); + angle: parseDouble(json, 0)!, alignment: Alignment.center); } return RotationDetails.fromJson(json); @@ -82,7 +82,7 @@ class RotationDetails { factory RotationDetails.fromJson(Map json) { return RotationDetails( - angle: parseDouble(json["angle"]), + angle: parseDouble(json["angle"], 0)!, alignment: json["alignment"] != null ? alignmentFromJson(json["alignment"]) : Alignment.center); @@ -103,9 +103,9 @@ class ScaleDetails { factory ScaleDetails.fromJson(Map json) { return ScaleDetails( - scale: json["scale"] != null ? parseDouble(json["scale"]) : null, - scaleX: json["scale_x"] != null ? parseDouble(json["scale_x"]) : null, - scaleY: json["scale_y"] != null ? parseDouble(json["scale_y"]) : null, + scale: parseDouble(json["scale"]), + scaleX: parseDouble(json["scale_x"]), + scaleY: parseDouble(json["scale_y"]), alignment: json["alignment"] != null ? alignmentFromJson(json["alignment"]) : Alignment.center); @@ -120,10 +120,11 @@ class OffsetDetails { factory OffsetDetails.fromJson(dynamic json) { if (json is List && json.length > 1) { - return OffsetDetails(x: parseDouble(json[0]), y: parseDouble(json[1])); + return OffsetDetails( + x: parseDouble(json[0], 0)!, y: parseDouble(json[1], 0)!); } else { return OffsetDetails( - x: parseDouble(json["x"]), y: parseDouble(json["y"])); + x: parseDouble(json["x"], 0)!, y: parseDouble(json["y"], 0)!); } } } diff --git a/packages/flet_video/lib/src/utils/video.dart b/packages/flet_video/lib/src/utils/video.dart index 1b531943b..7fbecd628 100644 --- a/packages/flet_video/lib/src/utils/video.dart +++ b/packages/flet_video/lib/src/utils/video.dart @@ -76,9 +76,7 @@ Map subtitleConfigurationFromJSON( fontWeight: FontWeight.normal, backgroundColor: Color(0xaa000000)), visible: json["visible"] != null ? parseBool(json["visible"]) : true, - textScaleFactor: json["text_scale_factor"] != null - ? parseDouble(json["text_scale_factor"]) - : null, + textScaleFactor: parseDouble(json["text_scale_factor"]), textAlign: json["text_align"] != null ? parseTextAlign(json["text_align"], TextAlign.center)! : TextAlign.center, From 9ec0103587c955cbde37164cd67fa4e87a2226ae Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Sat, 11 May 2024 01:01:48 +0200 Subject: [PATCH 3/5] refactor parseBool --- packages/flet/lib/src/controls/canvas.dart | 4 +- packages/flet/lib/src/utils/numbers.dart | 2 +- .../flet/lib/src/utils/overlay_style.dart | 8 +--- packages/flet/lib/src/utils/text.dart | 4 +- packages/flet/lib/src/utils/textfield.dart | 2 +- packages/flet/lib/src/utils/theme.dart | 48 +++++++------------ packages/flet_video/lib/src/utils/video.dart | 2 +- 7 files changed, 25 insertions(+), 45 deletions(-) diff --git a/packages/flet/lib/src/controls/canvas.dart b/packages/flet/lib/src/controls/canvas.dart index 8704a4d33..f15890a07 100644 --- a/packages/flet/lib/src/controls/canvas.dart +++ b/packages/flet/lib/src/controls/canvas.dart @@ -362,8 +362,8 @@ class FletCustomPainter extends CustomPainter { Offset(parseDouble(elem["x"], 0)!, parseDouble(elem["y"], 0)!), radius: Radius.circular(parseDouble(elem["radius"], 0)!), rotation: parseDouble(elem["rotation"], 0)!, - largeArc: parseBool(elem["large_arc"]), - clockwise: parseBool(elem["clockwise"])); + largeArc: parseBool(elem["large_arc"], false)!, + clockwise: parseBool(elem["clockwise"], true)!); } else if (type == "oval") { path.addOval(Rect.fromLTWH( parseDouble(elem["x"], 0)!, diff --git a/packages/flet/lib/src/utils/numbers.dart b/packages/flet/lib/src/utils/numbers.dart index 5f15d5ed7..269df0b5b 100644 --- a/packages/flet/lib/src/utils/numbers.dart +++ b/packages/flet/lib/src/utils/numbers.dart @@ -18,7 +18,7 @@ int? parseInt(dynamic v, [int? defValue]) { } } -bool parseBool(dynamic v, [bool defValue = false]) { +bool? parseBool(dynamic v, [bool? defValue]) { if (v is bool) { return v; } else if (v == null) { diff --git a/packages/flet/lib/src/utils/overlay_style.dart b/packages/flet/lib/src/utils/overlay_style.dart index 650c5ec53..0b87190ce 100644 --- a/packages/flet/lib/src/utils/overlay_style.dart +++ b/packages/flet/lib/src/utils/overlay_style.dart @@ -27,13 +27,9 @@ SystemUiOverlayStyle overlayStyleFromJson( theme, json["system_navigation_bar_divider_color"] ?? "") : null, systemStatusBarContrastEnforced: - json["enforce_system_status_bar_contrast"] != null - ? parseBool(json["enforce_system_status_bar_contrast"]) - : null, + parseBool(json["enforce_system_status_bar_contrast"]), systemNavigationBarContrastEnforced: - json["enforce_system_navigation_bar_contrast"] != null - ? parseBool(json["enforce_system_navigation_bar_contrast"]) - : null, + parseBool(json["enforce_system_navigation_bar_contrast"]), systemNavigationBarIconBrightness: parseBrightness( json["system_navigation_bar_icon_brightness"], invertedBrightness), statusBarBrightness: diff --git a/packages/flet/lib/src/utils/text.dart b/packages/flet/lib/src/utils/text.dart index de69f67af..e00559233 100644 --- a/packages/flet/lib/src/utils/text.dart +++ b/packages/flet/lib/src/utils/text.dart @@ -181,9 +181,7 @@ TextStyle textStyleFromJson(ThemeData theme, Map json) { return TextStyle( fontSize: json["size"] != null ? parseDouble(json["size"]) : null, fontWeight: fontWeight != null ? getFontWeight(fontWeight) : null, - fontStyle: (json["italic"] != null) - ? (parseBool(json["italic"]) ? FontStyle.italic : null) - : null, + fontStyle: parseBool(json["italic"], false)! ? FontStyle.italic : null, fontFamily: json["font_family"], fontVariations: variations, height: json["height"] != null ? parseDouble(json["height"]) : null, diff --git a/packages/flet/lib/src/utils/textfield.dart b/packages/flet/lib/src/utils/textfield.dart index 9e7e003d2..94714df67 100644 --- a/packages/flet/lib/src/utils/textfield.dart +++ b/packages/flet/lib/src/utils/textfield.dart @@ -23,7 +23,7 @@ FilteringTextInputFormatter inputFilterFromJSON(dynamic json) { String? replacementString = ""; if (json != null) { - allow = parseBool(json["allow"], true); + allow = parseBool(json["allow"], true)!; regexString = json["regex_string"]?.toString(); replacementString = json["replacement_string"]?.toString(); } diff --git a/packages/flet/lib/src/utils/theme.dart b/packages/flet/lib/src/utils/theme.dart index ea8073d82..36b1ee668 100644 --- a/packages/flet/lib/src/utils/theme.dart +++ b/packages/flet/lib/src/utils/theme.dart @@ -273,7 +273,7 @@ ScrollbarThemeData? parseScrollBarTheme( crossAxisMargin: parseDouble(j["cross_axis_margin"]), mainAxisMargin: parseDouble(j["main_axis_margin"]), minThumbLength: parseDouble(j["min_thumb_length"]), - interactive: j["interactive"] != null ? parseBool(j["interactive"]) : null, + interactive: parseBool(j["interactive"]), ); } @@ -292,7 +292,7 @@ TabBarTheme? parseTabBarTheme(ThemeData theme, Map? j) { labelColor: HexColor.fromString(theme, j["label_color"]), unselectedLabelColor: HexColor.fromString(theme, j["unselected_label_color"]), - indicatorSize: parseBool(j["indicator_tab_size"], false) + indicatorSize: parseBool(j["indicator_tab_size"], false)! ? TabBarIndicatorSize.tab : TabBarIndicatorSize.label, indicator: j["indicator_border_radius"] != null || @@ -394,8 +394,7 @@ BottomSheetThemeData? parseBottomSheetTheme( dragHandleColor: HexColor.fromString(theme, j["drag_handle_color"]), elevation: parseDouble(j["elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, - showDragHandle: - j["show_drag_handle"] != null ? parseBool(j["show_drag_handle"]) : null, + showDragHandle: parseBool(j["show_drag_handle"]), modalBackgroundColor: HexColor.fromString(theme, j["modal_bgcolor"]), modalElevation: parseDouble(j["modal_elevation"]), clipBehavior: j["clip_behavior"] != null @@ -459,8 +458,7 @@ ChipThemeData? parseChipTheme(ThemeData theme, Map? j) { (b) => b.name.toLowerCase() == j["brightness"].toLowerCase()) : null, selectedShadowColor: HexColor.fromString(theme, j["selected_shadow_color"]), - showCheckmark: - j["show_checkmark"] != null ? parseBool(j["show_checkmark"]) : null, + showCheckmark: parseBool(j["show_checkmark"]), pressElevation: parseDouble(j["click_elevation"]), ); } @@ -486,8 +484,7 @@ FloatingActionButtonThemeData? parseFloatingActionButtonTheme( highlightElevation: parseDouble(j["highlight_elevation"]), disabledElevation: parseDouble(j["disabled_elevation"]), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, - enableFeedback: - j["enable_feedback"] != null ? parseBool(j["enable_feedback"]) : null, + enableFeedback: parseBool(j["enable_feedback"]), extendedPadding: j["extended_padding"] != null ? edgeInsetsFromJson(j["extended_padding"]) : null, @@ -524,8 +521,7 @@ NavigationRailThemeData? parseNavigationRailTheme( ? outlinedBorderFromJSON(j["indicator_shape"]) : null, minExtendedWidth: parseDouble(j["min_extended_width"]), - useIndicator: - j["use_indicator"] != null ? parseBool(j["use_indicator"]) : null, + useIndicator: parseBool(j["use_indicator"]), ); } @@ -547,8 +543,7 @@ AppBarTheme? parseAppBarTheme(ThemeData theme, Map? j) { toolbarTextStyle: parseTextStyle("toolbar_text_style"), shape: j["shape"] != null ? outlinedBorderFromJSON(j["shape"]) : null, elevation: parseDouble(j["elevation"]), - centerTitle: - j["center_title"] != null ? parseBool(j["center_title"]) : null, + centerTitle: parseBool(j["center_title"]), titleSpacing: parseDouble(j["title_spacing"]), scrolledUnderElevation: parseDouble(j["scroll_elevation"]), toolbarHeight: parseDouble(j["toolbar_height"]), @@ -713,8 +708,7 @@ SnackBarThemeData? parseSnackBarTheme( ? DismissDirection.values.firstWhereOrNull( (c) => c.name.toLowerCase() == j["dismiss_direction"].toLowerCase()) : null, - showCloseIcon: - j["show_close_icon"] != null ? parseBool(j["show_close_icon"]) : null, + showCloseIcon: parseBool(j["show_close_icon"]), actionOverflowThreshold: parseDouble(j["action_overflow_threshold"]), ); } @@ -900,17 +894,15 @@ ListTileThemeData? parseListTileTheme( : null, selectedColor: HexColor.fromString(theme, j["selected_color"]), selectedTileColor: HexColor.fromString(theme, j["selected_tile_color"]), - isThreeLine: - j["is_three_line"] != null ? parseBool(j["is_three_line"]) : null, + isThreeLine: parseBool(j["is_three_line"]), visualDensity: j["visual_density"] != null ? parseVisualDensity(j["visual_density"]) : null, titleTextStyle: parseTextStyle("title_text_style"), subtitleTextStyle: parseTextStyle("subtitle_text_style"), minVerticalPadding: parseDouble(j["min_vertical_padding"]), - enableFeedback: - j["enable_feedback"] != null ? parseBool(j["enable_feedback"]) : null, - dense: j["dense"] != null ? parseBool(j["dense"]) : null, + enableFeedback: parseBool(j["enable_feedback"]), + dense: parseBool(j["dense"]), // style: horizontalTitleGap: parseDouble(j["horizontal_spacing"]), // titleAlignment: j["title_alignment"] != null ? alignmentFromJson(j["title_alignment"]) : null, @@ -930,11 +922,9 @@ TooltipThemeData? parseTooltipTheme(ThemeData theme, Map? j) { } return theme.tooltipTheme.copyWith( - enableFeedback: j["enable_feedback"] != null, + enableFeedback: parseBool(j["enable_feedback"]), height: parseDouble(j["height"]), - excludeFromSemantics: j["exclude_from_semantics"] != null - ? parseBool(j["exclude_from_semantics"]) - : null, + excludeFromSemantics: parseBool(j["exclude_from_semantics"]), textStyle: parseTextStyle("text_style"), ); } @@ -1008,7 +998,7 @@ PopupMenuThemeData? parsePopupMenuTheme( textStyle: parseTextStyle("text_style"), labelTextStyle: getMaterialStateProperty( j["label_text_style"], (jv) => parseTextStyle(jv)), - enableFeedback: parseBool(j["enable_feedback"], true), + enableFeedback: parseBool(j["enable_feedback"]), elevation: parseDouble(j["elevation"]), iconSize: parseDouble(j["icon_size"]), position: j["menu_position"] != null @@ -1096,13 +1086,9 @@ BottomNavigationBarThemeData? parseBottomNavigationBarTheme( selectedItemColor: HexColor.fromString(theme, j["selected_item_color"]), unselectedItemColor: HexColor.fromString(theme, j["unselected_item_color"]), elevation: parseDouble(j["elevation"]), - enableFeedback: parseBool(j["enable_feedback"], true), - showSelectedLabels: j["show_selected_labels"] != null - ? parseBool(j["show_selected_labels"]) - : null, - showUnselectedLabels: j["show_unselected_labels"] != null - ? parseBool(j["show_unselected_labels"]) - : null, + enableFeedback: parseBool(j["enable_feedback"]), + showSelectedLabels: parseBool(j["show_selected_labels"]), + showUnselectedLabels: parseBool(j["show_unselected_labels"]), selectedLabelStyle: parseTextStyle("selected_label_text_style"), unselectedLabelStyle: parseTextStyle("unselected_label_text_style"), ); diff --git a/packages/flet_video/lib/src/utils/video.dart b/packages/flet_video/lib/src/utils/video.dart index 7fbecd628..da7ec44b3 100644 --- a/packages/flet_video/lib/src/utils/video.dart +++ b/packages/flet_video/lib/src/utils/video.dart @@ -75,7 +75,7 @@ Map subtitleConfigurationFromJSON( color: Color(0xffffffff), fontWeight: FontWeight.normal, backgroundColor: Color(0xaa000000)), - visible: json["visible"] != null ? parseBool(json["visible"]) : true, + visible: parseBool(json["visible"], true)!, textScaleFactor: parseDouble(json["text_scale_factor"]), textAlign: json["text_align"] != null ? parseTextAlign(json["text_align"], TextAlign.center)! From 1c8b1c57ad4d0f944c3563d824be29e1fe97f736 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Fri, 24 May 2024 19:48:44 +0200 Subject: [PATCH 4/5] Fix errors --- packages/flet/lib/src/utils/colors.dart | 6 ++--- packages/flet_map/lib/src/polyline_layer.dart | 1 + packages/flet_map/lib/src/utils/map.dart | 23 ++++++++++--------- packages/flet_video/lib/src/utils/video.dart | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/flet/lib/src/utils/colors.dart b/packages/flet/lib/src/utils/colors.dart index 5fe98e06d..ca5a993dd 100644 --- a/packages/flet/lib/src/utils/colors.dart +++ b/packages/flet/lib/src/utils/colors.dart @@ -137,7 +137,7 @@ Map _materialAccentColors = { // https://stackoverflow.com/questions/50081213/how-do-i-use-hexadecimal-color-strings-in-flutter extension HexColor on Color { - static Color? fromString(ThemeData? theme, [String? colorString = ""]) { + static Color? fromString(ThemeData? theme, [String? colorString]) { if (colorString == null || colorString.isEmpty) { return null; } @@ -251,5 +251,5 @@ MaterialStateProperty? parseMaterialStateColor( j1, (jv) => HexColor.fromString(theme, jv as String), null); } -Color? parseColorFromJson(ThemeData? theme, [String? colorString = ""]) => - colorString != null ? HexColor.fromString(theme, colorString ?? "") : null; +Color? parseColorFromJson(ThemeData? theme, [String? colorString]) => + colorString != null ? HexColor.fromString(theme, colorString) : null; diff --git a/packages/flet_map/lib/src/polyline_layer.dart b/packages/flet_map/lib/src/polyline_layer.dart index 36604be36..50adc173e 100644 --- a/packages/flet_map/lib/src/polyline_layer.dart +++ b/packages/flet_map/lib/src/polyline_layer.dart @@ -55,6 +55,7 @@ class PolylineLayerControl extends StatelessWidget with FletStoreMixin { colorsStop: colorsStop != null ? (jsonDecode(colorsStop) as List) .map((e) => parseDouble(e)) + .whereNotNull() .toList() : null, gradientColors: gradientColors != null diff --git a/packages/flet_map/lib/src/utils/map.dart b/packages/flet_map/lib/src/utils/map.dart index e618d894d..34c16eaf8 100644 --- a/packages/flet_map/lib/src/utils/map.dart +++ b/packages/flet_map/lib/src/utils/map.dart @@ -15,7 +15,8 @@ LatLng? parseLatLng(Control control, String propName, [LatLng? defValue]) { } LatLng latLngFromJson(Map json) { - return LatLng(parseDouble(json['latitude']), parseDouble(json['longitude'])); + return LatLng( + parseDouble(json['latitude'], 0)!, parseDouble(json['longitude'], 0)!); } LatLngBounds? parseLatLngBounds(Control control, String propName, @@ -50,19 +51,19 @@ InteractionOptions? parseInteractionOptions(Control control, String propName) { InteractionOptions interactionOptionsFromJSON(dynamic json) { return InteractionOptions( enableMultiFingerGestureRace: - parseBool(json["enable_multi_finger_gesture_race"], false), - enableScrollWheel: parseBool(json["enable_scroll_wheel"], false), - pinchMoveThreshold: parseDouble(json["pinch_move_threshold"], 40.0), - scrollWheelVelocity: parseDouble(json["scroll_wheel_velocity"], 0.005), - pinchZoomThreshold: parseDouble(json["pinch_zoom_threshold"], 0.5), - rotationThreshold: parseDouble(json["rotation_threshold"], 20.0), - flags: parseInt(json["flags"], InteractiveFlag.all), + parseBool(json["enable_multi_finger_gesture_race"], false)!, + enableScrollWheel: parseBool(json["enable_scroll_wheel"], false)!, + pinchMoveThreshold: parseDouble(json["pinch_move_threshold"], 40.0)!, + scrollWheelVelocity: parseDouble(json["scroll_wheel_velocity"], 0.005)!, + pinchZoomThreshold: parseDouble(json["pinch_zoom_threshold"], 0.5)!, + rotationThreshold: parseDouble(json["rotation_threshold"], 20.0)!, + flags: parseInt(json["flags"], InteractiveFlag.all)!, rotationWinGestures: - parseInt(json["rotation_win_gestures"], MultiFingerGesture.rotate), + parseInt(json["rotation_win_gestures"], MultiFingerGesture.rotate)!, pinchMoveWinGestures: parseInt(json["pinch_move_win_gestures"], - MultiFingerGesture.pinchZoom | MultiFingerGesture.pinchMove), + MultiFingerGesture.pinchZoom | MultiFingerGesture.pinchMove)!, pinchZoomWinGestures: parseInt(json["pinch_zoom_win_gestures"], - MultiFingerGesture.pinchZoom | MultiFingerGesture.pinchMove)); + MultiFingerGesture.pinchZoom | MultiFingerGesture.pinchMove)!); } EvictErrorTileStrategy? parseEvictErrorTileStrategy(String? strategy, diff --git a/packages/flet_video/lib/src/utils/video.dart b/packages/flet_video/lib/src/utils/video.dart index 7c662b8b3..77deb6179 100644 --- a/packages/flet_video/lib/src/utils/video.dart +++ b/packages/flet_video/lib/src/utils/video.dart @@ -119,6 +119,6 @@ VideoControllerConfiguration? controllerConfigurationFromJSON(dynamic json) { vo: json["output_driver"], hwdec: json["hardware_decoding_api"], enableHardwareAcceleration: - parseBool(json["enable_hardware_acceleration"], true), + parseBool(json["enable_hardware_acceleration"], true)!, ); } From 99ebba761a3a653d6b364f5f501890955e5fd78e Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Fri, 24 May 2024 23:34:27 +0200 Subject: [PATCH 5/5] Fix error in transforms.dart --- packages/flet/lib/src/utils/transforms.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flet/lib/src/utils/transforms.dart b/packages/flet/lib/src/utils/transforms.dart index ba2b0cb49..ee1554c36 100644 --- a/packages/flet/lib/src/utils/transforms.dart +++ b/packages/flet/lib/src/utils/transforms.dart @@ -107,7 +107,7 @@ class ScaleDetails { scale: parseDouble(json["scale"]), scaleX: parseDouble(json["scale_x"]), scaleY: parseDouble(json["scale_y"]), - alignment: alignment: alignmentFromJson(json["alignment"], Alignment.center)!); + alignment: alignmentFromJson(json["alignment"], Alignment.center)!); } }