mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
fix & opt
fix: cant ping when launch page is ping fix: button text color not primaryColor opt: getting primaryColor
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
|
||||
import '../../core/utils/ui.dart';
|
||||
|
||||
const regUrl =
|
||||
r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]*";
|
||||
final _reg = RegExp(
|
||||
r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]*");
|
||||
|
||||
const _textStyle = TextStyle();
|
||||
|
||||
class UrlText extends StatelessWidget {
|
||||
final String text;
|
||||
@@ -12,18 +15,17 @@ class UrlText extends StatelessWidget {
|
||||
final TextAlign? textAlign;
|
||||
final TextStyle style;
|
||||
|
||||
const UrlText(
|
||||
{Key? key,
|
||||
required this.text,
|
||||
this.replace,
|
||||
this.textAlign,
|
||||
this.style = const TextStyle()})
|
||||
: super(key: key);
|
||||
const UrlText({
|
||||
Key? key,
|
||||
required this.text,
|
||||
this.replace,
|
||||
this.textAlign,
|
||||
this.style = _textStyle,
|
||||
}) : super(key: key);
|
||||
|
||||
List<InlineSpan> _getTextSpans(bool isDarkMode) {
|
||||
List<InlineSpan> _getTextSpans(Color c) {
|
||||
List<InlineSpan> widgets = <InlineSpan>[];
|
||||
final reg = RegExp(regUrl);
|
||||
Iterable<Match> matches = reg.allMatches(text);
|
||||
Iterable<Match> matches = _reg.allMatches(text);
|
||||
List<_ResultMatch> resultMatches = <_ResultMatch>[];
|
||||
int start = 0;
|
||||
|
||||
@@ -54,16 +56,22 @@ class UrlText extends StatelessWidget {
|
||||
|
||||
for (var result in resultMatches) {
|
||||
if (result.isUrl) {
|
||||
widgets.add(_LinkTextSpan(
|
||||
widgets.add(
|
||||
_LinkTextSpan(
|
||||
replace: replace ?? result.text,
|
||||
text: result.text,
|
||||
style: style.copyWith(color: Colors.blue)));
|
||||
style: style.copyWith(color: primaryColor),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
widgets.add(TextSpan(
|
||||
widgets.add(
|
||||
TextSpan(
|
||||
text: result.text,
|
||||
style: style.copyWith(
|
||||
color: isDarkMode ? Colors.white : Colors.black,
|
||||
)));
|
||||
color: c,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return widgets;
|
||||
@@ -73,7 +81,7 @@ class UrlText extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return RichText(
|
||||
textAlign: textAlign ?? TextAlign.start,
|
||||
text: TextSpan(children: _getTextSpans(isDarkMode(context))),
|
||||
text: TextSpan(children: _getTextSpans(contentColor.resolve(context))),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -81,12 +89,13 @@ class UrlText extends StatelessWidget {
|
||||
class _LinkTextSpan extends TextSpan {
|
||||
_LinkTextSpan({TextStyle? style, required String text, String? replace})
|
||||
: super(
|
||||
style: style,
|
||||
text: replace,
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
openUrl(text);
|
||||
});
|
||||
style: style,
|
||||
text: replace,
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
openUrl(text);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _ResultMatch {
|
||||
|
||||
Reference in New Issue
Block a user