|
@@ -0,0 +1,105 @@
|
|
|
+import 'package:fis_lib_report/converts/date_to_string_converter.dart';
|
|
|
+import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
|
|
|
+import 'package:fis_lib_report/converts/text_size_converter.dart';
|
|
|
+import 'package:fis_lib_report/converts/vertical_alignment.dart';
|
|
|
+import 'package:fis_lib_report/report/dateTimeElement.dart';
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+
|
|
|
+class RDateTime extends StatefulWidget {
|
|
|
+ final DateTimeElement dateTimeElement;
|
|
|
+ RDateTime(this.dateTimeElement);
|
|
|
+ @override
|
|
|
+ State<StatefulWidget> createState() {
|
|
|
+ return _RDateTimeState(dateTimeElement);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class _RDateTimeState extends State<RDateTime> {
|
|
|
+ final DateTimeElement dateTimeElement;
|
|
|
+ _RDateTimeState(this.dateTimeElement);
|
|
|
+
|
|
|
+ String _dateTime = '';
|
|
|
+ double _fontSize = 15.0;
|
|
|
+ double _width = 0;
|
|
|
+ TextStyle _style = TextStyle();
|
|
|
+ Color _fontColor = Colors.black;
|
|
|
+ Color _backgroundColor = const Color.fromARGB(255, 255, 255, 255);
|
|
|
+ EdgeInsets _margin = EdgeInsets.all(0);
|
|
|
+
|
|
|
+ @override
|
|
|
+ initState() {
|
|
|
+ final currentDateTime = DateTime.now();
|
|
|
+ final timestamp = currentDateTime.millisecondsSinceEpoch;
|
|
|
+ _dateTime = currentDateTime.toString().substring(0, 10);
|
|
|
+ final format = dateTimeElement.dateTimeFormat;
|
|
|
+ if (format != null) {
|
|
|
+ if (format == 'yyyy-MM-dd') {
|
|
|
+ _dateTime = DateToStringConverter.dateAndTimeToString(
|
|
|
+ timestamp, {"y-m": "-", "m-d": "-"});
|
|
|
+ } else if (format == 'yyyy年M月d日 HH:mm') {
|
|
|
+ _dateTime = DateToStringConverter.dateAndTimeToString(
|
|
|
+ timestamp, {"y-m": "年", "m-d": "月", "d-h": "日", "h-m": ":"});
|
|
|
+ } else if (format == 'yyyy-MM-dd HH:mm') {
|
|
|
+ _dateTime = DateToStringConverter.dateAndTimeToString(
|
|
|
+ timestamp, {"y-m": "-", "m-d": "-", "h-m": ":"});
|
|
|
+ } else if (format == "yyyy年M月d日") {
|
|
|
+ _dateTime = DateToStringConverter.dateAndTimeToString(
|
|
|
+ timestamp, {"y-m": "年", "m-d": "月", "d-h": "日"});
|
|
|
+ } else if (format == 'yyyy.MM.dd') {
|
|
|
+ _dateTime = DateToStringConverter.dateAndTimeToString(
|
|
|
+ timestamp, {"y-m": ".", "m-d": "."});
|
|
|
+ } else if (format == 'yyyy/MM/dd') {
|
|
|
+ _dateTime = DateToStringConverter.dateAndTimeToString(
|
|
|
+ timestamp, {"y-m": "/", "m-d": "/"});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _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) {
|
|
|
+ return Container(
|
|
|
+ margin: _margin,
|
|
|
+ alignment: AlignmentConvert.verticalLayoutConvert(
|
|
|
+ dateTimeElement.verticalAlignment!),
|
|
|
+ width: _width,
|
|
|
+ child: Text(
|
|
|
+ _dateTime,
|
|
|
+ style: _style,
|
|
|
+ textAlign: AlignmentConvert.horizontalAlignmentConvert(
|
|
|
+ dateTimeElement.horizontalAlignment),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|