fix & opt

fix: cant ping when launch page is ping
fix: button text color not primaryColor
opt: getting primaryColor
This commit is contained in:
lollipopkit
2023-02-01 17:18:46 +08:00
parent 2faea10d61
commit 21ac323ed1
28 changed files with 445 additions and 423 deletions

View File

@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import '../../data/res/color.dart';
import '../../data/res/menu.dart';
import '../../generated/l10n.dart';
import 'primary_color.dart';
class DropdownBtnItem {
final String text;
@@ -15,12 +15,10 @@ class DropdownBtnItem {
Widget build(S s) => Row(
children: [
PrimaryColor(builder: (context, primaryColor) {
return Icon(
icon,
color: primaryColor,
);
}),
Icon(
icon,
color: primaryColor,
),
const SizedBox(
width: 10,
),

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'primary_color.dart';
import '../../data/res/color.dart';
InputDecoration buildDecoration(String label,
{TextStyle? textStyle, IconData? icon, String? hint}) {
@@ -8,11 +8,9 @@ InputDecoration buildDecoration(String label,
labelText: label,
labelStyle: textStyle,
hintText: hint,
icon: PrimaryColor(builder: (context, primaryColor) {
return Icon(
icon,
color: primaryColor,
);
}),
icon: Icon(
icon,
color: primaryColor,
),
);
}

View File

@@ -1,20 +0,0 @@
import 'package:flutter/material.dart';
import '../../data/store/setting.dart';
import '../../locator.dart';
final _primaryColor = locator<SettingStore>().primaryColor.listenable();
class PrimaryColor extends StatelessWidget {
final Widget Function(BuildContext context, Color primaryColor) builder;
const PrimaryColor({Key? key, required this.builder}) : super(key: key);
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<int>(
builder: (context, c, child) => builder(context, Color(c)),
valueListenable: _primaryColor,
);
}
}

View File

@@ -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 {