opt: sys msg

This commit is contained in:
bggRGjQaUbCoE
2024-10-14 14:56:04 +08:00
parent b18412dc23
commit cd75873672

View File

@@ -7,6 +7,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:uuid/rng.dart';
import 'controller.dart'; import 'controller.dart';
@@ -125,28 +126,25 @@ class _SysMsgPageState extends State<SysMsgPage> {
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
.onSurface .onSurface
.withOpacity(0.75), .withOpacity(0.85),
), ),
), ),
const SizedBox(height: 5), const SizedBox(height: 5),
Row( SizedBox(
mainAxisAlignment: MainAxisAlignment.end, width: double.infinity,
children: [ child: Text(
Text( "${_sysMsgController.msgFeedSysMsgList[i].timeAt}",
"${_sysMsgController.msgFeedSysMsgList[i].timeAt}", maxLines: 1,
maxLines: 1, overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis, style: Theme.of(context)
style: Theme.of(context) .textTheme
.textTheme .bodySmall!
.bodySmall! .copyWith(
.copyWith( color:
color: Theme.of(context) Theme.of(context).colorScheme.outline,
.colorScheme ),
.outline textAlign: TextAlign.end,
.withOpacity(0.8), ),
),
)
],
), ),
], ],
), ),
@@ -171,82 +169,54 @@ class _SysMsgPageState extends State<SysMsgPage> {
InlineSpan _buildContent(String content) { InlineSpan _buildContent(String content) {
final List<InlineSpan> spanChildren = <InlineSpan>[]; final List<InlineSpan> spanChildren = <InlineSpan>[];
RegExp urlRegExp = RegExp('#\\{([^}]*)\\}\\{"([^}]*)"\\}'); RegExp urlRegExp = RegExp(
Iterable<Match> matches = urlRegExp.allMatches(content); '#\\{([^}]*)\\}\\{"([^}]*)"\\}|https?:\\/\\/[^\\s/\$.?#].[^\\s]*|www\\.[^\\s/\$.?#].[^\\s]*');
int previousEndIndex = 0; content.splitMapJoin(
if (matches.isNotEmpty) { urlRegExp,
for (final Match match in matches) { onMatch: (Match match) {
if (match.start > previousEndIndex) { if (match[0]!.startsWith('#')) {
spanChildren.add( spanChildren.add(
TextSpan( TextSpan(
text: content.substring(previousEndIndex, match.start), text: match[1],
),
);
}
spanChildren.add(
TextSpan(
text: match.group(1),
style: TextStyle(color: Theme.of(context).colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () {
try {
Uri uri = Uri.parse(match.group(2)!);
PiliScheme.routePush(uri);
} catch (err) {
SmartDialog.showToast(err.toString());
}
},
),
);
previousEndIndex = match.end;
}
} else {
urlRegExp = RegExp(
'https?:\\/\\/[^\\s/\$.?#].[^\\s]*|www\\.[^\\s/\$.?#].[^\\s]*');
matches = urlRegExp.allMatches(content);
if (matches.isNotEmpty) {
for (final Match match in matches) {
if (match.start > previousEndIndex) {
spanChildren.add(
TextSpan(
text: content.substring(previousEndIndex, match.start),
),
);
}
spanChildren.add(
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
size: MediaQuery.of(context).textScaler.scale(14),
Icons.link,
color: Theme.of(context).colorScheme.primary,
),
),
);
spanChildren.add(
TextSpan(
text: '网页链接',
style: TextStyle(color: Theme.of(context).colorScheme.primary), style: TextStyle(color: Theme.of(context).colorScheme.primary),
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
try { try {
Uri uri = Uri.parse(match.group(0)!); Uri uri = Uri.parse(match[2]!);
PiliScheme.routePush(uri); PiliScheme.routePush(uri);
} catch (err) { } catch (err) {
SmartDialog.showToast(err.toString()); SmartDialog.showToast(err.toString());
Utils.copyText(match.group(0) ?? '');
} }
}, },
), ),
); );
previousEndIndex = match.end; } else {
spanChildren.add(
TextSpan(
text: '\u{1F517}网页链接',
style: TextStyle(color: Theme.of(context).colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () {
try {
Uri uri = Uri.parse(match[0]!);
PiliScheme.routePush(uri);
} catch (err) {
SmartDialog.showToast(err.toString());
Utils.copyText(match[0] ?? '');
}
},
),
);
} }
} else { return '';
},
onNonMatch: (String nonMatchStr) {
spanChildren.add( spanChildren.add(
TextSpan(text: content), TextSpan(text: nonMatchStr),
); );
} return '';
} },
);
return TextSpan(children: spanChildren); return TextSpan(children: spanChildren);
} }
} }