|
@@ -18,7 +18,6 @@ class RDateTime extends StatefulWidget {
|
|
|
}
|
|
|
|
|
|
class _RDateTimeState extends State<RDateTime> {
|
|
|
- late final DateTimeElement dateTimeElement;
|
|
|
DateTime selectedDate = DateTime.now();
|
|
|
|
|
|
_RDateTimeState();
|
|
@@ -34,50 +33,13 @@ class _RDateTimeState extends State<RDateTime> {
|
|
|
|
|
|
@override
|
|
|
initState() {
|
|
|
- dateTimeElement = widget.dateTimeElement;
|
|
|
- //_dateTimeInfo =
|
|
|
- // ReportInfo.instance.getElementInfo(dateTimeElement) as DateTimeInfo;
|
|
|
-
|
|
|
- final format = dateTimeElement.dateTimeFormat;
|
|
|
- if (format != null) {
|
|
|
- _dateTimeConvert(
|
|
|
- format, ReportInfo.instance.reportDate!.millisecondsSinceEpoch);
|
|
|
- }
|
|
|
-
|
|
|
- _fontSize = dateTimeElement.fontSize ?? 15.0;
|
|
|
- //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
|
|
|
- final fontStyles = dateTimeElement.fontStyles;
|
|
|
- final fontColor = dateTimeElement.fontColor;
|
|
|
- if (fontColor != null) {
|
|
|
- _fontColor = Color.fromARGB(
|
|
|
- fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
|
|
|
- }
|
|
|
- final backgroundColor = dateTimeElement.background;
|
|
|
- if (backgroundColor != null) {
|
|
|
- _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
|
|
|
- backgroundColor.g!, backgroundColor.b!);
|
|
|
- }
|
|
|
- final margin = dateTimeElement.margin;
|
|
|
- if (margin != null) {
|
|
|
- _margin = EdgeInsets.only(
|
|
|
- top: margin.top ?? 0,
|
|
|
- bottom: margin.bottom ?? 0,
|
|
|
- left: margin.left ?? 0,
|
|
|
- right: margin.right ?? 0);
|
|
|
- }
|
|
|
- _style = TextStyle(
|
|
|
- fontSize: PtToPxConverter.ptToPx(_fontSize),
|
|
|
- color: _fontColor,
|
|
|
- backgroundColor: _backgroundColor,
|
|
|
- );
|
|
|
-
|
|
|
- _width = PtToPxConverter.ptToPx(
|
|
|
- TextSizeConvert.getTextSize(_dateTime, _style).width);
|
|
|
super.initState();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
+ final dateTimeElement = widget.dateTimeElement;
|
|
|
+ _initDatas();
|
|
|
return Container(
|
|
|
margin: _margin,
|
|
|
decoration: BoxDecoration(
|
|
@@ -127,7 +89,7 @@ class _RDateTimeState extends State<RDateTime> {
|
|
|
lastDate: DateTime(2025),
|
|
|
);
|
|
|
if (picked != null && picked != selectedDate) {
|
|
|
- final format = dateTimeElement.dateTimeFormat;
|
|
|
+ final format = widget.dateTimeElement.dateTimeFormat;
|
|
|
setState(() {
|
|
|
selectedDate = picked;
|
|
|
_dateTimeConvert(format!, selectedDate.millisecondsSinceEpoch);
|
|
@@ -135,6 +97,46 @@ class _RDateTimeState extends State<RDateTime> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void _initDatas() {
|
|
|
+ final dateTimeElement = widget.dateTimeElement;
|
|
|
+
|
|
|
+ final format = dateTimeElement.dateTimeFormat;
|
|
|
+ if (format != null) {
|
|
|
+ _dateTimeConvert(
|
|
|
+ format, ReportInfo.instance.reportDate!.millisecondsSinceEpoch);
|
|
|
+ }
|
|
|
+
|
|
|
+ _fontSize = dateTimeElement.fontSize ?? 15.0;
|
|
|
+ //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
|
|
|
+ final fontStyles = dateTimeElement.fontStyles;
|
|
|
+ final fontColor = dateTimeElement.fontColor;
|
|
|
+ if (fontColor != null) {
|
|
|
+ _fontColor = Color.fromARGB(
|
|
|
+ fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
|
|
|
+ }
|
|
|
+ final backgroundColor = dateTimeElement.background;
|
|
|
+ if (backgroundColor != null) {
|
|
|
+ _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
|
|
|
+ backgroundColor.g!, backgroundColor.b!);
|
|
|
+ }
|
|
|
+ final margin = dateTimeElement.margin;
|
|
|
+ if (margin != null) {
|
|
|
+ _margin = EdgeInsets.only(
|
|
|
+ top: margin.top ?? 0,
|
|
|
+ bottom: margin.bottom ?? 0,
|
|
|
+ left: margin.left ?? 0,
|
|
|
+ right: margin.right ?? 0);
|
|
|
+ }
|
|
|
+ _style = TextStyle(
|
|
|
+ fontSize: PtToPxConverter.ptToPx(_fontSize),
|
|
|
+ color: _fontColor,
|
|
|
+ backgroundColor: _backgroundColor,
|
|
|
+ );
|
|
|
+
|
|
|
+ _width = PtToPxConverter.ptToPx(
|
|
|
+ TextSizeConvert.getTextSize(_dateTime, _style).width);
|
|
|
+ }
|
|
|
+
|
|
|
void _dateTimeConvert(String format, int timestamp) {
|
|
|
if (format == 'yyyy-MM-dd') {
|
|
|
_dateTime = DateToStringConverter.dateAndTimeToString(
|