refactor: screen constructor

This commit is contained in:
Rongjian Zhang 2019-11-03 00:02:41 +08:00
parent 60b68bc61c
commit fd206993a1
9 changed files with 39 additions and 57 deletions

View File

@ -20,17 +20,12 @@ $key: reactions(content: $key) {
/// Screen for issue and pull request
class IssueScreen extends StatefulWidget {
final int number;
final String owner;
final String name;
final int number;
final bool isPullRequest;
IssueScreen({
@required this.number,
@required this.owner,
@required this.name,
this.isPullRequest = false,
});
IssueScreen(this.owner, this.name, this.number, {this.isPullRequest = false});
@override
_IssueScreenState createState() => _IssueScreenState();

View File

@ -14,11 +14,7 @@ class IssuesScreen extends StatelessWidget {
final String name;
final bool isPullRequest;
IssuesScreen({
@required this.owner,
@required this.name,
this.isPullRequest = false,
});
IssuesScreen(this.owner, this.name, {this.isPullRequest = false});
Future<ListPayload> _query(BuildContext context, [String cursor]) async {
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';

View File

@ -26,13 +26,8 @@ class ObjectScreen extends StatelessWidget {
final List<String> paths;
final String type;
ObjectScreen({
@required this.owner,
@required this.name,
@required this.branch,
this.paths = const [],
this.type = 'tree',
});
ObjectScreen(this.owner, this.name, this.branch,
{this.paths = const [], this.type = 'tree'});
String get _expression => '$branch:$_path';
String get _extname {
@ -100,9 +95,9 @@ class ObjectScreen extends StatelessWidget {
screenBuilder: (_) {
if (item['type'] == 'commit') return null;
return ObjectScreen(
name: name,
owner: owner,
branch: branch,
owner,
name,
branch,
paths: [...paths, item['name']],
type: item['type'],
);

View File

@ -233,9 +233,9 @@ class RepositoryScreen extends StatelessWidget {
rightWidget:
Text(filesize((repo['diskUsage'] as int) * 1000)),
screenBuilder: (_) => ObjectScreen(
owner: owner,
name: name,
branch: repo[branchInfoKey]['name'],
owner,
name,
repo[branchInfoKey]['name'] as String,
),
),
if (repo['hasIssuesEnabled'] as bool)
@ -244,16 +244,15 @@ class RepositoryScreen extends StatelessWidget {
text: Text('Issues'),
rightWidget:
Text(numberFormat.format(repo['issues']['totalCount'])),
screenBuilder: (_) =>
IssuesScreen(owner: owner, name: name),
screenBuilder: (_) => IssuesScreen(owner, name),
),
TableViewItem(
leftIconData: Octicons.git_pull_request,
text: Text('Pull requests'),
rightWidget: Text(
numberFormat.format(repo['pullRequests']['totalCount'])),
screenBuilder: (_) => IssuesScreen(
owner: owner, name: name, isPullRequest: true),
screenBuilder: (_) =>
IssuesScreen(owner, name, isPullRequest: true),
),
TableViewItem(
leftIconData: Octicons.project,

View File

@ -44,8 +44,8 @@ class ActionItem {
ActionItem.issue(String owner, String name, int number)
: text = '#$number',
onPress = ((context) {
Provider.of<ThemeModel>(context).pushRoute(context,
(_) => IssueScreen(owner: owner, name: name, number: number));
Provider.of<ThemeModel>(context)
.pushRoute(context, (_) => IssueScreen(owner, name, number));
});
}

View File

@ -232,9 +232,9 @@ class EventItem extends StatelessWidget {
detail: event.payload['comment']['body'],
iconData: Octicons.comment_discussion,
screenBuilder: (_) => IssueScreen(
owner: event.repoOwner,
name: event.repoName,
number: number,
event.repoOwner,
event.repoName,
number,
isPullRequest: isPullRequest,
),
actionItems: [
@ -258,11 +258,8 @@ class EventItem extends StatelessWidget {
],
iconData: Octicons.issue_opened,
detail: event.payload['issue']['title'],
screenBuilder: (_) => IssueScreen(
owner: event.repoOwner,
name: event.repoName,
number: number,
),
screenBuilder: (_) =>
IssueScreen(event.repoOwner, event.repoName, number),
actionItems: [
ActionItem.user(event.actorLogin),
ActionItem.user(event.repoOwner),
@ -299,9 +296,9 @@ class EventItem extends StatelessWidget {
iconData: Octicons.git_pull_request,
detail: event.payload['pull_request']['title'],
screenBuilder: (_) => IssueScreen(
owner: event.repoOwner,
name: event.repoName,
number: number,
event.repoOwner,
event.repoName,
number,
isPullRequest: true,
),
actionItems: [
@ -327,9 +324,9 @@ class EventItem extends StatelessWidget {
],
detail: event.payload['comment']['body'],
screenBuilder: (_) => IssueScreen(
owner: event.repoOwner,
name: event.repoName,
number: number,
event.repoOwner,
event.repoName,
number,
isPullRequest: true,
),
actionItems: [

View File

@ -43,9 +43,9 @@ class IssueItem extends StatelessWidget {
return Link(
screenBuilder: (context) {
return IssueScreen(
number: payload['number'],
owner: payload['repository']['owner']['login'],
name: payload['repository']['name'],
payload['repository']['owner']['login'] as String,
payload['repository']['name'] as String,
payload['number'] as int,
isPullRequest: isPullRequest,
);
},

View File

@ -38,9 +38,9 @@ class MarkdownView extends StatelessWidget {
return Provider.of<ThemeModel>(context).pushRoute(
context,
(_) => IssueScreen(
owner: m['owner'],
name: m['name'],
number: int.parse(m['number']),
m['owner'],
m['name'],
int.parse(m['number']),
isPullRequest: true,
));
}
@ -50,9 +50,9 @@ class MarkdownView extends StatelessWidget {
return Provider.of<ThemeModel>(context).pushRoute(
context,
(_) => IssueScreen(
owner: m['owner'],
name: m['name'],
number: int.parse(m['number']),
m['owner'],
m['name'],
int.parse(m['number']),
));
}

View File

@ -106,9 +106,9 @@ class _NotificationItemState extends State<NotificationItem> {
Provider.of<ThemeModel>(context).pushRoute(
context,
(_) => IssueScreen(
number: payload.number,
owner: payload.owner,
name: payload.name,
payload.owner,
payload.name,
payload.number,
isPullRequest: payload.type == 'PullRequest',
));