Files
biz_xfj_cloud/lib/common/utils/json/json_tool.dart
T

99 lines
2.9 KiB
Dart

import 'package:pj_supermarket_cloud/common/index.dart';
abstract class JsonTool {
static bool stringToBoolean(String? value) {
if (value == null) return false;
return value == '1';
}
static String? booleanToString(bool? value) {
if (value == null) return null;
return value ? '1' : '0';
}
static int? stringToInt(String? value) {
if (value == null) return null;
return int.tryParse(value);
}
static String? intToString(int? value) {
if (value == null) return null;
return value.toString();
}
static String? anyToString(dynamic value) {
if (value == null) return null;
return value.toString();
}
static Map<String, dynamic>? anyToMap(dynamic value) {
if (value == null) return null;
return dynamic as Map<String, dynamic>?;
}
static OrderType? stringToOrderType(String? value) {
final byCode = OrderType.values.fromCode(value);
if (byCode != null) return byCode;
if (value == null) return null;
final name = value.contains('.') ? value.split('.').last : value;
return OrderType.values.byName(name);
}
static String? orderTypeToString(OrderType? value) {
if (value == null) return null;
return value.code;
}
static OrderPayType? stringToOrderPayType(String? value) {
final byCode = OrderPayType.values.fromCode(value);
if (byCode != null) return byCode;
if (value == null) return null;
final name = value.contains('.') ? value.split('.').last : value;
return OrderPayType.values.byName(name);
}
static String? orderPayTypeToString(OrderPayType? value) {
if (value == null) return null;
return value.code;
}
static WalletActType? stringToWalletActType(String? value) {
final byCode = WalletActType.values.fromCode(value);
if (byCode != null) return byCode;
if (value == null) return null;
final name = value.contains('.') ? value.split('.').last : value;
return WalletActType.values.byName(name);
}
static String? walletActTypeToString(WalletActType? value) {
if (value == null) return null;
return value.code;
}
static DiscountsType? stringToDiscountsType(String? value) {
final byCode = DiscountsType.values.fromCode(value);
if (byCode != null) return byCode;
if (value == null) return null;
final name = value.contains('.') ? value.split('.').last : value;
return DiscountsType.values.byName(name);
}
static String? discountsTypeToString(DiscountsType? value) {
if (value == null) return null;
return value.code;
}
static ProductHourType? stringToProductHourType(String? value) {
final byCode = ProductHourType.values.fromCode(value);
if (byCode != null) return byCode;
if (value == null) return null;
final name = value.contains('.') ? value.split('.').last : value;
return ProductHourType.values.byName(name);
}
static String? productHourTypeToString(ProductHourType? value) {
if (value == null) return null;
return value.code;
}
}