|
@@ -1,4 +1,11 @@
|
|
|
+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());
|
|
@@ -32,15 +39,6 @@ class MyApp extends StatelessWidget {
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
const MyHomePage({Key? key, required this.title}) : super(key: key);
|
|
|
|
|
|
- // This widget is the home page of your application. It is stateful, meaning
|
|
|
- // that it has a State object (defined below) that contains fields that affect
|
|
|
- // how it looks.
|
|
|
-
|
|
|
- // This class is the configuration for the state. It holds the values (in this
|
|
|
- // case the title) provided by the parent (in this case the App widget) and
|
|
|
- // used by the build method of the State. Fields in a Widget subclass are
|
|
|
- // always marked "final".
|
|
|
-
|
|
|
final String title;
|
|
|
|
|
|
@override
|
|
@@ -48,68 +46,92 @@ class MyHomePage extends StatefulWidget {
|
|
|
}
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
- int _counter = 0;
|
|
|
+ ReportTemplateDocument _reportTemplate = ReportTemplateDocument();
|
|
|
+ double _height = 0;
|
|
|
+ double _width = 0;
|
|
|
+ List<IBlockElement> _blocks = [];
|
|
|
+ List<IBlockElement> _header = [];
|
|
|
+ List<IBlockElement> _footer = [];
|
|
|
+ double _baseFontSize = 9.0;
|
|
|
+ double _footerDistance = 34.0;
|
|
|
+ double _footerHeight = 0;
|
|
|
+ EdgeInsetsGeometry _padding = const EdgeInsets.all(56.83);
|
|
|
+ @override
|
|
|
+ initState() {
|
|
|
+ _intitTemplate();
|
|
|
|
|
|
- void _incrementCounter() {
|
|
|
- setState(() {
|
|
|
- // This call to setState tells the Flutter framework that something has
|
|
|
- // changed in this State, which causes it to rerun the build method below
|
|
|
- // so that the display can reflect the updated values. If we changed
|
|
|
- // _counter without calling setState(), then the build method would not be
|
|
|
- // called again, and so nothing would appear to happen.
|
|
|
- _counter++;
|
|
|
- });
|
|
|
+ super.initState();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- // This method is rerun every time setState is called, for instance as done
|
|
|
- // by the _incrementCounter method above.
|
|
|
- //
|
|
|
- // The Flutter framework has been optimized to make rerunning build methods
|
|
|
- // fast, so that you can just rebuild anything that needs updating rather
|
|
|
- // than having to individually change instances of widgets.
|
|
|
return Scaffold(
|
|
|
- appBar: AppBar(
|
|
|
- // Here we take the value from the MyHomePage object that was created by
|
|
|
- // the App.build method, and use it to set our appbar title.
|
|
|
- title: Text(widget.title),
|
|
|
- ),
|
|
|
- body: Center(
|
|
|
- // Center is a layout widget. It takes a single child and positions it
|
|
|
- // in the middle of the parent.
|
|
|
+ body: Container(
|
|
|
+ decoration: _buildDecoration(),
|
|
|
+ padding: _padding,
|
|
|
+ height: _height * 2,
|
|
|
+ width: _width * 1.5,
|
|
|
child: Column(
|
|
|
- // Column is also a layout widget. It takes a list of children and
|
|
|
- // arranges them vertically. By default, it sizes itself to fit its
|
|
|
- // children horizontally, and tries to be as tall as its parent.
|
|
|
- //
|
|
|
- // Invoke "debug painting" (press "p" in the console, choose the
|
|
|
- // "Toggle Debug Paint" action from the Flutter Inspector in Android
|
|
|
- // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
|
|
|
- // to see the wireframe for each widget.
|
|
|
- //
|
|
|
- // Column has various properties to control how it sizes itself and
|
|
|
- // how it positions its children. Here we use mainAxisAlignment to
|
|
|
- // center the children vertically; the main axis here is the vertical
|
|
|
- // axis because Columns are vertical (the cross axis would be
|
|
|
- // horizontal).
|
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
|
|
- children: <Widget>[
|
|
|
- const Text(
|
|
|
- 'You have pushed the button this many times:',
|
|
|
- ),
|
|
|
- Text(
|
|
|
- '$_counter',
|
|
|
- style: Theme.of(context).textTheme.headline4,
|
|
|
- ),
|
|
|
+ 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);
|
|
|
+ }),
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
- floatingActionButton: FloatingActionButton(
|
|
|
- onPressed: _incrementCounter,
|
|
|
- tooltip: 'Increment',
|
|
|
- child: const Icon(Icons.add),
|
|
|
- ), // This trailing comma makes auto-formatting nicer for build methods.
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|