Skip to content

Commit baaf72a

Browse files
committed
feat: Add flutter_highlight dependency and update OtherDemosPage for syntax highlighting
1 parent e91c85e commit baaf72a

4 files changed

Lines changed: 60 additions & 25 deletions

File tree

‎.vscode/settings.json‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"activityBar.activeBackground": "#92aecb",
4+
"activityBar.background": "#92aecb",
5+
"activityBar.foreground": "#15202b",
6+
"activityBar.inactiveForeground": "#15202b99",
7+
"activityBarBadge.background": "#ad527f",
8+
"activityBarBadge.foreground": "#e7e7e7",
9+
"commandCenter.border": "#15202b99",
10+
"sash.hoverBorder": "#92aecb",
11+
"statusBar.background": "#6f94bb",
12+
"statusBar.foreground": "#15202b",
13+
"statusBarItem.hoverBackground": "#4f7aa8",
14+
"statusBarItem.remoteBackground": "#6f94bb",
15+
"statusBarItem.remoteForeground": "#15202b",
16+
"titleBar.activeBackground": "#6f94bb",
17+
"titleBar.activeForeground": "#15202b",
18+
"titleBar.inactiveBackground": "#6f94bb99",
19+
"titleBar.inactiveForeground": "#15202b99"
20+
},
21+
"peacock.color": "#6f94bb"
22+
}

‎lib/pages/api_demo/other_demos/other_demos_page.dart‎

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import 'package:flutter/services.dart';
44
import 'package:flutter_animate/flutter_animate.dart';
55
import 'package:flutter_resizable_container/flutter_resizable_container.dart';
66
import 'package:google_fonts/google_fonts.dart';
7+
import 'package:flutter_highlight/flutter_highlight.dart';
8+
import 'package:flutter_highlight/themes/github.dart';
9+
import 'package:flutter_highlight/themes/dracula.dart';
710
import 'package:llm_json_stream/classes/json_stream_parser.dart';
811
import 'package:llm_json_stream/classes/property_stream.dart';
912
import 'package:json_stream_parser_demo/utils/stream_text_in_chunks.dart';
@@ -302,8 +305,7 @@ class _OtherDemosPageState extends State<OtherDemosPage> {
302305
_DemoItem(
303306
key: ValueKey('demo8_$_streamKey'),
304307
title: 'List onElement - String Streams',
305-
code:
306-
'parser.getListProperty("tags", onElement: ...) [Stream<String>];',
308+
code: 'parser.getListProperty("tags", onElement: ...);',
307309
json:
308310
'{"tags": ["flutter", "dart", "json", "streaming"]}',
309311
interval: _interval,
@@ -467,16 +469,17 @@ class _DemoItemState extends State<_DemoItem> {
467469
),
468470
),
469471
const SizedBox(height: 16),
470-
Container(
471-
padding: const EdgeInsets.all(16),
472-
decoration: BoxDecoration(
473-
color: isDark ? Colors.grey[850] : Colors.grey[100],
474-
borderRadius: BorderRadius.circular(8),
475-
),
476-
child: SelectableText(
477-
widget.code,
478-
style: GoogleFonts.robotoMono(
479-
fontSize: 16,
472+
ClipRRect(
473+
borderRadius: BorderRadius.circular(8),
474+
child: SelectionArea(
475+
child: HighlightView(
476+
widget.code,
477+
language: 'dart',
478+
theme: isDark ? draculaTheme : githubTheme,
479+
padding: const EdgeInsets.all(16),
480+
textStyle: GoogleFonts.robotoMono(
481+
fontSize: 16,
482+
),
480483
),
481484
),
482485
),
@@ -530,7 +533,7 @@ class _DemoItemState extends State<_DemoItem> {
530533
style: GoogleFonts.robotoMono(
531534
fontSize: 16,
532535
fontWeight: FontWeight.bold,
533-
color: Colors.black,
536+
color: isDark ? Colors.white : Colors.black,
534537
letterSpacing: 0.5,
535538
),
536539
),
@@ -540,7 +543,7 @@ class _DemoItemState extends State<_DemoItem> {
540543
text: fullJson.substring(streamedLength),
541544
style: GoogleFonts.robotoMono(
542545
fontSize: 16,
543-
color: isDark ? Colors.grey[700] : Colors.grey[400],
546+
color: isDark ? Colors.grey[600] : Colors.grey[400],
544547
letterSpacing: 0.5,
545548
),
546549
),
@@ -569,7 +572,6 @@ class _StringFutureDemo extends StatelessWidget {
569572
style: const TextStyle(
570573
fontSize: 16,
571574
fontWeight: FontWeight.bold,
572-
color: Colors.black,
573575
),
574576
)
575577
.animate()
@@ -612,7 +614,6 @@ class _StringStreamDemoState extends State<_StringStreamDemo> {
612614
style: const TextStyle(
613615
fontSize: 16,
614616
fontWeight: FontWeight.bold,
615-
color: Colors.black,
616617
),
617618
);
618619
}
@@ -668,7 +669,9 @@ class _PropertyChip extends StatelessWidget {
668669
label: Text(
669670
'$label: ${snapshot.data}',
670671
style: const TextStyle(
671-
fontSize: 16, fontWeight: FontWeight.bold, color: Colors.black),
672+
fontSize: 16,
673+
fontWeight: FontWeight.bold,
674+
),
672675
),
673676
padding: const EdgeInsets.all(8),
674677
)
@@ -698,7 +701,6 @@ class _NestedPropertyDemo extends StatelessWidget {
698701
style: const TextStyle(
699702
fontSize: 16,
700703
fontWeight: FontWeight.bold,
701-
color: Colors.black,
702704
),
703705
)
704706
.animate()
@@ -727,7 +729,6 @@ class _ListIndexDemo extends StatelessWidget {
727729
style: const TextStyle(
728730
fontSize: 16,
729731
fontWeight: FontWeight.bold,
730-
color: Colors.black,
731732
),
732733
)
733734
.animate()
@@ -757,7 +758,6 @@ class _ChainingDemo extends StatelessWidget {
757758
style: const TextStyle(
758759
fontSize: 16,
759760
fontWeight: FontWeight.bold,
760-
color: Colors.black,
761761
),
762762
)
763763
.animate()
@@ -814,7 +814,6 @@ class _ListOnElementObjectsDemoState extends State<_ListOnElementObjectsDemo> {
814814
style: const TextStyle(
815815
fontSize: 16,
816816
fontWeight: FontWeight.bold,
817-
color: Colors.black,
818817
),
819818
),
820819
padding: const EdgeInsets.all(8),
@@ -884,8 +883,7 @@ class _ListOnElementStringsDemoState extends State<_ListOnElementStringsDemo> {
884883
return Chip(
885884
label: Text(
886885
tag,
887-
style: const TextStyle(
888-
fontSize: 16, fontWeight: FontWeight.bold, color: Colors.black),
886+
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
889887
),
890888
padding: const EdgeInsets.all(8),
891889
)
@@ -915,7 +913,6 @@ class _EdgeCaseMultilineDemo extends StatelessWidget {
915913
style: const TextStyle(
916914
fontSize: 16,
917915
fontWeight: FontWeight.bold,
918-
color: Colors.black,
919916
),
920917
)
921918
.animate()
@@ -944,7 +941,6 @@ class _EdgeCaseSpecialCharsDemo extends StatelessWidget {
944941
style: const TextStyle(
945942
fontSize: 16,
946943
fontWeight: FontWeight.bold,
947-
color: Colors.black,
948944
),
949945
)
950946
.animate()

‎pubspec.lock‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ packages:
102102
url: "https://pub.dev"
103103
source: hosted
104104
version: "4.5.2"
105+
flutter_highlight:
106+
dependency: "direct main"
107+
description:
108+
name: flutter_highlight
109+
sha256: "7b96333867aa07e122e245c033b8ad622e4e3a42a1a2372cbb098a2541d8782c"
110+
url: "https://pub.dev"
111+
source: hosted
112+
version: "0.7.0"
105113
flutter_lints:
106114
dependency: "direct dev"
107115
description:
@@ -155,6 +163,14 @@ packages:
155163
url: "https://pub.dev"
156164
source: hosted
157165
version: "0.4.5"
166+
highlight:
167+
dependency: transitive
168+
description:
169+
name: highlight
170+
sha256: "5353a83ffe3e3eca7df0abfb72dcf3fa66cc56b953728e7113ad4ad88497cf21"
171+
url: "https://pub.dev"
172+
source: hosted
173+
version: "0.7.0"
158174
http:
159175
dependency: transitive
160176
description:

‎pubspec.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
google_generative_ai: 0.4.5
1818
responsive_framework: ^1.5.1
1919
flutter_resizable_container: ^4.2.0
20+
flutter_highlight: ^0.7.0
2021

2122
dev_dependencies:
2223
flutter_test:

0 commit comments

Comments
 (0)