Skip to content

Commit cebe37a

Browse files
fix: add mounted guard before setState in _CopyButton._copyToClipboard
setState() was called after 'await Clipboard.setData()' without a mounted check — throws if the widget is disposed during the clipboard write (e.g. user navigates away from the code block screen).
1 parent 4fcadf1 commit cebe37a

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/src/widgets/code_block_widget.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class _CopyButtonState extends State<_CopyButton> {
261261

262262
Future<void> _copyToClipboard() async {
263263
await Clipboard.setData(ClipboardData(text: widget.code));
264+
if (!mounted) return;
264265
setState(() => _copied = true);
265266

266267
await Future.delayed(const Duration(seconds: 2));

0 commit comments

Comments
 (0)