Browse Source

新增报告OnClose事件,用于关闭时清除UI

loki.wu 2 years ago
parent
commit
f3e44215e9
3 changed files with 36 additions and 8 deletions
  1. 5 0
      lib/main.dart
  2. 29 8
      lib/report_edit.dart
  3. 2 0
      lib/report_info/report_info.dart

+ 5 - 0
lib/main.dart

@@ -136,6 +136,11 @@ class _MyHomePageState extends State<MyHomePage> {
                 ReportInfo.instance
                     .reload('pet', DateTime.now(), _petStr, onSelect);
               }),
+          MaterialButton(
+              child: Text('onClose'),
+              onPressed: () {
+                ReportInfo.instance.onClose.emit(this, null);
+              }),
         ],
       ),
     );

+ 29 - 8
lib/report_edit.dart

@@ -44,14 +44,7 @@ class _ReportEditPageState extends State<ReportEditPage> {
   @override
   initState() {
     _intitTemplate();
-    ReportInfo.instance.onReload.addListener((sender, e) {
-      _header.clear();
-      _blocks.clear();
-      _footer.clear();
-      widget.onSelect.dispose();
-      _intitTemplate(args: e);
-      ReportInfo.instance.onReloadFinsh.emit(this, '');
-    });
+    _initListentener();
     super.initState();
   }
 
@@ -60,6 +53,7 @@ class _ReportEditPageState extends State<ReportEditPage> {
     if (widget.jsonStr.isEmpty) {
       return const SizedBox();
     }
+
     final pagePadding = _reportTemplate.pagePadding ?? RTThickness.uniform(56);
     return Center(
       child: Container(
@@ -140,6 +134,14 @@ class _ReportEditPageState extends State<ReportEditPage> {
       args.onSelect.addListener((sender, e) {
         ReportInfo.instance.selectedInputImage(e);
       });
+      ReportInfo.instance.onClose.addListener((sender, e) {
+        setState(() {
+          _header.clear();
+          _blocks.clear();
+          _footer.clear();
+          widget.onSelect.dispose();
+        });
+      });
     } else {
       widget.onSelect.addListener((sender, e) {
         ReportInfo.instance.selectedInputImage(e);
@@ -148,6 +150,25 @@ class _ReportEditPageState extends State<ReportEditPage> {
     isInit = true;
   }
 
+  void _initListentener() {
+    ReportInfo.instance.onReload.addListener((sender, e) {
+      _header.clear();
+      _blocks.clear();
+      _footer.clear();
+      widget.onSelect.dispose();
+      _intitTemplate(args: e);
+      ReportInfo.instance.onReloadFinsh.emit(this, '');
+    });
+    ReportInfo.instance.onClose.addListener((sender, e) {
+      setState(() {
+        _header.clear();
+        _blocks.clear();
+        _footer.clear();
+        widget.onSelect.dispose();
+      });
+    });
+  }
+
   void _initPage() {
     try {
       _height = PtToPxConverter.ptToPx(_reportTemplate.pageSize!.height);

+ 2 - 0
lib/report_info/report_info.dart

@@ -58,6 +58,8 @@ class ReportInfo {
 
   FEventHandler onReloadFinsh = FEventHandler();
 
+  FEventHandler onClose = FEventHandler();
+
   static ReportInfo get instance {
     _reportInfo ??= ReportInfo._internal();
     return _reportInfo!;