import 'dart:io'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:gallery_saver/gallery_saver.dart'; import 'package:native_vision/native/native_vision.dart'; import 'loading_overlay.dart'; class DocCleanPage extends StatefulWidget { final String imgPath; const DocCleanPage({Key? key, required this.imgPath}) : super(key: key); @override State createState() { return DocCleanPageState(); } } class DocCleanPageState extends State { String? cleanedImgPath; void cleanImage(String imgPath) async { LoadingOverlay.of(context).show(); int docFilterPtr = await DocCleanFilter.init(); final cleanedImgPath = await DocCleanFilter.process(imgPath, docFilterPtr); await DocCleanFilter.release(docFilterPtr); if (!mounted) return; setState(() { this.cleanedImgPath = cleanedImgPath; }); LoadingOverlay.of(context).hide(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text("文档增强"), actions: [ TextButton( onPressed: () async { if (cleanedImgPath == null) { Fluttertoast.showToast(msg: "请先做增强处理"); return; } final succ = await GallerySaver.saveImage(cleanedImgPath!); Fluttertoast.showToast(msg: succ != null && succ ? "成功" : "失败"); }, child: const Text('保存', style: TextStyle( fontSize: 18, color: Colors.white, )), ), ]), body: Stack(fit: StackFit.expand, children: [ Image.file(File(cleanedImgPath ?? widget.imgPath)), Positioned( bottom: 20, left: 0, right: 0, child: Center( child: FloatingActionButton( child: const Icon(Icons.check), onPressed: () { cleanImage(widget.imgPath); }, ), ), ) ])); } }