diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 2cddac3..2788743 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -161,7 +161,7 @@ class ListPayload { } extension MyHelper on BuildContext { - pushUrl(String url, {bool replace = false}) { + Future pushUrl(String url, {bool replace = false}) async { // Fimber.d(url); if (url.startsWith('/')) { if (replace) { diff --git a/lib/widgets/comment_item.dart b/lib/widgets/comment_item.dart index da0ea31..98bcaff 100644 --- a/lib/widgets/comment_item.dart +++ b/lib/widgets/comment_item.dart @@ -3,17 +3,16 @@ import 'package:git_touch/graphql/__generated__/github.data.gql.dart'; import 'package:git_touch/graphql/__generated__/schema.schema.gql.dart'; import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/theme.dart'; +import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/action_button.dart'; +import 'package:git_touch/widgets/avatar.dart'; +import 'package:git_touch/widgets/link.dart'; import 'package:git_touch/widgets/markdown_view.dart'; +import 'package:git_touch/widgets/user_name.dart'; import 'package:primer/primer.dart'; import 'package:provider/provider.dart'; import 'package:timeago/timeago.dart' as timeago; -import 'package:git_touch/utils/utils.dart'; -import 'package:git_touch/widgets/avatar.dart'; -import 'package:git_touch/widgets/link.dart'; -import 'package:git_touch/widgets/user_name.dart'; - class EmojiPayload { EmojiPayload({ required this.key, @@ -30,7 +29,6 @@ class EmojiPayload { typedef EmojiUpdateCallaback = void Function(GReactionContent data); class GhEmojiAction extends StatefulWidget { - GhEmojiAction(this.id, GReactableParts r, this.onReaction) : items = [ EmojiPayload( @@ -173,7 +171,8 @@ mutation { } } -class CommentItem extends StatelessWidget { // TODO +class CommentItem extends StatelessWidget { + // TODO const CommentItem({ required this.avatar, diff --git a/lib/widgets/commit_item.dart b/lib/widgets/commit_item.dart index 986cb20..80ed939 100644 --- a/lib/widgets/commit_item.dart +++ b/lib/widgets/commit_item.dart @@ -1,8 +1,8 @@ +import 'package:antd_mobile/antd_mobile.dart'; import 'package:flutter/widgets.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/avatar.dart'; -import 'package:git_touch/widgets/link.dart'; import 'package:provider/provider.dart'; import 'package:timeago/timeago.dart' as timeago; @@ -26,51 +26,49 @@ class CommitItem extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Provider.of(context); - return LinkWidget( - url: url, - child: Container( - padding: CommonStyle.padding, - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (avatarUrl != null) ...[ - Avatar(url: avatarUrl, linkUrl: avatarLink), - const SizedBox(width: 10), - ], - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - message!, - style: TextStyle( - fontSize: 17, - color: theme.palette.text, - ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - ), - const SizedBox(height: 4), - Row( - children: [ - Text(author!, - style: TextStyle( - fontSize: 15, color: theme.palette.primary)), - Text( - ' committed ${timeago.format(createdAt!)}', - style: TextStyle( - color: theme.palette.secondaryText, - fontSize: 15, - ), - ), - if (widgets != null) ...widgets!, - ], - ) - ], - ), - ) + return AntListItem( + onClick: () { + context.pushUrl(url!); + }, + child: Row( + children: [ + if (avatarUrl != null) ...[ + Avatar(url: avatarUrl, linkUrl: avatarLink), + const SizedBox(width: 10), ], - ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + message!, + style: TextStyle( + fontSize: 17, + color: theme.palette.text, + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + ), + const SizedBox(height: 4), + Row( + children: [ + Text(author!, + style: TextStyle( + fontSize: 15, color: theme.palette.primary)), + Text( + ' committed ${timeago.format(createdAt!)}', + style: TextStyle( + color: theme.palette.secondaryText, + fontSize: 15, + ), + ), + if (widgets != null) ...widgets!, + ], + ) + ], + ), + ) + ], ), ); } diff --git a/lib/widgets/contributor_item.dart b/lib/widgets/contributor_item.dart index 9a79a2c..e101963 100644 --- a/lib/widgets/contributor_item.dart +++ b/lib/widgets/contributor_item.dart @@ -1,12 +1,11 @@ +import 'package:antd_mobile/antd_mobile.dart'; import 'package:flutter/widgets.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/avatar.dart'; -import 'package:git_touch/widgets/link.dart'; import 'package:provider/provider.dart'; class ContributorItem extends StatelessWidget { - const ContributorItem({ required this.login, required this.avatarUrl, @@ -21,45 +20,44 @@ class ContributorItem extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Provider.of(context); - return LinkWidget( - url: url, - child: Container( - padding: CommonStyle.padding, - child: Row( - children: [ - Avatar(url: avatarUrl, size: AvatarSize.large), - const SizedBox(width: 10), - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Text( - login!, - style: TextStyle( - color: theme.palette.primary, - fontSize: 18, - fontWeight: FontWeight.w600, - ), - ), - ], - ), - const SizedBox(height: 6), - if (commits != null) - DefaultTextStyle( + return AntListItem( + onClick: () { + context.pushUrl(url); + }, + child: Row( + children: [ + Avatar(url: avatarUrl, size: AvatarSize.large), + const SizedBox(width: 10), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Text( + login!, style: TextStyle( - color: theme.palette.secondaryText, - fontSize: 16, + color: theme.palette.primary, + fontSize: 18, + fontWeight: FontWeight.w600, ), - child: Text('Commits: $commits'), ), - ], - ), - ) - ], - ), + ], + ), + const SizedBox(height: 6), + if (commits != null) + DefaultTextStyle( + style: TextStyle( + color: theme.palette.secondaryText, + fontSize: 16, + ), + child: Text('Commits: $commits'), + ), + ], + ), + ) + ], ), ); } diff --git a/lib/widgets/issue_item.dart b/lib/widgets/issue_item.dart index 6580088..6da9426 100644 --- a/lib/widgets/issue_item.dart +++ b/lib/widgets/issue_item.dart @@ -1,12 +1,11 @@ +import 'package:antd_mobile/antd_mobile.dart'; import 'package:flutter/widgets.dart'; import 'package:git_touch/models/theme.dart'; +import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/avatar.dart'; import 'package:provider/provider.dart'; import 'package:timeago/timeago.dart' as timeago; -import 'package:git_touch/utils/utils.dart'; -import 'package:git_touch/widgets/link.dart'; - const issueGqlChunk = ''' url number @@ -34,7 +33,6 @@ comments { '''; class IssueItem extends StatelessWidget { - const IssueItem({ required this.url, required this.subtitle, @@ -60,100 +58,90 @@ class IssueItem extends StatelessWidget { Widget build(BuildContext context) { final theme = Provider.of(context); - return LinkWidget( - url: url, - child: Container( - padding: CommonStyle.padding, - // color: payload.unread ? Colors.white : Colors.black12, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( + return AntListItem( + arrow: null, + onClick: () { + context.pushUrl(url!); + }, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(isPr ? Octicons.git_pull_request : Octicons.issue_opened, + color: GithubPalette.open, size: 20), + const SizedBox(width: 6), + Expanded( + child: Column( crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Icon(isPr ? Octicons.git_pull_request : Octicons.issue_opened, - color: GithubPalette.open, size: 20), - const SizedBox(width: 6), - Expanded( - child: Container( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: join(const SizedBox(height: 8), [ - Text.rich( - TextSpan( - children: [ - TextSpan(text: '$title '), - TextSpan( - text: subtitle, - style: TextStyle( - color: theme.palette.tertiaryText, - fontWeight: FontWeight.normal, - ), - ), - ], - ), - style: TextStyle( - fontSize: 17, - color: theme.palette.text, - fontWeight: FontWeight.w600, - ), + children: join(const SizedBox(height: 8), [ + Text.rich( + TextSpan( + children: [ + TextSpan(text: '$title '), + TextSpan( + text: subtitle, + style: TextStyle( + color: theme.palette.tertiaryText, + fontWeight: FontWeight.normal, ), - if (labels != null) labels!, - DefaultTextStyle( - style: TextStyle( - fontSize: 14, - color: theme.palette.secondaryText, - ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - // FIXME: Deleted user - if (avatarUrl != null) ...[ - Avatar( - size: AvatarSize.extraSmall, - url: avatarUrl, - ), - const SizedBox(width: 4), - Text( - author!, - style: const TextStyle( - fontWeight: FontWeight.w600), - ), - ], - Expanded( - child: Text( - ' opened ${timeago.format(updatedAt!)}', - style: TextStyle( - fontSize: 17, - color: theme.palette.secondaryText, - ), - overflow: TextOverflow.ellipsis, - )), - if (commentCount! > 0) ...[ - const Expanded(child: SizedBox()), - Icon(Octicons.comment, - size: 14, - color: theme.palette.secondaryText), - const SizedBox(width: 3), - Text(numberFormat.format(commentCount)) - ], - ], - ), - ) - ]), - ), + ), + ], + ), + style: TextStyle( + fontSize: 17, + color: theme.palette.text, + fontWeight: FontWeight.w600, ), ), - // Column( - // children: [ - // Icon(Octicons.check, color: Colors.black45), - // Icon(Octicons.unmute, color: Colors.black45) - // ], - // ), - ], + if (labels != null) labels!, + DefaultTextStyle( + style: TextStyle( + fontSize: 14, + color: theme.palette.secondaryText, + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + // FIXME: Deleted user + if (avatarUrl != null) ...[ + Avatar( + size: AvatarSize.extraSmall, + url: avatarUrl, + ), + const SizedBox(width: 4), + Text( + author!, + style: const TextStyle(fontWeight: FontWeight.w600), + ), + ], + Expanded( + child: Text( + ' opened ${timeago.format(updatedAt!)}', + style: TextStyle( + fontSize: 17, + color: theme.palette.secondaryText, + ), + overflow: TextOverflow.ellipsis, + )), + if (commentCount! > 0) ...[ + const Expanded(child: SizedBox()), + Icon(Octicons.comment, + size: 14, color: theme.palette.secondaryText), + const SizedBox(width: 3), + Text(numberFormat.format(commentCount)) + ], + ], + ), + ) + ]), ), - ], - ), + ), + // Column( + // children: [ + // Icon(Octicons.check, color: Colors.black45), + // Icon(Octicons.unmute, color: Colors.black45) + // ], + // ), + ], ), ); } diff --git a/lib/widgets/markdown_view.dart b/lib/widgets/markdown_view.dart index 0e5939f..8f28332 100644 --- a/lib/widgets/markdown_view.dart +++ b/lib/widgets/markdown_view.dart @@ -133,7 +133,7 @@ class MarkdownFlutterView extends StatelessWidget { var y = path.join(x, url); if (y.startsWith('/')) y = y.substring(1); - return context.pushUrl( + context.pushUrl( '/${basePaths![0]}/${basePaths![1]}/${basePaths![2]}?path=${y.urlencode}'); } @@ -148,7 +148,7 @@ class MarkdownFlutterView extends StatelessWidget { for (var p in matchedPaths) { final m = matchPattern(url, p); if (m != null) { - return context.pushUrl( + context.pushUrl( url.replaceFirst(RegExp(r'https://github.com'), '/github')); } } diff --git a/lib/widgets/repo_header.dart b/lib/widgets/repo_header.dart index 2d1b9fe..a74e26b 100644 --- a/lib/widgets/repo_header.dart +++ b/lib/widgets/repo_header.dart @@ -6,7 +6,6 @@ import 'package:git_touch/widgets/link.dart'; import 'package:provider/provider.dart'; class RepoHeader extends StatelessWidget { - const RepoHeader({ required this.avatarUrl, required this.avatarLink, diff --git a/lib/widgets/repository_item.dart b/lib/widgets/repository_item.dart index 95e5e33..137c565 100644 --- a/lib/widgets/repository_item.dart +++ b/lib/widgets/repository_item.dart @@ -1,3 +1,4 @@ +import 'package:antd_mobile/antd_mobile.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; import 'package:from_css_color/from_css_color.dart'; @@ -8,7 +9,6 @@ import 'package:git_touch/models/gogs.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/avatar.dart'; -import 'package:git_touch/widgets/link.dart'; import 'package:github/github.dart' as github; import 'package:provider/provider.dart'; import 'package:timeago/timeago.dart' as timeago; @@ -142,121 +142,113 @@ class RepositoryItem extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Provider.of(context); - return LinkWidget( - url: url, - child: Container( - padding: CommonStyle.padding, - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Avatar( - url: avatarUrl, - size: AvatarSize.small, - linkUrl: avatarLink, - ), - const SizedBox(width: 8), - Expanded( - child: Text.rich( - TextSpan(children: [ - TextSpan( - text: '$owner / ', - style: TextStyle( - fontSize: 18, - color: theme.palette.primary, - ), - ), - TextSpan( - text: name, - style: TextStyle( - fontSize: 18, - color: theme.palette.primary, - fontWeight: FontWeight.w600, - ), - // overflow: TextOverflow.ellipsis, - ), - ]), - overflow: TextOverflow.ellipsis, - ), - ), - if (iconData != null) ...[ - const SizedBox(width: 6), - DefaultTextStyle( - style: TextStyle(color: theme.palette.secondaryText), - child: Icon(iconData, - size: 18, color: theme.palette.secondaryText), - ), - ] - ], - ), - const SizedBox(height: 8), - if (description != null && description!.isNotEmpty) ...[ - Text( - description!, + return AntListItem( + arrow: null, + onClick: () { + context.pushUrl(url); + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Avatar( + url: avatarUrl, + size: AvatarSize.small, + linkUrl: avatarLink, + ), + const SizedBox(width: 8), + Expanded( + child: Text.rich( + TextSpan(children: [ + TextSpan( + text: '$owner / ', style: TextStyle( - color: theme.palette.secondaryText, - fontSize: 16, + fontSize: 18, + color: theme.palette.primary, ), ), - const SizedBox(height: 10), - ], - if (note != null) ...[ - Text( - note!, + TextSpan( + text: name, style: TextStyle( - fontSize: 14, - color: theme.palette.tertiaryText, + fontSize: 18, + color: theme.palette.primary, + fontWeight: FontWeight.w600, ), + // overflow: TextOverflow.ellipsis, ), - const SizedBox(height: 10), - ], - DefaultTextStyle( - style: TextStyle(color: theme.palette.text, fontSize: 14), - child: Row( - children: [ - if (primaryLanguageName != null) ...[ - Container( - width: 12, - height: 12, - decoration: BoxDecoration( - color: fromCssColor(primaryLanguageColor ?? - github.languageColors[primaryLanguageName!]!), - shape: BoxShape.circle, - ), - ), - const SizedBox(width: 4), - Text( - primaryLanguageName!, - overflow: TextOverflow.ellipsis, - ), - const SizedBox(width: 24), - ], - if (starCount! > 0) ...[ - Icon(Octicons.star, - size: 16, color: theme.palette.text), - const SizedBox(width: 2), - Text(numberFormat.format(starCount)), - const SizedBox(width: 24), - ], - if (forkCount! > 0) ...[ - Icon(Octicons.repo_forked, - size: 16, color: theme.palette.text), - const SizedBox(width: 2), - Text(numberFormat.format(forkCount)), - ], - ], - ), - ), - ], + ]), + overflow: TextOverflow.ellipsis, + ), + ), + if (iconData != null) ...[ + const SizedBox(width: 6), + DefaultTextStyle( + style: TextStyle(color: theme.palette.secondaryText), + child: Icon(iconData, + size: 18, color: theme.palette.secondaryText), + ), + ] + ], + ), + const SizedBox(height: 8), + if (description != null && description!.isNotEmpty) ...[ + Text( + description!, + style: TextStyle( + color: theme.palette.secondaryText, + fontSize: 16, ), ), + const SizedBox(height: 10), ], - ), + if (note != null) ...[ + Text( + note!, + style: TextStyle( + fontSize: 14, + color: theme.palette.tertiaryText, + ), + ), + const SizedBox(height: 10), + ], + DefaultTextStyle( + style: TextStyle(color: theme.palette.text, fontSize: 14), + child: Row( + children: [ + if (primaryLanguageName != null) ...[ + Container( + width: 12, + height: 12, + decoration: BoxDecoration( + color: fromCssColor(primaryLanguageColor ?? + github.languageColors[primaryLanguageName!]!), + shape: BoxShape.circle, + ), + ), + const SizedBox(width: 4), + Text( + primaryLanguageName!, + overflow: TextOverflow.ellipsis, + ), + const SizedBox(width: 24), + ], + if (starCount! > 0) ...[ + Icon(Octicons.star, size: 16, color: theme.palette.text), + const SizedBox(width: 2), + Text(numberFormat.format(starCount)), + const SizedBox(width: 24), + ], + if (forkCount! > 0) ...[ + Icon(Octicons.repo_forked, + size: 16, color: theme.palette.text), + const SizedBox(width: 2), + Text(numberFormat.format(forkCount)), + ], + ], + ), + ), + ], ), ); } diff --git a/lib/widgets/user_item.dart b/lib/widgets/user_item.dart index 5a52f61..427b78f 100644 --- a/lib/widgets/user_item.dart +++ b/lib/widgets/user_item.dart @@ -1,9 +1,9 @@ +import 'package:antd_mobile/antd_mobile.dart'; import 'package:flutter/widgets.dart'; import 'package:git_touch/graphql/__generated__/github.data.gql.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/avatar.dart'; -import 'package:git_touch/widgets/link.dart'; import 'package:provider/provider.dart'; const userGqlChunk = ''' @@ -52,7 +52,6 @@ class GhBioWidget extends StatelessWidget { } class UserItem extends StatelessWidget { - const UserItem.github({ required this.login, required this.name, @@ -126,61 +125,59 @@ class UserItem extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Provider.of(context); - return LinkWidget( - url: url, - child: Container( - padding: CommonStyle.padding, - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Avatar(url: avatarUrl, size: AvatarSize.large), - const SizedBox(width: 10), - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - textBaseline: TextBaseline.alphabetic, - crossAxisAlignment: CrossAxisAlignment.baseline, - children: [ - if (name != null && name!.isNotEmpty) ...[ - Text( - name!, - style: TextStyle( - color: theme.palette.text, - fontSize: 18, - fontWeight: FontWeight.w500, - ), - ), - const SizedBox(width: 8), - ], - Expanded( - child: Text( - login!, - style: TextStyle( - color: theme.palette.text, - fontSize: 16, - ), - overflow: TextOverflow.ellipsis, + return AntListItem( + onClick: () { + context.pushUrl(url); + }, + child: Row( + children: [ + Avatar(url: avatarUrl, size: AvatarSize.large), + const SizedBox(width: 10), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + textBaseline: TextBaseline.alphabetic, + crossAxisAlignment: CrossAxisAlignment.baseline, + children: [ + if (name != null && name!.isNotEmpty) ...[ + Text( + name!, + style: TextStyle( + color: theme.palette.text, + fontSize: 18, + fontWeight: FontWeight.w500, ), ), + const SizedBox(width: 8), ], - ), - const SizedBox(height: 6), - if (bio != null) - DefaultTextStyle( - style: TextStyle( - color: theme.palette.secondaryText, - fontSize: 16, + Expanded( + child: Text( + login!, + style: TextStyle( + color: theme.palette.text, + fontSize: 16, + ), + overflow: TextOverflow.ellipsis, ), - child: bio!, ), - ], - ), - ) - ], - ), + ], + ), + const SizedBox(height: 6), + if (bio != null) + DefaultTextStyle( + style: TextStyle( + color: theme.palette.secondaryText, + fontSize: 16, + ), + child: bio!, + ), + ], + ), + ) + ], ), ); }