123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 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<StatefulWidget> createState() {
- return DocCleanPageState();
- }
- }
- class DocCleanPageState extends State<DocCleanPage> {
- 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);
- },
- ),
- ),
- )
- ]));
- }
- }
|