BBreaking change

This commit is contained in:
LollipopKit
2021-10-26 07:31:42 +08:00
parent 44e9780e5a
commit a725604121
20 changed files with 710 additions and 183 deletions

View File

@@ -1,32 +0,0 @@
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class DonutPieChart extends StatelessWidget {
final List<charts.Series<dynamic, num>> seriesList;
final bool animate;
const DonutPieChart(this.seriesList, {Key? key, this.animate = false})
: super(key: key);
@override
Widget build(BuildContext context) {
return charts.PieChart(seriesList,
animate: animate,
layoutConfig: charts.LayoutConfig(
leftMarginSpec: charts.MarginSpec.fixedPixel(1),
topMarginSpec: charts.MarginSpec.fixedPixel(1),
rightMarginSpec: charts.MarginSpec.fixedPixel(1),
bottomMarginSpec: charts.MarginSpec.fixedPixel(17)),
defaultRenderer: charts.ArcRendererConfig<num>(
arcWidth: 6,
arcRatio: 0.2,
));
}
}
class IndexPercent {
final int id;
final int percent;
IndexPercent(this.id, this.percent);
}

View File

@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
class RoundRectCard extends StatelessWidget {
const RoundRectCard(this.child, {Key? key}) : super(key: key);
final Widget child;
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 17),
child: child,
),
margin: const EdgeInsets.symmetric(vertical: 7),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(17))),
);
}
}

View File

@@ -0,0 +1,91 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/utils.dart';
const regUrl =
r"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]*";
class UrlText extends StatelessWidget {
final String text;
final String? replace;
final TextStyle style;
const UrlText(
{Key? key,
required this.text,
this.replace,
this.style = const TextStyle()})
: super(key: key);
List<InlineSpan> _getTextSpans(bool isDarkMode) {
List<InlineSpan> widgets = <InlineSpan>[];
final reg = RegExp(regUrl);
Iterable<Match> _matches = reg.allMatches(text);
List<_ResultMatch> resultMatches = <_ResultMatch>[];
int start = 0;
for (Match match in _matches) {
final group0 = match.group(0);
if (group0 != null && group0.isNotEmpty) {
if (start != match.start) {
_ResultMatch result1 = _ResultMatch();
result1.isUrl = false;
result1.text = text.substring(start, match.start);
resultMatches.add(result1);
}
_ResultMatch result2 = _ResultMatch();
result2.isUrl = true;
result2.text = match.group(0)!;
resultMatches.add(result2);
start = match.end;
}
}
if (start < text.length) {
_ResultMatch result1 = _ResultMatch();
result1.isUrl = false;
result1.text = text.substring(start);
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: Colors.blue)));
} else {
widgets.add(TextSpan(
text: result.text,
style: style.copyWith(
color: isDarkMode ? Colors.white : Colors.black,
)));
}
}
return widgets;
}
@override
Widget build(BuildContext context) {
return RichText(
text: TextSpan(children: _getTextSpans(isDarkMode(context))),
);
}
}
class _LinkTextSpan extends TextSpan {
_LinkTextSpan({TextStyle? style, required String text, String? replace})
: super(
style: style,
text: replace,
recognizer: TapGestureRecognizer()
..onTap = () {
openUrl(text);
});
}
class _ResultMatch {
late bool isUrl;
late String text;
}