mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 03:37:42 +01:00
feat: add button to quickly switch accounts (#36)
Co-authored-by: Rongjian Zhang <pd4d10@gmail.com>
This commit is contained in:
parent
c71c2da2ef
commit
62b02ed504
@ -56,6 +56,7 @@ class BbUserScreen extends StatelessWidget {
|
||||
avatarUrl: user.avatarUrl,
|
||||
name: user.displayName,
|
||||
createdAt: user.createdOn,
|
||||
isViewer: isViewer,
|
||||
bio: null,
|
||||
),
|
||||
CommonStyle.border,
|
||||
|
@ -115,7 +115,7 @@ class GhRepoScreen extends StatelessWidget {
|
||||
active: repo.viewerSubscription ==
|
||||
GhRepoSubscriptionState.SUBSCRIBED,
|
||||
text: _buildWatchState(repo.viewerSubscription),
|
||||
onPressed: () async {
|
||||
onTap: () async {
|
||||
final vs = GhRepoSubscriptionState.values.where((v) =>
|
||||
v != GhRepoSubscriptionState.ARTEMIS_UNKNOWN);
|
||||
theme.showActions(context, [
|
||||
@ -176,7 +176,7 @@ class GhRepoScreen extends StatelessWidget {
|
||||
MutationButton(
|
||||
active: repo.viewerHasStarred,
|
||||
text: repo.viewerHasStarred ? 'Unstar' : 'Star',
|
||||
onPressed: () async {
|
||||
onTap: () async {
|
||||
if (repo.viewerHasStarred) {
|
||||
await context
|
||||
.read<AuthModel>()
|
||||
|
@ -72,22 +72,24 @@ class GhUserScreen extends StatelessWidget {
|
||||
login: p.login,
|
||||
createdAt: p.createdAt,
|
||||
bio: p.bio,
|
||||
followWidget: p.viewerCanFollow == true
|
||||
? MutationButton(
|
||||
active: p.viewerIsFollowing,
|
||||
text: p.viewerIsFollowing ? 'Unfollow' : 'Follow',
|
||||
onPressed: () async {
|
||||
if (p.viewerIsFollowing) {
|
||||
await auth.ghClient.users.unfollowUser(p.login);
|
||||
} else {
|
||||
await auth.ghClient.users.followUser(p.login);
|
||||
}
|
||||
setState(() {
|
||||
p.viewerIsFollowing = !p.viewerIsFollowing;
|
||||
});
|
||||
},
|
||||
)
|
||||
: null,
|
||||
isViewer: isViewer,
|
||||
rightWidgets: [
|
||||
if (p.viewerCanFollow)
|
||||
MutationButton(
|
||||
active: p.viewerIsFollowing,
|
||||
text: p.viewerIsFollowing ? 'Unfollow' : 'Follow',
|
||||
onTap: () async {
|
||||
if (p.viewerIsFollowing) {
|
||||
await auth.ghClient.users.unfollowUser(p.login);
|
||||
} else {
|
||||
await auth.ghClient.users.followUser(p.login);
|
||||
}
|
||||
setState(() {
|
||||
p.viewerIsFollowing = !p.viewerIsFollowing;
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
CommonStyle.border,
|
||||
Row(children: [
|
||||
|
@ -50,6 +50,7 @@ class GlUserScreen extends StatelessWidget {
|
||||
name: user.name,
|
||||
createdAt: user.createdAt,
|
||||
bio: user.bio,
|
||||
isViewer: isViewer,
|
||||
),
|
||||
CommonStyle.border,
|
||||
Column(
|
||||
|
@ -105,6 +105,7 @@ class GtUserScreen extends StatelessWidget {
|
||||
avatarUrl: p.user.avatarUrl,
|
||||
name: p.user.fullName,
|
||||
createdAt: p.user.created,
|
||||
isViewer: isViewer,
|
||||
bio: '',
|
||||
),
|
||||
CommonStyle.border,
|
||||
|
@ -6,12 +6,14 @@ import 'package:provider/provider.dart';
|
||||
class MutationButton extends StatelessWidget {
|
||||
final bool active;
|
||||
final String text;
|
||||
final VoidCallback onPressed;
|
||||
final String url;
|
||||
final VoidCallback onTap;
|
||||
|
||||
MutationButton({
|
||||
@required this.active,
|
||||
@required this.text,
|
||||
@required this.onPressed,
|
||||
this.url,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -21,7 +23,8 @@ class MutationButton extends StatelessWidget {
|
||||
final backgroundColor =
|
||||
active ? theme.palette.primary : theme.palette.background;
|
||||
return Link(
|
||||
onTap: onPressed,
|
||||
url: url,
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.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/mutation_button.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class UserHeader extends StatelessWidget {
|
||||
@ -10,7 +11,7 @@ class UserHeader extends StatelessWidget {
|
||||
final String login;
|
||||
final DateTime createdAt;
|
||||
final String bio;
|
||||
final Widget followWidget;
|
||||
final List<Widget> rightWidgets;
|
||||
|
||||
UserHeader({
|
||||
@required this.avatarUrl,
|
||||
@ -18,8 +19,17 @@ class UserHeader extends StatelessWidget {
|
||||
@required this.login,
|
||||
@required this.createdAt,
|
||||
@required this.bio,
|
||||
this.followWidget,
|
||||
});
|
||||
bool isViewer = false,
|
||||
List<Widget> rightWidgets,
|
||||
}) : this.rightWidgets = [
|
||||
...(rightWidgets ?? []),
|
||||
if (isViewer)
|
||||
MutationButton(
|
||||
active: false,
|
||||
text: 'Switch accounts',
|
||||
url: '/login',
|
||||
)
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -32,9 +42,9 @@ class UserHeader extends StatelessWidget {
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Avatar(url: avatarUrl, size: AvatarSize.extraLarge),
|
||||
if (followWidget != null) ...[
|
||||
if (rightWidgets?.isNotEmpty) ...[
|
||||
Expanded(child: Container()),
|
||||
followWidget,
|
||||
...rightWidgets,
|
||||
]
|
||||
],
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user