attr_signature_edit_widget.dart 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import 'dart:ui' as ui;
  2. import 'package:flutter/material.dart';
  3. import 'package:kmpdfkit_demo/widgets/function/attrwidget/attr_color_list_widget.dart';
  4. import 'package:kmpdfkit_demo/widgets/function/attrwidget/base_slider_widget.dart';
  5. import 'package:kmpdfkit_demo/widgets/util/signature_image_util.dart';
  6. import 'package:syncfusion_flutter_signaturepad/signaturepad.dart';
  7. class AttrSignatureEditWidget extends StatefulWidget {
  8. const AttrSignatureEditWidget({Key? key}) : super(key: key);
  9. @override
  10. State<AttrSignatureEditWidget> createState() =>
  11. _AttrSignatureEditWidgetState();
  12. }
  13. class _AttrSignatureEditWidgetState extends State<AttrSignatureEditWidget> {
  14. GlobalKey<SfSignaturePadState> _signaturePadKey = GlobalKey();
  15. double strokeWidth = 5;
  16. Color strokeColor = Colors.red;
  17. @override
  18. Widget build(BuildContext context) {
  19. return Scaffold(
  20. appBar: AppBar(
  21. title: const Text('Create signature'),
  22. actions: [
  23. TextButton(
  24. onPressed: () async {
  25. String? path =
  26. await SignatureImageUtil.saveByteDataImage(await _signaturePadKey.currentState?.toImage());
  27. Navigator.pop(context, path);
  28. },
  29. child: const Text(
  30. 'Done',
  31. style: TextStyle(color: Colors.white),
  32. ))
  33. ],
  34. ),
  35. body: Column(
  36. children: [
  37. ColorListWidget(
  38. color: strokeColor,
  39. colorOptionsCallback: (color) {
  40. setState(() {
  41. strokeColor = color;
  42. });
  43. }),
  44. BaseSliderWidget(
  45. sliderCurrentValue: strokeWidth,
  46. sliderMinValue: 1,
  47. sliderMaxValue: 50,
  48. icon: Icons.line_weight,
  49. valueText: '${strokeWidth.round()}',
  50. valueShowType: ValueShowType.sourceValue,
  51. sliderValueCallback: (lineWidth) {
  52. setState(() {
  53. strokeWidth = lineWidth;
  54. });
  55. }),
  56. Expanded(
  57. child: Stack(
  58. children: [
  59. Positioned(
  60. child: SfSignaturePad(
  61. key: _signaturePadKey,
  62. minimumStrokeWidth: strokeWidth,
  63. maximumStrokeWidth: strokeWidth,
  64. backgroundColor: Colors.transparent,
  65. strokeColor: strokeColor,
  66. )),
  67. Positioned(
  68. bottom: 10,
  69. right: 20,
  70. child: IconButton(
  71. onPressed: () {
  72. _signaturePadKey.currentState?.clear();
  73. },
  74. icon: const Icon(Icons.delete)))
  75. ],
  76. ),
  77. )
  78. ],
  79. ),
  80. );
  81. }
  82. }