Skip to content

Commit fdf647d

Browse files
dwdjunie-agent
andcommitted
Fix crash when unfolding OMEMO2 section in Verify screen
ExpansionTile's PageStorage-backed boolean expanded-state collided with a descendant SelectableText's implicit Scrollable storing a double scroll offset (Flutter framework bug flutter/flutter#97583), throwing 'type bool is not a subtype of type double?' whenever a fingerprint section was unfolded. Replaced the ExpansionTile-based _foldableSection with a self-contained _FoldableSection StatefulWidget that manages its own expand/collapse state without PageStorage, keeping the same folded-by-default/subtitle UX. Verified with flutter analyze (no issues) and the full flutter test suite (939/939 passing). Co-authored-by: Junie <[email protected]>
1 parent ece3d7d commit fdf647d

1 file changed

Lines changed: 93 additions & 14 deletions

File tree

‎lib/widgets/fingerprint_verification_screen.dart‎

Lines changed: 93 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,22 @@ class _FingerprintVerificationScreenState
836836
);
837837
}
838838

839-
/// Wraps a cryptosystem's section ([children]) in an [ExpansionTile] so
840-
/// contacts' unsupported cryptosystems (per
839+
/// Wraps a cryptosystem's section ([children]) in a foldable
840+
/// [_FoldableSection] so contacts' unsupported cryptosystems (per
841841
/// `XmppService.isEncryptionProtocolLikelySupported`) are folded away
842842
/// by default, instead of always showing every protocol's full
843843
/// fingerprint/device list regardless of whether the contact ever
844844
/// announced support for it.
845+
///
846+
/// Note: a real [ExpansionTile] was tried here first, but Flutter has a
847+
/// long-standing framework bug (flutter/flutter#97583) where an
848+
/// [ExpansionTile]'s PageStorage-backed expanded state (a `bool`) can
849+
/// collide with a descendant [Scrollable]'s PageStorage-backed scroll
850+
/// offset (a `double`) -- e.g. the implicit [Scrollable] created by the
851+
/// [SelectableText] fingerprint widgets below -- throwing
852+
/// `type 'bool' is not a subtype of type 'double?'` when expanding.
853+
/// [_FoldableSection] sidesteps this entirely by managing its own
854+
/// expand/collapse state instead of relying on [PageStorage].
845855
Widget _foldableSection({
846856
required BuildContext context,
847857
required EncryptionProtocol protocol,
@@ -852,22 +862,91 @@ class _FingerprintVerificationScreenState
852862
widget.peerBareJid,
853863
protocol,
854864
);
855-
return ExpansionTile(
856-
key: PageStorageKey(protocol),
865+
return _FoldableSection(
866+
title: title,
857867
initiallyExpanded: isSupported,
858-
title: Text(
859-
title,
860-
style: Theme.of(context).textTheme.titleMedium,
861-
),
862868
subtitle: isSupported
863869
? null
864-
: Text(
865-
'Not known to be supported by ${widget.peerBareJid}',
866-
style: Theme.of(context).textTheme.bodySmall,
867-
),
868-
tilePadding: EdgeInsets.zero,
869-
childrenPadding: const EdgeInsets.only(bottom: 8),
870+
: 'Not known to be supported by ${widget.peerBareJid}',
870871
children: children,
871872
);
872873
}
873874
}
875+
876+
/// A simple, self-contained expand/collapse section used in place of
877+
/// [ExpansionTile] to avoid a Flutter framework bug where [ExpansionTile]'s
878+
/// [PageStorage]-backed expanded state can collide with a descendant
879+
/// [Scrollable]'s stored scroll offset (see the explanation at
880+
/// `_FingerprintVerificationScreenState._foldableSection`).
881+
class _FoldableSection extends StatefulWidget {
882+
const _FoldableSection({
883+
required this.title,
884+
required this.initiallyExpanded,
885+
required this.children,
886+
this.subtitle,
887+
});
888+
889+
final String title;
890+
final String? subtitle;
891+
final bool initiallyExpanded;
892+
final List<Widget> children;
893+
894+
@override
895+
State<_FoldableSection> createState() => _FoldableSectionState();
896+
}
897+
898+
class _FoldableSectionState extends State<_FoldableSection> {
899+
late bool _expanded = widget.initiallyExpanded;
900+
901+
@override
902+
Widget build(BuildContext context) {
903+
return Column(
904+
crossAxisAlignment: CrossAxisAlignment.stretch,
905+
children: [
906+
InkWell(
907+
onTap: () => setState(() => _expanded = !_expanded),
908+
child: Padding(
909+
padding: const EdgeInsets.symmetric(vertical: 4),
910+
child: Row(
911+
children: [
912+
Expanded(
913+
child: Column(
914+
crossAxisAlignment: CrossAxisAlignment.start,
915+
children: [
916+
Text(
917+
widget.title,
918+
style: Theme.of(context).textTheme.titleMedium,
919+
),
920+
if (widget.subtitle != null)
921+
Text(
922+
widget.subtitle!,
923+
style: Theme.of(context).textTheme.bodySmall,
924+
),
925+
],
926+
),
927+
),
928+
AnimatedRotation(
929+
turns: _expanded ? 0.5 : 0,
930+
duration: const Duration(milliseconds: 200),
931+
child: const Icon(Icons.expand_more),
932+
),
933+
],
934+
),
935+
),
936+
),
937+
AnimatedSize(
938+
duration: const Duration(milliseconds: 200),
939+
child: _expanded
940+
? Padding(
941+
padding: const EdgeInsets.only(bottom: 8),
942+
child: Column(
943+
crossAxisAlignment: CrossAxisAlignment.stretch,
944+
children: widget.children,
945+
),
946+
)
947+
: const SizedBox.shrink(),
948+
),
949+
],
950+
);
951+
}
952+
}

0 commit comments

Comments
 (0)