attr_signature_edit_widget.dart 2.8 KB

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