mirror of
https://github.com/git-touch/git-touch
synced 2024-12-17 02:38:39 +01:00
refactor: drop screen builder
This commit is contained in:
parent
3802faaf51
commit
d71d67aa9f
@ -15,9 +15,10 @@ import 'package:git_touch/screens/object.dart';
|
||||
import 'package:git_touch/screens/pull.dart';
|
||||
import 'package:git_touch/screens/pulls.dart';
|
||||
import 'package:git_touch/screens/repository.dart';
|
||||
import 'package:git_touch/screens/repositories.dart';
|
||||
import 'package:git_touch/screens/settings.dart';
|
||||
import 'package:git_touch/screens/stargazers.dart';
|
||||
import 'package:git_touch/screens/user.dart';
|
||||
import 'package:git_touch/screens/watchers.dart';
|
||||
import 'package:primer/primer.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:git_touch/models/notification.dart';
|
||||
@ -245,6 +246,8 @@ void main() async {
|
||||
commitsRouter,
|
||||
objectRouter,
|
||||
issueAddRouter,
|
||||
stargazersRouter,
|
||||
watchersRouter,
|
||||
gitlabIssueRouter
|
||||
];
|
||||
|
||||
|
@ -5,7 +5,6 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/graphql/github_repository.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/screens/users.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/markdown_view.dart';
|
||||
@ -148,14 +147,12 @@ class RepositoryScreen extends StatelessWidget {
|
||||
EntryItem(
|
||||
count: repo.watchers.totalCount,
|
||||
text: 'Watchers',
|
||||
screenBuilder: (context) =>
|
||||
UsersScreen(owner, UsersScreenType.watch, repoName: name),
|
||||
url: '/$owner/$name/watchers',
|
||||
),
|
||||
EntryItem(
|
||||
count: repo.stargazers.totalCount,
|
||||
text: 'Stars',
|
||||
screenBuilder: (context) =>
|
||||
UsersScreen(owner, UsersScreenType.star, repoName: name),
|
||||
url: '/$owner/$name/stargazers',
|
||||
),
|
||||
EntryItem(
|
||||
count: repo.forks.totalCount,
|
||||
|
20
lib/screens/stargazers.dart
Normal file
20
lib/screens/stargazers.dart
Normal file
@ -0,0 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/screens/users.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
|
||||
final stargazersRouter =
|
||||
RouterScreen('/:owner/:name/stargazers', (context, params) {
|
||||
return StargazersScreen(params['owner'].first, params['name'].first);
|
||||
});
|
||||
|
||||
class StargazersScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
|
||||
StargazersScreen(this.owner, this.name);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return UsersScreen(owner, UsersScreenType.star, repoName: name);
|
||||
}
|
||||
}
|
19
lib/screens/stars.dart
Normal file
19
lib/screens/stars.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/screens/users.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
|
||||
final starsRouter = RouterScreen('/:owner/:name/watchers', (context, params) {
|
||||
return StarsScreen(params['owner'].first, params['name'].first);
|
||||
});
|
||||
|
||||
class StarsScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String login;
|
||||
|
||||
StarsScreen(this.owner, this.login);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return UsersScreen(login, UsersScreenType.watch, repoName: owner);
|
||||
}
|
||||
}
|
@ -21,7 +21,26 @@ import 'package:git_touch/widgets/action_button.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
final userRouter = RouterScreen(
|
||||
'/:login', (context, parameters) => UserScreen(parameters['login'].first));
|
||||
'/:login',
|
||||
(context, parameters) {
|
||||
final login = parameters['login'].first;
|
||||
final tab = parameters['tab'].first;
|
||||
switch (tab) {
|
||||
case 'followers':
|
||||
return UsersScreen(login, UsersScreenType.follower);
|
||||
case 'following':
|
||||
return UsersScreen(login, UsersScreenType.following);
|
||||
case 'people':
|
||||
return UsersScreen(login, UsersScreenType.member);
|
||||
case 'stars':
|
||||
return RepositoriesScreen.stars(login);
|
||||
case 'repositories':
|
||||
return RepositoriesScreen(login);
|
||||
default:
|
||||
return UserScreen(parameters['login'].first);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
class UserScreen extends StatelessWidget {
|
||||
final String login;
|
||||
@ -79,6 +98,7 @@ class UserScreen extends StatelessWidget {
|
||||
Widget _buildUser(BuildContext context, GithubUserUser user,
|
||||
List<ContributionsInfo> contributions) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
final login = user.login;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
@ -94,24 +114,22 @@ class UserScreen extends StatelessWidget {
|
||||
EntryItem(
|
||||
count: user.repositories.totalCount,
|
||||
text: 'Repositories',
|
||||
screenBuilder: (context) => RepositoriesScreen(user.login),
|
||||
url: '/$login?tab=repositories',
|
||||
),
|
||||
EntryItem(
|
||||
count: user.starredRepositories.totalCount,
|
||||
text: 'Stars',
|
||||
screenBuilder: (context) => RepositoriesScreen.stars(user.login),
|
||||
url: '/$login?tab=stars',
|
||||
),
|
||||
EntryItem(
|
||||
count: user.followers.totalCount,
|
||||
text: 'Followers',
|
||||
screenBuilder: (context) =>
|
||||
UsersScreen(user.login, UsersScreenType.follower),
|
||||
url: '/$login?tab=followers',
|
||||
),
|
||||
EntryItem(
|
||||
count: user.following.totalCount,
|
||||
text: 'Following',
|
||||
screenBuilder: (context) =>
|
||||
UsersScreen(user.login, UsersScreenType.following),
|
||||
url: '/$login?tab=following',
|
||||
),
|
||||
]),
|
||||
CommonStyle.verticalGap,
|
||||
@ -187,13 +205,12 @@ class UserScreen extends StatelessWidget {
|
||||
EntryItem(
|
||||
count: payload.pinnableItems.totalCount,
|
||||
text: 'Repositories',
|
||||
screenBuilder: (context) => RepositoriesScreen(payload.login),
|
||||
url: '/$login?tab=repositories',
|
||||
),
|
||||
EntryItem(
|
||||
count: payload.membersWithRole.totalCount,
|
||||
text: 'Members',
|
||||
screenBuilder: (context) =>
|
||||
UsersScreen(payload.login, UsersScreenType.member),
|
||||
url: '/$login?tab=people',
|
||||
),
|
||||
]),
|
||||
CommonStyle.verticalGap,
|
||||
|
20
lib/screens/watchers.dart
Normal file
20
lib/screens/watchers.dart
Normal file
@ -0,0 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/screens/users.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
|
||||
final watchersRouter =
|
||||
RouterScreen('/:owner/:name/watchers', (context, params) {
|
||||
return WatchersScreen(params['owner'].first, params['name'].first);
|
||||
});
|
||||
|
||||
class WatchersScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
|
||||
WatchersScreen(this.owner, this.name);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return UsersScreen(owner, UsersScreenType.watch, repoName: name);
|
||||
}
|
||||
}
|
@ -7,13 +7,11 @@ import 'link.dart';
|
||||
class EntryItem extends StatelessWidget {
|
||||
final int count;
|
||||
final String text;
|
||||
final WidgetBuilder screenBuilder;
|
||||
final String url;
|
||||
|
||||
EntryItem({
|
||||
@required this.count,
|
||||
@required this.text,
|
||||
this.screenBuilder,
|
||||
this.url,
|
||||
});
|
||||
|
||||
@ -23,6 +21,7 @@ class EntryItem extends StatelessWidget {
|
||||
|
||||
return Expanded(
|
||||
child: Link(
|
||||
url: url,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 14),
|
||||
child: Column(
|
||||
@ -46,7 +45,6 @@ class EntryItem extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
url: url,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user