rt_table.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'dart:math';
  2. import 'package:fis_lib_report/pages/rt_cell.dart';
  3. import 'package:fis_lib_report/report/cellPostion.dart';
  4. import 'package:fis_lib_report/report/interfaces/block_element.dart';
  5. import 'package:fis_lib_report/report/interfaces/cell.dart';
  6. import 'package:fis_lib_report/report/interfaces/rt_table.dart';
  7. import 'package:fis_lib_report/report/rt_Cell.dart';
  8. import 'package:fis_lib_report/report/rt_table.dart';
  9. import 'package:flutter/cupertino.dart';
  10. class RTTablePage extends StatefulWidget {
  11. const RTTablePage({required this.element, Key? key}) : super(key: key);
  12. final RTTable element;
  13. @override
  14. State<StatefulWidget> createState() {
  15. return _RTTableState();
  16. }
  17. }
  18. class _RTTableState extends State<RTTablePage> {
  19. Map<CellPostion, ICell>? _cells;
  20. List<ICell>? _values = [];
  21. int? _column;
  22. int? _row;
  23. @override
  24. initState() {
  25. super.initState();
  26. _cells = widget.element.cells ?? {};
  27. List<CellPostion> cellPostions = _cells!.keys.toList();
  28. cellPostions.sort(((a, b) => (b.column!).compareTo(a.column!)));
  29. // +1 为列数
  30. _column = cellPostions.first.column! + 1;
  31. _values = _cells!.values.toList();
  32. _row = widget.element.rowDefinitions!.length;
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return SizedBox(
  37. height: _row! * 40,
  38. child: (_column == null || _column == 0 || _values!.isEmpty)
  39. ? const SizedBox()
  40. : GridView.builder(
  41. controller: ScrollController(),
  42. shrinkWrap: true,
  43. itemCount: _values!.length,
  44. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  45. crossAxisCount: _column!,
  46. childAspectRatio: _column == 3 ? 6.6 : 24,
  47. ),
  48. itemBuilder: (BuildContext context, int index) {
  49. final cell = _values![index];
  50. RTCell c = cell as RTCell;
  51. return RTCellPage(
  52. cell: c,
  53. );
  54. },
  55. ),
  56. );
  57. }
  58. }