diff --git a/lib/views/widgets/e_signature/e_signature.dart b/lib/views/widgets/e_signature/e_signature.dart index e21a51a0..6aa8ca6a 100644 --- a/lib/views/widgets/e_signature/e_signature.dart +++ b/lib/views/widgets/e_signature/e_signature.dart @@ -6,7 +6,6 @@ import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; -import '../../app_style/sizing.dart'; import '../loaders/image_loader.dart'; class ESignature extends StatefulWidget { @@ -49,115 +48,111 @@ class _ESignatureState extends State { @override Widget build(BuildContext context) { - return Column( - children: [ - if (widget.oldSignature != null || signature != null) + return FormField(onSaved: (_) async { + widget.onSaved(signature); + }, builder: (FormFieldState state) { + return Column( + children: [ Container( width: MediaQuery.of(context).size.width, - padding: const EdgeInsets.only(bottom: 8), - height: 90 * AppStyle.getScaleFactor(context), - child: signature != null ? Image.memory(signature) : ImageLoader(boxFit: BoxFit.contain, url: widget.oldSignature), - ), - FormField(onSaved: (_) async { - widget.onSaved(signature); - }, builder: (FormFieldState state) { - return Column( - children: [ - Container( - width: MediaQuery.of(context).size.width, - padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: _editable ? const BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)) : BorderRadius.circular(10), - boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, + padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: _editable ? const BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)) : BorderRadius.circular(10), + boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)], + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - widget.title.tinyFont(context).paddingOnly(top: 8), - (!_editable - ? "edit".toSvgAsset(width: 48).paddingOnly(top: 8) - : Container( - width: 48.toScreenWidth, - height: 48.toScreenWidth, - decoration: BoxDecoration(borderRadius: BorderRadius.circular(100), border: Border.all(color: AppColor.neutral30)), - padding: const EdgeInsets.all(11), - margin: const EdgeInsets.only(top: 8), - child: "done".toSvgAsset(width: 26), - )) - .onPress(() async { - if (_editable) { - signature = await _controller.toPngBytes(); - if (widget.onChange != null) { - widget.onChange(signature); - } - } - _editable = !_editable; - setState(() {}); - }), - ], - ), - AbsorbPointer( - absorbing: !_editable, - child: Signature( - controller: _controller, - height: 135.toScreenHeight, - width: MediaQuery.of(context).size.width - 64.toScreenWidth, - backgroundColor: Colors.transparent, - ), - ), + widget.title.tinyFont(context).paddingOnly(top: 8), + (!_editable + ? "edit".toSvgAsset(width: 48).paddingOnly(top: 8) + : Container( + width: 48.toScreenWidth, + height: 48.toScreenWidth, + decoration: BoxDecoration(borderRadius: BorderRadius.circular(100), border: Border.all(color: AppColor.neutral30)), + padding: const EdgeInsets.all(11), + margin: const EdgeInsets.only(top: 8), + child: "done".toSvgAsset(width: 26), + )) + .onPress(() async { + if (_editable) { + signature = await _controller.toPngBytes(); + if (widget.onChange != null) { + widget.onChange(signature); + } + } + _editable = !_editable; + setState(() {}); + }), ], ), + (widget.oldSignature != null || signature != null || !_editable) + ? Container( + height: 135.toScreenHeight, + width: MediaQuery.of(context).size.width, + padding: const EdgeInsets.only(bottom: 8), + child: signature != null ? Image.memory(signature) : ImageLoader(boxFit: BoxFit.contain, url: widget.oldSignature), + ) + : AbsorbPointer( + absorbing: !_editable, + child: Signature( + controller: _controller, + height: 135.toScreenHeight, + width: MediaQuery.of(context).size.width - 64.toScreenWidth, + backgroundColor: Colors.transparent, + ), + ), + ], + ), + ), + if (_editable) + Container( + decoration: const BoxDecoration( + color: AppColor.neutral30, + borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)), ), - if (_editable) - Container( - decoration: const BoxDecoration( - color: AppColor.neutral30, - borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)), - ), - child: Row( - children: [ - "clear".toSvgAsset(width: 14).paddingOnly(start: 16).onPress(() { - _controller.clear(); - }), - 35.width, - "back".toSvgAsset(width: 17).onPress(() { - _controller.undo(); - }), - 27.width, - "redo".toSvgAsset(width: 17).onPress(() { - _controller.redo(); - }), - // IconButton( - // onPressed: () { - // _unpaint = !_unpaint; - // setState(() {}); - // }, - // icon: Icon( - // _unpaint ? Icons.draw : Icons.ac_unit, - // color: _unpaint ? AColors.orange : null, - // )), - // const Spacer(), - // IconButton( - // onPressed: () async { - // signature = await _controller.toPngBytes(); - // if (widget.onChange != null) { - // widget.onChange(signature); - // } - // setState(() {}); - // }, - // icon: const Icon(Icons.check)), - ], - ).paddingOnly(top: 12, bottom: 12), - ) - ], - ); - }), - ], - ); + child: Row( + children: [ + "clear".toSvgAsset(width: 14).paddingOnly(start: 16).onPress(() { + _controller.clear(); + }), + 35.width, + "back".toSvgAsset(width: 17).onPress(() { + _controller.undo(); + }), + 27.width, + "redo".toSvgAsset(width: 17).onPress(() { + _controller.redo(); + }), + // IconButton( + // onPressed: () { + // _unpaint = !_unpaint; + // setState(() {}); + // }, + // icon: Icon( + // _unpaint ? Icons.draw : Icons.ac_unit, + // color: _unpaint ? AColors.orange : null, + // )), + // const Spacer(), + // IconButton( + // onPressed: () async { + // signature = await _controller.toPngBytes(); + // if (widget.onChange != null) { + // widget.onChange(signature); + // } + // setState(() {}); + // }, + // icon: const Icon(Icons.check)), + ], + ).paddingOnly(top: 12, bottom: 12), + ) + ], + ); + }); } }