~repos /only-bible-app
GIT_CONFIG_PARAMETERS="'http.version=HTTP/1.1'" git clone
https://git.pyrossh.dev/only-bible-app.git
Discussions:
https://groups.google.com/g/rust-embed-devs
The only bible app you will ever need. No ads. No in-app purchases. No distractions.
62045ecd
—
pyrossh 1 month ago
Add red letter highlighting
- lib/home.dart +22 -3
lib/home.dart
CHANGED
|
@@ -225,12 +225,31 @@ class _VerseTextState extends State<_VerseText> with SingleTickerProviderStateMi
|
|
|
225
225
|
super.dispose();
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
static final _redTagPattern = RegExp(r"<red>(.*?)</red>");
|
|
229
|
+
|
|
228
230
|
@override
|
|
229
231
|
Widget build(BuildContext context) {
|
|
230
232
|
final v = widget.verse;
|
|
231
233
|
final theme = widget.theme;
|
|
232
234
|
final appState = widget.appState;
|
|
233
235
|
|
|
236
|
+
List<TextSpan> buildVerseTextSpans(String text, TextStyle style) {
|
|
237
|
+
final spans = <TextSpan>[];
|
|
238
|
+
final redStyle = style.copyWith(color: const Color(0xFF9A1111));
|
|
239
|
+
var lastEnd = 0;
|
|
240
|
+
for (final match in _redTagPattern.allMatches(text)) {
|
|
241
|
+
if (match.start > lastEnd) {
|
|
242
|
+
spans.add(TextSpan(text: text.substring(lastEnd, match.start), style: style));
|
|
243
|
+
}
|
|
244
|
+
spans.add(TextSpan(text: match.group(1), style: redStyle));
|
|
245
|
+
lastEnd = match.end;
|
|
246
|
+
}
|
|
247
|
+
if (lastEnd < text.length) {
|
|
248
|
+
spans.add(TextSpan(text: text.substring(lastEnd), style: style));
|
|
249
|
+
}
|
|
250
|
+
return spans;
|
|
251
|
+
}
|
|
252
|
+
|
|
234
253
|
Widget buildText(Color? bgColor) {
|
|
235
254
|
return Text.rich(
|
|
236
255
|
TextSpan(
|
|
@@ -252,9 +271,9 @@ class _VerseTextState extends State<_VerseText> with SingleTickerProviderStateMi
|
|
|
252
271
|
backgroundColor: bgColor,
|
|
253
272
|
),
|
|
254
273
|
),
|
|
255
|
-
|
|
274
|
+
...buildVerseTextSpans(
|
|
256
|
-
|
|
275
|
+
v.text ?? "",
|
|
257
|
-
|
|
276
|
+
bgColor != null
|
|
258
277
|
? appState.getHighlightStyle(context, v).copyWith(backgroundColor: bgColor)
|
|
259
278
|
: appState.getHighlightStyle(context, v),
|
|
260
279
|
),
|