import 'dart:convert'; 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'; import 'package:fis_lib_report/report/rt_thickness.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( // This is the theme of your application. // // Try running your application with "flutter run". You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // "hot reload" (press "r" in the console where you ran "flutter run", // or simply save your changes to "hot reload" in a Flutter IDE). // Notice that the counter didn't reset back to zero; the application // is not restarted. primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { ReportTemplateDocument _reportTemplate = ReportTemplateDocument(); double _height = 0; double _width = 0; List _blocks = []; List _header = []; List _footer = []; double _baseFontSize = 9.0; double _footerDistance = 34.0; double _footerHeight = 0; EdgeInsetsGeometry _padding = const EdgeInsets.all(56.83); @override initState() { _intitTemplate(); super.initState(); } @override Widget build(BuildContext context) { return Scaffold( body: Container( decoration: _buildDecoration(), padding: _padding, height: _height * 2, width: _width * 1.5, child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, children: [ ..._header.map((head) { return BlockElementPage(element: head); }), ..._blocks.map((block) { return BlockElementPage(element: block); }), const SizedBox(height: 10), ..._footer.map((footer) { return BlockElementPage(element: footer); }), ], ), ), ); } BoxDecoration _buildDecoration() { return BoxDecoration( border: Border.all( width: 0.5, color: const Color.fromARGB(255, 83, 83, 83), ), color: Colors.grey[200]); } void _intitTemplate() { rootBundle.loadString('assets/default.json').then((jsonStr) { final reportMap = jsonDecode(jsonStr); final template = ReportTemplateDocument.fromJson(reportMap); _reportTemplate = template; setState(() { _initPage(); }); }); } void _initPage() { try { _height = _reportTemplate.pageSize!.height ?? 841; _width = _reportTemplate.pageSize!.width ?? 595; _baseFontSize = _reportTemplate.baseFontSize ?? 14; _footerDistance = _reportTemplate.footerDistance ?? 0; _footerHeight = _reportTemplate.footerHeight ?? 0; final pagePadding = _reportTemplate.pagePadding ?? RTThickness.uniform(56); _padding = EdgeInsets.only( left: pagePadding.left ?? 0, right: pagePadding.right ?? 0, top: pagePadding.top ?? 0, bottom: pagePadding.bottom ?? 0, ); _footer = _reportTemplate.footer ?? []; _blocks = _reportTemplate.blocks ?? []; _header = _reportTemplate.header ?? []; } catch (e) { _height = 841.8897637795275; _width = 595.275590551181; } } }