main.dart 5.9 KB

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