From 5b21a43a1eb9a517400c06ec1cd85a41f144350d Mon Sep 17 00:00:00 2001 From: wutsi Date: Sun, 25 Dec 2022 13:57:32 -0500 Subject: [PATCH] support null weidget/ --- CHANGELOG.md | 5 +++++ lib/src/money.dart | 8 +++++++- lib/src/parser.dart | 8 ++++++-- lib/src/text.dart | 20 +------------------- lib/src/widget.dart | 18 ++++++++++++++++++ pubspec.yaml | 2 +- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77bf4bb..276f4e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## [0.1.192] 2022-12-25 + +- CHANGE: Add alignment to MoneyText +- CHANGE: Use `SDUINull` for unsupported widgets + ## [0.1.190] 2022-12-24 - ADD: Add chart component diff --git a/lib/src/money.dart b/lib/src/money.dart index 557e1ba..9d9c97a 100644 --- a/lib/src/money.dart +++ b/lib/src/money.dart @@ -21,6 +21,7 @@ class SDUIMoneyText extends SDUIWidget { double? valueFontSize; double? currencyFontSize; bool? bold; + String? alignment; @override SDUIWidget fromJson(Map? json) { @@ -31,6 +32,7 @@ class SDUIMoneyText extends SDUIWidget { valueFontSize = json?['valueFontSize']; currencyFontSize = json?['currencyFontSize']; bold = json?['bold']; + alignment = json?['alignment']; return super.fromJson(json); } @@ -44,6 +46,7 @@ class SDUIMoneyText extends SDUIWidget { valueFontSize: valueFontSize ?? 50, currencyFontSize: currencyFontSize ?? 12, bold: bold, + textAlign: toTextAlign(alignment), ); } @@ -56,6 +59,7 @@ class MoneyText extends StatelessWidget { final double currencyFontSize; final Color? color; final bool? bold; + final TextAlign? textAlign; const MoneyText( {Key? key, @@ -65,7 +69,8 @@ class MoneyText extends StatelessWidget { this.valueFontSize = 50, this.currencyFontSize = 12, this.color, - this.bold = false}) + this.bold = false, + this.textAlign}) : super(key: key); @override @@ -94,6 +99,7 @@ class MoneyText extends StatelessWidget { ), ]), key: key, + textAlign: textAlign, ); } diff --git a/lib/src/parser.dart b/lib/src/parser.dart index a259d10..b16e010 100644 --- a/lib/src/parser.dart +++ b/lib/src/parser.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:logger/logger.dart'; import 'action.dart'; import 'appbar.dart'; @@ -32,8 +33,10 @@ import 'icon_button.dart'; import 'image.dart'; import 'input.dart'; import 'list_view.dart'; +import 'logger.dart'; import 'money.dart'; import 'noop.dart'; +import 'null.dart'; import 'page_view.dart'; import 'photo_view.dart'; import 'pin_with_keyboard.dart'; @@ -56,7 +59,7 @@ import 'wrap.dart'; //-- Core ------------------------------------ /// Parser that convert JSON to flutter [Widget] class SDUIParser { - // static final Logger _logger = LoggerFactory.create('SDUIParser'); + static final Logger _logger = LoggerFactory.create('SDUIParser'); static final SDUIParser _singleton = SDUIParser._internal(); SDUIParser._internal(); @@ -259,7 +262,8 @@ class SDUIParser { default: widget = SDUIWidgetRegistry.getInstance().create(type); if (widget == null) { - throw Exception("Unsupported node: ${json["type"]}"); + _logger.w(">>>> Unsupported node: ${json["type"]}"); + widget = SDUINull(); } } diff --git a/lib/src/text.dart b/lib/src/text.dart index 71ead11..af49287 100644 --- a/lib/src/text.dart +++ b/lib/src/text.dart @@ -29,7 +29,7 @@ class SDUIText extends SDUIWidget { caption ?? '', overflow: _toTextOverflow(), style: _toTextStyle(), - textAlign: _toTextAlign(), + textAlign: toTextAlign(alignment), maxLines: maxLines, key: id == null ? null : Key(id!), ); @@ -69,24 +69,6 @@ class SDUIText extends SDUIWidget { fontStyle: italic == true ? FontStyle.italic : FontStyle.normal, decoration: _toTextDecoration()); - TextAlign? _toTextAlign() { - switch (alignment?.toLowerCase()) { - case 'left': - return TextAlign.left; - case 'right': - return TextAlign.right; - case 'center': - return TextAlign.center; - case 'justify': - return TextAlign.justify; - case 'end': - return TextAlign.end; - case 'start': - return TextAlign.start; - } - return null; - } - TextDecoration? _toTextDecoration() { switch (decoration?.toLowerCase()) { case 'strikethrough': diff --git a/lib/src/widget.dart b/lib/src/widget.dart index 2c01464..ec9ec57 100644 --- a/lib/src/widget.dart +++ b/lib/src/widget.dart @@ -57,6 +57,24 @@ abstract class SDUIWidget { return Color(int.parse('FF$hexCode', radix: 16)); } + TextAlign? toTextAlign(String? alignment) { + switch (alignment?.toLowerCase()) { + case 'left': + return TextAlign.left; + case 'right': + return TextAlign.right; + case 'center': + return TextAlign.center; + case 'justify': + return TextAlign.justify; + case 'end': + return TextAlign.end; + case 'start': + return TextAlign.start; + } + return null; + } + IconData? toIconData(String? code) { if (code == null) { return null; diff --git a/pubspec.yaml b/pubspec.yaml index c314c8f..ec15b6c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ description: SDUI make it easy to implement Server Driven UI pattern on flutter. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.1.190 +version: 0.1.192 environment: sdk: ">=2.12.0 <3.0.0"