Browse Source

网格布局优化,根据Json获取宽高

loki.wu 2 years ago
parent
commit
d090c1f68e

+ 10 - 3
lib/main.dart

@@ -1,5 +1,6 @@
 import 'dart:convert';
 
+import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
 import 'package:fis_lib_report/pages/block_element_page.dart';
 import 'package:fis_lib_report/report/interfaces/block_element.dart';
 import 'package:fis_lib_report/report/report_template_document.dart';
@@ -56,10 +57,16 @@ class _MyHomePageState extends State<MyHomePage> {
   double _footerDistance = 34.0;
   double _footerHeight = 0;
   EdgeInsetsGeometry _padding = const EdgeInsets.all(56.83);
+
   @override
   initState() {
     _intitTemplate();
-
+    final padding = _reportTemplate.pagePadding!;
+    _padding = EdgeInsets.only(
+        top: PtToPxConverter.ptToPx(padding.top!),
+        bottom: PtToPxConverter.ptToPx(padding.bottom!),
+        right: PtToPxConverter.ptToPx(padding.right!),
+        left: PtToPxConverter.ptToPx(padding.left!));
     super.initState();
   }
 
@@ -69,8 +76,8 @@ class _MyHomePageState extends State<MyHomePage> {
       body: Container(
         decoration: _buildDecoration(),
         padding: _padding,
-        height: _height * 2,
-        width: _width * 1.5,
+        height: PtToPxConverter.ptToPx(_height),
+        width: PtToPxConverter.ptToPx(_width),
         child: Column(
           mainAxisSize: MainAxisSize.min,
           mainAxisAlignment: MainAxisAlignment.start,

+ 3 - 8
lib/pages/block_element_page.dart

@@ -41,8 +41,8 @@ class _BlockElementState extends State<BlockElementPage> {
     } else if (_type != null && _type!.name == ElementType.imageList!.name) {
       final inputImageList = widget.element as InputImageList;
       return Container(
-        height: 200,
-        width: 700,
+        height: 180,
+        width: 580,
         alignment: Alignment.center,
         decoration: TestBoxDecoration.buildDecoration(),
         child: const Text('图片选择框'),
@@ -50,12 +50,7 @@ class _BlockElementState extends State<BlockElementPage> {
     }
     return Container(
       height: 20,
-      decoration: BoxDecoration(
-          border: Border.all(
-            width: 0.5,
-            color: const Color.fromARGB(255, 83, 83, 83),
-          ),
-          color: Colors.grey[200]),
+      decoration: TestBoxDecoration.buildDecoration(),
     );
   }
 }

+ 1 - 1
lib/pages/components/RDateTime.dart

@@ -1,7 +1,7 @@
 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/converts/alignment_convert.dart';
 import 'package:fis_lib_report/report/dateTimeElement.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';

+ 10 - 11
lib/pages/components/input_text.dart

@@ -1,11 +1,8 @@
 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/converts/alignment_convert.dart';
 import 'package:fis_lib_report/report/inputText.dart';
-import 'package:fis_lib_report/report/interfaces/position_layout.dart';
-import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
-import 'package:flutter/rendering.dart';
 
 class RInputText extends StatefulWidget {
   final InputText inputText;
@@ -31,6 +28,7 @@ class _RInputTextState extends State<RInputText> {
   Color _backgroundColor = const Color.fromARGB(255, 255, 255, 255);
   int? _lineLength = 1;
   TextStyle? _textStyle;
+
   @override
   initState() {
     final fontColor = inputText.fontColor;
@@ -68,7 +66,7 @@ class _RInputTextState extends State<RInputText> {
     );
     return Container(
       width: PtToPxConverter.ptToPx(_lineWidth!),
-      height: _textWrap! ? _height! * 4 : (_height! + 5),
+      height: _textWrap! ? _height! * 4 : (_height! + 2),
       padding: EdgeInsets.only(top: _textWrap! ? 10 : 5, right: 5, left: 5),
       decoration: BoxDecoration(
         border: Border.all(
@@ -77,11 +75,10 @@ class _RInputTextState extends State<RInputText> {
         ),
         color: _backgroundColor,
       ),
-      alignment: Alignment.center,
       child: TextField(
         focusNode: _focusNode,
         readOnly: inputText.isReadOnly ?? false,
-        cursorHeight: _height!,
+        // cursorHeight: _height!,
         decoration: InputDecoration.collapsed(
           hintText: '',
           hintStyle: TextStyle(
@@ -89,12 +86,14 @@ class _RInputTextState extends State<RInputText> {
             color: Colors.black54,
           ),
           fillColor: _backgroundColor,
-          filled: true,
+          filled: false,
+        ).copyWith(
+          contentPadding: EdgeInsets.symmetric(vertical: _textWrap! ? 2.5 : 4),
         ),
         textAlignVertical: AlignmentConvert.verticalAlignmentConvert(
             inputText.verticalAlignment),
+        minLines: 1,
         maxLines: _textWrap! ? 6 : 1,
-        minLines: _textWrap! ? 6 : 1,
         controller: _controller,
         textAlign: TextAlign.start,
         style: _textStyle,
@@ -113,7 +112,7 @@ class _RInputTextState extends State<RInputText> {
     if (inputText.tag!.name == 'HospitalName') {
       if (_lineWidth! < width) {
         setState(() {
-          if (width < 500) {
+          if (width < 480) {
             _lineWidth = width;
           }
         });
@@ -126,7 +125,7 @@ class _RInputTextState extends State<RInputText> {
               .width >
           inputText.lineWidth!) {
         setState(() {
-          if (width < 500) {
+          if (width < 480) {
             _lineWidth = width;
           }
         });

+ 53 - 0
lib/pages/components/line.dart

@@ -0,0 +1,53 @@
+import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
+import 'package:fis_lib_report/report/line.dart';
+import 'package:fis_lib_report/report/rt_thickness.dart';
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+
+class RLine extends StatefulWidget {
+  final Line line;
+
+  RLine(this.line);
+
+  @override
+  State<StatefulWidget> createState() {
+    return _LineState(line);
+  }
+}
+
+class _LineState extends State<RLine> {
+  final Line line;
+  _LineState(this.line);
+
+  @override
+  initState() {
+    ///TODO(Loki):设置虚线or实线
+    final borderStyle = line.borderStyle;
+
+    super.initState();
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    final stroke = line.stroke!;
+    final a = stroke.a!;
+    final r = stroke.r!;
+    final g = stroke.g!;
+    final b = stroke.b!;
+    final margin = line.margin ?? RTThickness.uniform(0);
+    return Container(
+      height: 10, //TODO(Loki):这里的Height在Json中没有
+      margin: EdgeInsets.only(
+          top: margin.top!,
+          bottom: margin.bottom!,
+          right: margin.left!,
+          left: margin.left!),
+      width: PtToPxConverter.ptToPx(line.width),
+      child: Divider(
+        height: line.thickness,
+        thickness: line.thickness,
+        color: Color.fromARGB(a, r, g, b),
+      ),
+    );
+  }
+}

+ 6 - 12
lib/pages/paragraph_page.dart

@@ -1,5 +1,6 @@
 import 'package:fis_lib_report/pages/components/RDateTime.dart';
 import 'package:fis_lib_report/pages/components/input_text.dart';
+import 'package:fis_lib_report/pages/components/line.dart';
 import 'package:fis_lib_report/pages/components/multi_select.dart';
 import 'package:fis_lib_report/pages/components/static_Text.dart';
 import 'package:fis_lib_report/pages/helpler.dart';
@@ -8,6 +9,7 @@ import 'package:fis_lib_report/report/element_type.dart';
 import 'package:fis_lib_report/report/inputText.dart';
 import 'package:fis_lib_report/report/interfaces/element.dart';
 import 'package:fis_lib_report/report/interfaces/position_layout.dart';
+import 'package:fis_lib_report/report/line.dart';
 import 'package:fis_lib_report/report/multiSelected.dart';
 import 'package:fis_lib_report/report/paragraph.dart';
 import 'package:fis_lib_report/report/singleSelected.dart';
@@ -68,7 +70,7 @@ class _ParagraphState extends State<ParagraphPage> {
             if (values != null && values.isNotEmpty) {
               return SizedBox(
                 width: 104,
-                height: 30,
+                height: 28,
                 child: DropdownButton(
                   onChanged: (Object? value) {},
                   items: values.map<DropdownMenuItem<String>>((String value) {
@@ -81,16 +83,8 @@ class _ParagraphState extends State<ParagraphPage> {
               );
             }
           } else if (element.elementType!.name == ElementType.line!.name) {
-            return Container(
-              margin: const EdgeInsets.symmetric(vertical: 10),
-              padding: const EdgeInsets.symmetric(horizontal: 0),
-              width: 760,
-              child: const Divider(
-                height: 1,
-                thickness: 1,
-                color: Colors.black,
-              ),
-            );
+            Line line = element as Line;
+            return RLine(line);
           } else if (element.elementType!.name == ElementType.dateTime!.name) {
             final dateTime = element as DateTimeElement;
             return RDateTime(dateTime);
@@ -101,7 +95,7 @@ class _ParagraphState extends State<ParagraphPage> {
             List<String>? values = multiSelected.items;
             return SizedBox(
               width: 120,
-              height: 30,
+              height: 28,
               child: TextField(
                 cursorWidth: 0,
                 mouseCursor: SystemMouseCursors.click,

+ 55 - 19
lib/pages/rt_table.dart

@@ -1,5 +1,6 @@
 import 'dart:math';
 
+import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
 import 'package:fis_lib_report/pages/rt_cell.dart';
 import 'package:fis_lib_report/report/cellPostion.dart';
 import 'package:fis_lib_report/report/interfaces/block_element.dart';
@@ -25,6 +26,7 @@ class _RTTableState extends State<RTTablePage> {
   List<ICell>? _values = [];
   int? _column;
   int? _row;
+  double _width = 0;
 
   @override
   initState() {
@@ -34,31 +36,65 @@ class _RTTableState extends State<RTTablePage> {
     cellPostions.sort(((a, b) => (b.column!).compareTo(a.column!)));
     // +1 为列数
     _column = cellPostions.first.column! + 1;
+
+    for (int i = 0; i < _column! - 1; i++) {
+      _width += widget.element.columnDefinitions![i].width!;
+    }
     _values = _cells!.values.toList();
-    _row = widget.element.rowDefinitions!.length;
+    _row = widget.element.rowDefinitions!.length + 1;
   }
 
   @override
   Widget build(BuildContext context) {
-    return SizedBox(
-      child: (_column == null || _column == 0 || _values!.isEmpty)
-          ? const SizedBox()
-          : GridView.builder(
-              controller: ScrollController(),
-              shrinkWrap: true,
-              itemCount: _values!.length,
-              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
-                crossAxisCount: _column!,
-                childAspectRatio: _column == 3 ? 6.6 : 18.5,
-              ),
-              itemBuilder: (BuildContext context, int index) {
-                final cell = _values![index];
-                RTCell c = cell as RTCell;
-                return RTCellPage(
-                  cell: c,
-                );
-              },
+    List<Widget> widgets = [];
+    for (int i = 0; i < _row! - 1; i++) {
+      final children = _cells!.keys.where((element) => element.row! == i);
+      List<Widget> childwidgets = [];
+      children.forEach((cellPostion) {
+        double width =
+            widget.element.columnDefinitions![cellPostion.column!].width ?? 0.0;
+        if (cellPostion.columnSpan! > 1) {
+          for (int i = 1; i < cellPostion.columnSpan!; i++) {
+            width += widget.element.columnDefinitions![cellPostion.column! + i]
+                    .width ??
+                0.0;
+          }
+        }
+        double height =
+            widget.element.rowDefinitions![cellPostion.row!].height ?? 0.0;
+        if (cellPostion.rowSpan! > 1) {
+          for (int i = 1; i < cellPostion.rowSpan!; i++) {
+            height +=
+                widget.element.rowDefinitions![cellPostion.row! + i].height ??
+                    0.0;
+          }
+        }
+        print('height' + height.toString() + '   width:' + width.toString());
+        final cell = _cells![cellPostion];
+        RTCell c = cell as RTCell;
+        childwidgets.add(
+          SizedBox(
+            width: PtToPxConverter.ptToPx(width),
+            height: PtToPxConverter.ptToPx(height),
+            child: RTCellPage(
+              cell: c,
             ),
+          ),
+        );
+      });
+      final row = SizedBox(
+        child: Row(
+          children: childwidgets,
+        ),
+      );
+
+      widgets.add(Container(
+        child: row,
+      ));
+    }
+    return SizedBox(
+      child:
+          Column(mainAxisAlignment: MainAxisAlignment.start, children: widgets),
     );
   }
 }

+ 1 - 0
lib/report/line.dart

@@ -18,6 +18,7 @@ class Line extends Shape implements ILine {
 
   Line.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
     stroke = RTColor.fromJson(json['Stroke']);
+    width = json['Width'];
     thickness = json['Thickness'];
     borderStyle = RTBorderStyle.values
         .firstWhere((element) => element.name == json['BorderStyle']);