From 535e9737994ff914eb2afff05d8b8953f8fc7c9e Mon Sep 17 00:00:00 2001 From: Kevin Despoulains Date: Mon, 26 Apr 2021 12:21:49 +0200 Subject: [PATCH] updating checkbox to handle long press and using UniqueKey() to avoid weird side effects --- lib/widgets/text_block.dart | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/widgets/text_block.dart b/lib/widgets/text_block.dart index efd56a27..beaadae1 100644 --- a/lib/widgets/text_block.dart +++ b/lib/widgets/text_block.dart @@ -163,6 +163,7 @@ class EditableTextBlock extends StatelessWidget { if (attrs[Attribute.list.key] == Attribute.checked) { return _Checkbox( + key: UniqueKey(), style: defaultStyles!.leading!.style, width: 32, isChecked: true, @@ -173,9 +174,9 @@ class EditableTextBlock extends StatelessWidget { if (attrs[Attribute.list.key] == Attribute.unchecked) { return _Checkbox( + key: UniqueKey(), style: defaultStyles!.leading!.style, width: 32, - isChecked: false, offset: block.offset + line.offset, onTap: onCheckboxTap, ); @@ -704,14 +705,13 @@ class _Checkbox extends StatelessWidget { Key? key, this.style, this.width, - this.isChecked, + this.isChecked = false, this.offset, this.onTap, }) : super(key: key); - final TextStyle? style; final double? width; - final bool? isChecked; + final bool isChecked; final int? offset; final Function(int, bool)? onTap; @@ -727,9 +727,12 @@ class _Checkbox extends StatelessWidget { alignment: AlignmentDirectional.topEnd, width: width, padding: const EdgeInsetsDirectional.only(end: 13), - child: Checkbox( - value: isChecked, - onChanged: _onCheckboxClicked, + child: GestureDetector( + onLongPress: () => _onCheckboxClicked(!isChecked), + child: Checkbox( + value: isChecked, + onChanged: _onCheckboxClicked, + ), ), ); }