mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 03:37:42 +01:00
fix(gh): text with at notation
This commit is contained in:
parent
1fe7e1fdc9
commit
2248415574
@ -10,7 +10,7 @@ import 'package:git_touch/widgets/mutation_button.dart';
|
||||
import 'package:git_touch/widgets/entry_item.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
import 'package:git_touch/widgets/text_contains_organization.dart';
|
||||
import 'package:git_touch/widgets/text_with_at.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/widgets/user_header.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -166,8 +166,9 @@ class GhUserScreen extends StatelessWidget {
|
||||
if (isNotNullOrEmpty(p.company))
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.organization,
|
||||
text: TextContainsOrganization(
|
||||
p.company,
|
||||
text: TextWithAt(
|
||||
text: p.company,
|
||||
linkFactory: (text) => '/github/' + text.substring(1),
|
||||
style: TextStyle(fontSize: 17, color: theme.palette.text),
|
||||
oneLine: true,
|
||||
),
|
||||
|
@ -1,27 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
|
||||
class TextContainsOrganization extends StatelessWidget {
|
||||
class TextWithAt extends StatelessWidget {
|
||||
final String text;
|
||||
final String Function(String text) linkFactory;
|
||||
final TextStyle style;
|
||||
final bool oneLine;
|
||||
|
||||
TextContainsOrganization(this.text, {this.style, this.oneLine = false});
|
||||
TextWithAt({
|
||||
@required this.text,
|
||||
@required this.linkFactory,
|
||||
this.style,
|
||||
this.oneLine = false,
|
||||
});
|
||||
|
||||
static final _reg = RegExp(r'@[A-Za-z-]+');
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final orgs = _reg.allMatches(text).map((m) => m.group(0)).toList();
|
||||
final matches = _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))) {
|
||||
for (var index in List.generate(matches.length, (i) => (i))) {
|
||||
if (chunks[index].isNotEmpty) {
|
||||
spans.add(TextSpan(text: chunks[index]));
|
||||
}
|
||||
spans.add(
|
||||
createLinkSpan(context, orgs[index], '/' + orgs[index].substring(1)));
|
||||
createLinkSpan(context, matches[index], linkFactory(matches[index])));
|
||||
}
|
||||
if (chunks.last.isNotEmpty) {
|
||||
spans.add(TextSpan(text: chunks.last));
|
Loading…
x
Reference in New Issue
Block a user