Skip to content

Commit 3b4553e

Browse files
authored
feat: copy highlighted text to clipboard on tap (#1649)
1 parent 710e83c commit 3b4553e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

mobile-app/lib/ui/views/news/html_handler/html_handler.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:convert';
33
import 'package:cached_network_image/cached_network_image.dart';
44
import 'package:collection/collection.dart';
55
import 'package:flutter/material.dart';
6+
import 'package:flutter/services.dart';
67
import 'package:flutter_html/flutter_html.dart';
78
import 'package:flutter_html_table/flutter_html_table.dart';
89
import 'package:freecodecamp/ui/theme/fcc_theme.dart';
@@ -238,6 +239,49 @@ class HTMLParser {
238239
return Container();
239240
},
240241
),
242+
TagExtension(
243+
tagsToExtend: {'code'},
244+
builder: (child) {
245+
String? parsed = parser.parseFragment(child.innerHtml).text ?? '';
246+
247+
return InkWell(
248+
onTap: () {
249+
Clipboard.setData(ClipboardData(text: parsed));
250+
ScaffoldMessenger.of(context).showSnackBar(
251+
SnackBar(
252+
content: Text.rich(
253+
TextSpan(
254+
children: [
255+
TextSpan(
256+
text: parsed,
257+
style: const TextStyle(
258+
fontWeight: FontWeight.bold,
259+
fontSize: 20,
260+
),
261+
),
262+
const TextSpan(
263+
text: ' copied to clipboard!',
264+
style: TextStyle(fontSize: 20),
265+
),
266+
],
267+
),
268+
),
269+
duration: const Duration(seconds: 1),
270+
),
271+
);
272+
},
273+
child: Text(
274+
parsed,
275+
style: const TextStyle(
276+
fontFamily: 'Hack',
277+
color: Colors.white,
278+
fontSize: 18,
279+
backgroundColor: FccColors.gray75,
280+
),
281+
),
282+
);
283+
},
284+
),
241285
TagExtension(
242286
tagsToExtend: {'img'},
243287
builder: (child) {

0 commit comments

Comments
 (0)