main.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import 'dart:convert';
  2. import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
  3. import 'package:fis_lib_report/pages/block_element_page.dart';
  4. import 'package:fis_lib_report/pages/components/vid_image.dart';
  5. import 'package:fis_lib_report/report/interfaces/block_element.dart';
  6. import 'package:fis_lib_report/report/report_template_document.dart';
  7. import 'package:fis_lib_report/report/rt_thickness.dart';
  8. import 'package:fis_lib_report/report_info/report_info.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter/services.dart';
  11. void main() {
  12. runApp(const MyApp());
  13. }
  14. class MyApp extends StatelessWidget {
  15. const MyApp({Key? key}) : super(key: key);
  16. // This widget is the root of your application.
  17. @override
  18. Widget build(BuildContext context) {
  19. return MaterialApp(
  20. title: 'Flutter Demo',
  21. theme: ThemeData(
  22. // This is the theme of your application.
  23. //
  24. // Try running your application with "flutter run". You'll see the
  25. // application has a blue toolbar. Then, without quitting the app, try
  26. // changing the primarySwatch below to Colors.green and then invoke
  27. // "hot reload" (press "r" in the console where you ran "flutter run",
  28. // or simply save your changes to "hot reload" in a Flutter IDE).
  29. // Notice that the counter didn't reset back to zero; the application
  30. // is not restarted.
  31. primarySwatch: Colors.blue,
  32. ),
  33. home: const MyHomePage(title: 'Flutter Demo Home Page'),
  34. );
  35. }
  36. }
  37. class MyHomePage extends StatefulWidget {
  38. const MyHomePage({Key? key, required this.title}) : super(key: key);
  39. final String title;
  40. @override
  41. State<MyHomePage> createState() => _MyHomePageState();
  42. }
  43. class _MyHomePageState extends State<MyHomePage> {
  44. ReportTemplateDocument _reportTemplate = ReportTemplateDocument();
  45. double _height = 0;
  46. double _width = 0;
  47. List<IBlockElement> _blocks = [];
  48. List<IBlockElement> _header = [];
  49. List<IBlockElement> _footer = [];
  50. double _baseFontSize = 9.0;
  51. double _footerDistance = 34.0;
  52. double _footerHeight = 0;
  53. EdgeInsetsGeometry _padding = EdgeInsets.all(PtToPxConverter.ptToPx(56.83));
  54. @override
  55. initState() {
  56. _intitTemplate();
  57. super.initState();
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. final demoImags = [
  62. 'http://192.168.6.117:9001/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/compress%E8%83%8E%E5%84%BF2.VID',
  63. 'http://192.168.6.117:9001/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/compress%E8%83%8E%E5%84%BF1.VID',
  64. 'http://192.168.6.117:9001/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/compress%E4%B9%B3%E8%85%BA%E5%8D%95%E5%B8%A7%E5%9B%BE.VID',
  65. 'http://192.168.6.117:9001/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/compress%E4%B9%B3%E8%85%BAVideo.VID',
  66. 'http://192.168.6.117:9001/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/compress%E9%A2%88%E5%8A%A8%E8%84%89%E6%A8%AA%E5%88%87.VID'
  67. ];
  68. return Scaffold(
  69. body: Row(
  70. children: [
  71. Container(
  72. decoration: _buildDecoration(),
  73. padding: _padding,
  74. alignment: Alignment.center,
  75. height: _height,
  76. width: _width,
  77. child: Column(
  78. mainAxisAlignment: MainAxisAlignment.center,
  79. crossAxisAlignment: CrossAxisAlignment.center,
  80. mainAxisSize: MainAxisSize.min,
  81. children: [
  82. ..._header.map((head) {
  83. return BlockElementPage(element: head);
  84. }),
  85. ..._blocks.map((block) {
  86. return BlockElementPage(element: block);
  87. }),
  88. const SizedBox(height: 10),
  89. ..._footer.map((footer) {
  90. return BlockElementPage(element: footer);
  91. }),
  92. ],
  93. ),
  94. ),
  95. const SizedBox(width: 20),
  96. Container(
  97. decoration: _buildDecoration(),
  98. padding: _padding,
  99. alignment: Alignment.center,
  100. height: _height,
  101. width: _width,
  102. child: Wrap(
  103. children: [
  104. ...demoImags.map((element) {
  105. return MouseRegion(
  106. cursor: SystemMouseCursors.click,
  107. child: GestureDetector(
  108. onTap: () {},
  109. child: Container(
  110. margin: const EdgeInsets.all(15),
  111. child: VidImageView.network(element),
  112. ),
  113. ),
  114. );
  115. })
  116. ],
  117. )),
  118. ],
  119. ),
  120. );
  121. }
  122. BoxDecoration _buildDecoration() {
  123. return BoxDecoration(
  124. border: Border.all(
  125. width: 0.5,
  126. color: const Color.fromARGB(255, 83, 83, 83),
  127. ),
  128. color: Colors.white);
  129. }
  130. void _intitTemplate() {
  131. rootBundle.loadString('assets/default.json').then((jsonStr) {
  132. final reportMap = jsonDecode(jsonStr);
  133. final template = ReportTemplateDocument.fromJson(reportMap);
  134. _reportTemplate = template;
  135. ReportInfo.instance.init(_reportTemplate);
  136. setState(() {
  137. _initPage();
  138. });
  139. });
  140. }
  141. void _initPage() {
  142. try {
  143. _height = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.height);
  144. _width = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.width);
  145. _baseFontSize = PtToPxConverter.ptToPx(_reportTemplate.baseFontSize);
  146. _footerDistance = PtToPxConverter.ptToPx(_reportTemplate.footerDistance);
  147. _footerHeight = PtToPxConverter.ptToPx(_reportTemplate.footerHeight);
  148. final pagePadding =
  149. _reportTemplate.pagePadding ?? RTThickness.uniform(56);
  150. _padding = EdgeInsets.only(
  151. left: PtToPxConverter.ptToPx(pagePadding.left),
  152. right: PtToPxConverter.ptToPx(pagePadding.right),
  153. top: PtToPxConverter.ptToPx(pagePadding.top),
  154. bottom: PtToPxConverter.ptToPx(pagePadding.bottom),
  155. );
  156. _footer = _reportTemplate.footer ?? [];
  157. _blocks = _reportTemplate.blocks ?? [];
  158. _header = _reportTemplate.header ?? [];
  159. } catch (e) {
  160. _height = 841.8897637795275;
  161. _width = 595.275590551181;
  162. }
  163. }
  164. }