2019-09-27 12:23:47 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2019-10-06 15:27:00 +02:00
|
|
|
import 'package:git_touch/screens/user.dart';
|
2019-09-27 12:23:47 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
|
|
|
|
class TextContainsOrganization extends StatelessWidget {
|
|
|
|
final String text;
|
|
|
|
final TextStyle style;
|
|
|
|
final TextOverflow overflow;
|
|
|
|
|
|
|
|
TextContainsOrganization(this.text,
|
|
|
|
{this.style, this.overflow = TextOverflow.clip});
|
|
|
|
|
2019-09-27 12:32:38 +02:00
|
|
|
static final _reg = RegExp(r'@[\x00-\x7F]+');
|
2019-09-27 12:23:47 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final orgs = _reg.allMatches(text).map((m) => m.group(0)).toList();
|
|
|
|
final chunks = text.split(_reg);
|
|
|
|
|
|
|
|
List<TextSpan> spans = [];
|
|
|
|
for (var index in List.generate(orgs.length, (i) => (i))) {
|
|
|
|
if (chunks[index].isNotEmpty) {
|
|
|
|
spans.add(TextSpan(text: chunks[index]));
|
|
|
|
}
|
|
|
|
spans.add(createLinkSpan(context, orgs[index],
|
2019-10-06 15:27:00 +02:00
|
|
|
(_) => UserScreen(orgs[index].substring(1), isOrganization: true)));
|
2019-09-27 12:23:47 +02:00
|
|
|
}
|
|
|
|
if (chunks.last.isNotEmpty) {
|
|
|
|
spans.add(TextSpan(text: chunks.last));
|
|
|
|
}
|
|
|
|
|
|
|
|
return RichText(
|
|
|
|
text: TextSpan(children: spans, style: style), overflow: overflow);
|
|
|
|
}
|
|
|
|
}
|