main.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import 'dart:convert';
  2. import 'package:fis_lib_report/pages/block_element_page.dart';
  3. import 'package:fis_lib_report/report/interfaces/block_element.dart';
  4. import 'package:fis_lib_report/report/report_template_document.dart';
  5. import 'package:fis_lib_report/report/rt_thickness.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter/services.dart';
  8. void main() {
  9. runApp(const MyApp());
  10. }
  11. class MyApp extends StatelessWidget {
  12. const MyApp({Key? key}) : super(key: key);
  13. // This widget is the root of your application.
  14. @override
  15. Widget build(BuildContext context) {
  16. return MaterialApp(
  17. title: 'Flutter Demo',
  18. theme: ThemeData(
  19. // This is the theme of your application.
  20. //
  21. // Try running your application with "flutter run". You'll see the
  22. // application has a blue toolbar. Then, without quitting the app, try
  23. // changing the primarySwatch below to Colors.green and then invoke
  24. // "hot reload" (press "r" in the console where you ran "flutter run",
  25. // or simply save your changes to "hot reload" in a Flutter IDE).
  26. // Notice that the counter didn't reset back to zero; the application
  27. // is not restarted.
  28. primarySwatch: Colors.blue,
  29. ),
  30. home: const MyHomePage(title: 'Flutter Demo Home Page'),
  31. );
  32. }
  33. }
  34. class MyHomePage extends StatefulWidget {
  35. const MyHomePage({Key? key, required this.title}) : super(key: key);
  36. final String title;
  37. @override
  38. State<MyHomePage> createState() => _MyHomePageState();
  39. }
  40. class _MyHomePageState extends State<MyHomePage> {
  41. ReportTemplateDocument _reportTemplate = ReportTemplateDocument();
  42. double _height = 0;
  43. double _width = 0;
  44. List<IBlockElement> _blocks = [];
  45. List<IBlockElement> _header = [];
  46. List<IBlockElement> _footer = [];
  47. double _baseFontSize = 9.0;
  48. double _footerDistance = 34.0;
  49. double _footerHeight = 0;
  50. EdgeInsetsGeometry _padding = const EdgeInsets.all(56.83);
  51. @override
  52. initState() {
  53. _intitTemplate();
  54. super.initState();
  55. }
  56. @override
  57. Widget build(BuildContext context) {
  58. return Scaffold(
  59. body: Container(
  60. decoration: _buildDecoration(),
  61. padding: _padding,
  62. height: _height * 2,
  63. width: _width * 1.5,
  64. child: Column(
  65. mainAxisSize: MainAxisSize.min,
  66. mainAxisAlignment: MainAxisAlignment.start,
  67. children: [
  68. ..._header.map((head) {
  69. return BlockElementPage(element: head);
  70. }),
  71. ..._blocks.map((block) {
  72. return BlockElementPage(element: block);
  73. }),
  74. const SizedBox(height: 10),
  75. ..._footer.map((footer) {
  76. return BlockElementPage(element: footer);
  77. }),
  78. ],
  79. ),
  80. ),
  81. );
  82. }
  83. BoxDecoration _buildDecoration() {
  84. return BoxDecoration(
  85. border: Border.all(
  86. width: 0.5,
  87. color: const Color.fromARGB(255, 83, 83, 83),
  88. ),
  89. color: Colors.grey[200]);
  90. }
  91. void _intitTemplate() {
  92. rootBundle.loadString('assets/default.json').then((jsonStr) {
  93. final reportMap = jsonDecode(jsonStr);
  94. final template = ReportTemplateDocument.fromJson(reportMap);
  95. _reportTemplate = template;
  96. setState(() {
  97. _initPage();
  98. });
  99. });
  100. }
  101. void _initPage() {
  102. try {
  103. _height = _reportTemplate.pageSize!.height ?? 841;
  104. _width = _reportTemplate.pageSize!.width ?? 595;
  105. _baseFontSize = _reportTemplate.baseFontSize ?? 14;
  106. _footerDistance = _reportTemplate.footerDistance ?? 0;
  107. _footerHeight = _reportTemplate.footerHeight ?? 0;
  108. final pagePadding =
  109. _reportTemplate.pagePadding ?? RTThickness.uniform(56);
  110. _padding = EdgeInsets.only(
  111. left: pagePadding.left ?? 0,
  112. right: pagePadding.right ?? 0,
  113. top: pagePadding.top ?? 0,
  114. bottom: pagePadding.bottom ?? 0,
  115. );
  116. _footer = _reportTemplate.footer ?? [];
  117. _blocks = _reportTemplate.blocks ?? [];
  118. _header = _reportTemplate.header ?? [];
  119. } catch (e) {
  120. _height = 841.8897637795275;
  121. _width = 595.275590551181;
  122. }
  123. }
  124. }