mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
fix & opt.
fix: servers will only refresh once if `spi.autoConnect` is false opt.: `UrlText` algo
This commit is contained in:
@@ -79,10 +79,6 @@ bool get isLinux => OS.type == OS.linux;
|
|||||||
bool get isMacOS => OS.type == OS.macos;
|
bool get isMacOS => OS.type == OS.macos;
|
||||||
bool get isWindows => OS.type == OS.windows;
|
bool get isWindows => OS.type == OS.windows;
|
||||||
bool get isWeb => OS.type == OS.web;
|
bool get isWeb => OS.type == OS.web;
|
||||||
bool get isMobile =>
|
bool get isMobile => OS.type == OS.ios || OS.type == OS.android;
|
||||||
OS.type == OS.ios ||
|
|
||||||
OS.type == OS.android;
|
|
||||||
bool get isDesktop =>
|
bool get isDesktop =>
|
||||||
OS.type == OS.linux ||
|
OS.type == OS.linux || OS.type == OS.macos || OS.type == OS.windows;
|
||||||
OS.type == OS.macos ||
|
|
||||||
OS.type == OS.windows;
|
|
||||||
|
|||||||
@@ -104,7 +104,15 @@ class ServerProvider extends ChangeNotifier {
|
|||||||
if (s.state != ServerState.failed) return;
|
if (s.state != ServerState.failed) return;
|
||||||
_limiter.reset(s.spi.id);
|
_limiter.reset(s.spi.id);
|
||||||
}
|
}
|
||||||
if (!(s.spi.autoConnect ?? true)) return;
|
/// If [spi.autoConnect] is false and server is disconnected, then skip.
|
||||||
|
///
|
||||||
|
/// If [spi.autoConnect] is false and server is connected, then refresh.
|
||||||
|
/// If no this, the server will only refresh once by clicking refresh button.
|
||||||
|
///
|
||||||
|
/// If [spi.autoConnect] is true, then refresh.
|
||||||
|
if (!(s.spi.autoConnect ?? true) && s.state == ServerState.disconnected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
return await _getData(s.spi);
|
return await _getData(s.spi);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import '../../core/utils/ui.dart';
|
|||||||
final _reg = RegExp(
|
final _reg = RegExp(
|
||||||
r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]*");
|
r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]*");
|
||||||
|
|
||||||
const _textStyle = TextStyle();
|
|
||||||
|
|
||||||
class UrlText extends StatelessWidget {
|
class UrlText extends StatelessWidget {
|
||||||
final String text;
|
final String text;
|
||||||
final String? replace;
|
final String? replace;
|
||||||
@@ -20,60 +18,41 @@ class UrlText extends StatelessWidget {
|
|||||||
required this.text,
|
required this.text,
|
||||||
this.replace,
|
this.replace,
|
||||||
this.textAlign,
|
this.textAlign,
|
||||||
this.style = _textStyle,
|
this.style = const TextStyle(),
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
List<InlineSpan> getTextSpans(Color c) {
|
List<InlineSpan> _buildTextSpans(Color c) {
|
||||||
final widgets = <InlineSpan>[];
|
final widgets = <InlineSpan>[];
|
||||||
Iterable<Match> matches = _reg.allMatches(text);
|
|
||||||
List<_ResultMatch> resultMatches = <_ResultMatch>[];
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
|
|
||||||
for (Match match in matches) {
|
for (final match in _reg.allMatches(text)) {
|
||||||
final group0 = match.group(0);
|
final group0 = match.group(0);
|
||||||
if (group0 != null && group0.isNotEmpty) {
|
if (group0 != null && group0.isNotEmpty) {
|
||||||
if (start != match.start) {
|
if (start != match.start) {
|
||||||
_ResultMatch result1 = _ResultMatch(
|
widgets.add(
|
||||||
false,
|
TextSpan(
|
||||||
text.substring(start, match.start),
|
text: text.substring(start, match.start),
|
||||||
|
style: style.copyWith(color: c),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
resultMatches.add(result1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ResultMatch result2 = _ResultMatch(
|
widgets.add(_LinkTextSpan(
|
||||||
true,
|
replace: replace,
|
||||||
match.group(0)!,
|
text: group0,
|
||||||
);
|
style: style.copyWith(color: primaryColor),
|
||||||
resultMatches.add(result2);
|
));
|
||||||
start = match.end;
|
start = match.end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start < text.length) {
|
if (start < text.length) {
|
||||||
_ResultMatch result1 = _ResultMatch(
|
widgets.add(
|
||||||
false,
|
TextSpan(
|
||||||
text.substring(start),
|
text: text.substring(start),
|
||||||
|
style: style.copyWith(color: c),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
resultMatches.add(result1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var result in resultMatches) {
|
|
||||||
if (result.isUrl) {
|
|
||||||
widgets.add(
|
|
||||||
_LinkTextSpan(
|
|
||||||
replace: replace ?? result.text,
|
|
||||||
text: result.text,
|
|
||||||
style: style.copyWith(color: primaryColor),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
widgets.add(
|
|
||||||
TextSpan(
|
|
||||||
text: result.text,
|
|
||||||
style: style.copyWith(color: c),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return widgets;
|
return widgets;
|
||||||
}
|
}
|
||||||
@@ -83,7 +62,7 @@ class UrlText extends StatelessWidget {
|
|||||||
return RichText(
|
return RichText(
|
||||||
textAlign: textAlign ?? TextAlign.start,
|
textAlign: textAlign ?? TextAlign.start,
|
||||||
text: TextSpan(
|
text: TextSpan(
|
||||||
children: getTextSpans(DynamicColors.content.resolve(context)),
|
children: _buildTextSpans(DynamicColors.content.resolve(context)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -93,17 +72,10 @@ class _LinkTextSpan extends TextSpan {
|
|||||||
_LinkTextSpan({TextStyle? style, required String text, String? replace})
|
_LinkTextSpan({TextStyle? style, required String text, String? replace})
|
||||||
: super(
|
: super(
|
||||||
style: style,
|
style: style,
|
||||||
text: replace,
|
text: replace ?? text,
|
||||||
recognizer: TapGestureRecognizer()
|
recognizer: TapGestureRecognizer()
|
||||||
..onTap = () {
|
..onTap = () {
|
||||||
openUrl(text);
|
openUrl(text);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ResultMatch {
|
|
||||||
final bool isUrl;
|
|
||||||
final String text;
|
|
||||||
|
|
||||||
_ResultMatch(this.isUrl, this.text);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user