IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Flutter 电子签名 -> 正文阅读

[移动开发]Flutter 电子签名

依赖:signature: ^3.2.1
基本用方法

 bool landScape = false; // 是否横屏

  final SignatureController _signatureController = SignatureController(
    penStrokeWidth: 1, // 线条宽度
    penColor: Colors.black, // 线条颜色
    exportBackgroundColor: Colors.transparent, // 导出图片背景色
  );
DrawView(
                    signatureController: _signatureController,
                    width: double.infinity,
                    height: 200,
                    landScape: landScape,
                    biggerCallback: () {
                      setState(() {
                        landScape = true;
                      });
                    },
                    resetCallback: () {
                      setState(() {
                        landScape = true;
                      });
                    },
                  ),

用法


import 'package:repair_app_android/common/ColorsUtil.dart';
import 'package:signature/signature.dart';

import '../../../index.dart';
import 'DrawView.dart';
import 'dart:ui' as ui;

class SignaturePage extends StatefulWidget {
  @override
  _SignaturePageState createState() => _SignaturePageState();
}

class _SignaturePageState extends State<SignaturePage> {
  bool landScape = true; // 是否横屏

  final SignatureController _signatureController = SignatureController(
    penStrokeWidth: 1, // 线条宽度
    penColor: Colors.black, // 线条颜色
    exportBackgroundColor: Colors.transparent, // 导出图片背景色
  );

  @override
  Widget build(BuildContext context) {
    if (landScape == false) {
      return Scaffold(
        backgroundColor: ColorsUtil.black87,
        appBar: AppBar(
          brightness: Brightness.light,
          title: Text('类型'),
        ),
        body: SafeArea(
          child: FittedBox(
            fit: BoxFit.contain,
            child: DrawView(
              signatureController: _signatureController,
              width: 690,
              height: 370,
              landScape: landScape,
              biggerCallback: () {
                setState(() {
                  landScape = true;
                });
              },
              resetCallback: () {
                setState(() {
                  landScape = true;
                });
              },
            ),
          ),
        ),
      );
    } else {
      // 手写板横屏
      return Scaffold(
        body: Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          color: Colors.white,
          child: FittedBox(
            fit: BoxFit.contain,
            child: DrawView(
              signatureController: _signatureController,
              width: 690,
              height: 370,
              landScape: landScape,
              biggerCallback: () {
                setState(() {
                  landScape = false;
                });
              },
              resetCallback: () {
                setState(() {
                  landScape = false;
                });
              },
            ),
          ),
        ),
      );
    }
  }

}

签名View

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:repair_app_android/common/ColorsUtil.dart';
import 'package:signature/signature.dart';

class DrawView extends StatefulWidget {
  final signatureController;
  final biggerCallback; // 放大回调
  final resetCallback; // 还原大小回调
  final double width;
  final double height;
  final bool landScape; // 是否横屏
  DrawView(
      {Key key,
        this.signatureController,
        this.biggerCallback,
        this.resetCallback,
        @required this.width,
        @required this.height,
        this.landScape})
      : super(key: key);

  @override
  _DrawViewState createState() => _DrawViewState();
}

class _DrawViewState extends State<DrawView> {
  bool isEmpty;

  @override
  void initState() {
    super.initState();

    if (widget.signatureController.value.length > 0) {
      isEmpty = false;
    } else {
      isEmpty = true;
    }

    // 监听画板
    widget.signatureController.addListener(() {
      bool tmpIsEmpty = true;
      if (widget.signatureController.value.length > 0) {
        tmpIsEmpty = false;
      } else {
        tmpIsEmpty = true;
      }
      if (isEmpty != tmpIsEmpty) {
        if (this.mounted) {
          setState(() {
            isEmpty = tmpIsEmpty;
          });
        }
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return RotatedBox(
      quarterTurns: widget.landScape ? 1 : 0,
      child: Stack(
        alignment: Alignment.center,
        children: [
          Signature(
            controller: widget.signatureController,
            width: widget.width,
            height: widget.height,
            backgroundColor: Colors.white,
          ),
          // 暂无签名
          Offstage(
            offstage: isEmpty ? false : true,
            child: Text(
              '请在此处签字',
              style: TextStyle(
                fontSize: 20,
                color: Colors.grey,
              ),
            ),
          ),
          // 放大按钮
          Positioned(
            top: 10,
            right: widget.landScape ? 0 : 10,
            child: IconButton(
              icon: Image.asset(
                'imgs/logo_light.png',
                width: 0,
                height: 0,
              ),
              onPressed: () {
                //widget.biggerCallback();
              },
            ),
          ),
          // 橡皮 & 完成 按钮
          Positioned(
            bottom: 10,
            right: widget.landScape ? 0 : 10,
            child: Row(
              children: [
                // 橡皮
                ElevatedButton(
                  child: Text('重写',style: TextStyle(fontSize: 12),),
                  onPressed: () {
                    setState(() {
                      widget.signatureController.clear();
                    });
                  },
                ),
                // 完成
                Offstage(
                  offstage: widget.landScape ? false : true,
                  child: Container(
                    width: 80,
                    height: 50,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8),
                      color: Colors.blue,
                    ),
                    child: FlatButton(
                      padding: EdgeInsets.zero,
                      child: Text(
                        '完成',
                        style: TextStyle(
                          fontSize: 26,
                          color: Colors.black87,
                        ),
                      ),
                      onPressed: () {
                        widget.resetCallback();
                      },
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-07-16 11:25:31  更:2021-07-16 11:25:46 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/5 15:32:35-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码