mirror of
https://github.com/git-touch/git-touch
synced 2025-01-27 14:19:24 +01:00
refactor: extract link tap screen builder
This commit is contained in:
parent
374a39c420
commit
74aa4a7ea5
@ -61,48 +61,51 @@ class NotificationScreenState extends State<NotificationScreen> {
|
||||
_groupMap[repo].items.add(item);
|
||||
});
|
||||
|
||||
var schema = '{';
|
||||
_groupMap.forEach((repo, group) {
|
||||
var repoKey = getRepoKey(group);
|
||||
schema +=
|
||||
'$repoKey: repository(owner: "${group.owner}", name: "${group.name}") {';
|
||||
if (_groupMap.isNotEmpty) {
|
||||
// query state of issues and pull requests
|
||||
var schema = '{';
|
||||
_groupMap.forEach((repo, group) {
|
||||
var repoKey = getRepoKey(group);
|
||||
schema +=
|
||||
'$repoKey: repository(owner: "${group.owner}", name: "${group.name}") {';
|
||||
|
||||
group.items.forEach((item) {
|
||||
var key = getItemKey(item);
|
||||
group.items.forEach((item) {
|
||||
var key = getItemKey(item);
|
||||
|
||||
switch (item.type) {
|
||||
case 'Issue':
|
||||
schema += '''
|
||||
switch (item.type) {
|
||||
case 'Issue':
|
||||
schema += '''
|
||||
$key: issue(number: ${item.number}) {
|
||||
state
|
||||
}
|
||||
''';
|
||||
break;
|
||||
case 'PullRequest':
|
||||
schema += '''
|
||||
break;
|
||||
case 'PullRequest':
|
||||
schema += '''
|
||||
$key: pullRequest(number: ${item.number}) {
|
||||
state
|
||||
}
|
||||
''';
|
||||
break;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
schema += '}';
|
||||
});
|
||||
schema += '}';
|
||||
});
|
||||
schema += '}';
|
||||
|
||||
// print(schema);
|
||||
var data = await SettingsProvider.of(context).query(schema);
|
||||
_groupMap.forEach((repo, group) {
|
||||
group.items.forEach((item) {
|
||||
var itemData = data[getRepoKey(group)][getItemKey(item)];
|
||||
if (itemData != null) {
|
||||
item.state = itemData['state'];
|
||||
}
|
||||
// print(schema);
|
||||
var data = await SettingsProvider.of(context).query(schema);
|
||||
_groupMap.forEach((repo, group) {
|
||||
group.items.forEach((item) {
|
||||
var itemData = data[getRepoKey(group)][getItemKey(item)];
|
||||
if (itemData != null) {
|
||||
item.state = itemData['state'];
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
// print(data);
|
||||
// print(data);
|
||||
}
|
||||
|
||||
return _groupMap;
|
||||
}
|
||||
@ -120,10 +123,10 @@ $key: pullRequest(number: ${item.number}) {
|
||||
style: TextStyle(color: Colors.black, fontSize: 15),
|
||||
),
|
||||
Link(
|
||||
onTap: () async {
|
||||
// await SettingsProvider.of(context)
|
||||
// .putWithCredentials('/repos/$repo/notifications');
|
||||
// await _refresh();
|
||||
beforeRedirect: () async {
|
||||
await SettingsProvider.of(context)
|
||||
.putWithCredentials('/repos/$repo/notifications');
|
||||
await _refresh();
|
||||
},
|
||||
child: Icon(
|
||||
Octicons.check,
|
||||
|
@ -113,16 +113,12 @@ class _RepoScreenState extends State<RepoScreen> {
|
||||
EntryItem(
|
||||
count: payload['issues']['totalCount'],
|
||||
text: 'Issues',
|
||||
route: CupertinoPageRoute(
|
||||
builder: (context) => IssuesScreen(),
|
||||
),
|
||||
screenBuilder: (context) => IssuesScreen(),
|
||||
),
|
||||
EntryItem(
|
||||
count: payload['pullRequests']['totalCount'],
|
||||
text: 'Pull Requests',
|
||||
route: CupertinoPageRoute(
|
||||
builder: (context) => PullRequestsScreen(),
|
||||
),
|
||||
screenBuilder: (context) => PullRequestsScreen(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -175,26 +175,22 @@ class _UserScreenState extends State<UserScreen> {
|
||||
EntryItem(
|
||||
count: payload['repositories']['totalCount'],
|
||||
text: 'Repositories',
|
||||
route:
|
||||
CupertinoPageRoute(builder: (context) => ReposScreen()),
|
||||
screenBuilder: (context) => ReposScreen(),
|
||||
),
|
||||
EntryItem(
|
||||
count: payload['starredRepositories']['totalCount'],
|
||||
text: 'Stars',
|
||||
route:
|
||||
CupertinoPageRoute(builder: (context) => ReposScreen()),
|
||||
screenBuilder: (context) => ReposScreen(),
|
||||
),
|
||||
EntryItem(
|
||||
count: payload['followers']['totalCount'],
|
||||
text: 'Followers',
|
||||
route:
|
||||
CupertinoPageRoute(builder: (context) => UsersScreen()),
|
||||
screenBuilder: (context) => UsersScreen(),
|
||||
),
|
||||
EntryItem(
|
||||
count: payload['following']['totalCount'],
|
||||
text: 'Following',
|
||||
route:
|
||||
CupertinoPageRoute(builder: (context) => UsersScreen()),
|
||||
screenBuilder: (context) => UsersScreen(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -17,10 +17,7 @@ class Avatar extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Link(
|
||||
onTap: () {
|
||||
Navigator.of(context)
|
||||
.push(CupertinoPageRoute(builder: (_) => UserScreen(login)));
|
||||
},
|
||||
screenBuilder: (_) => UserScreen(login),
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Colors.transparent,
|
||||
backgroundImage: NetworkImage(url),
|
||||
|
@ -4,9 +4,9 @@ import 'link.dart';
|
||||
class EntryItem extends StatelessWidget {
|
||||
final int count;
|
||||
final String text;
|
||||
final CupertinoPageRoute route;
|
||||
final WidgetBuilder screenBuilder;
|
||||
|
||||
EntryItem({this.count, this.text, this.route});
|
||||
EntryItem({this.count, this.text, this.screenBuilder});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -17,14 +17,12 @@ class EntryItem extends StatelessWidget {
|
||||
padding: EdgeInsets.symmetric(vertical: 10),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text(count.toString()),
|
||||
Text(count.toString(), style: TextStyle(fontSize: 18)),
|
||||
Text(text, style: TextStyle(fontSize: 13))
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context).push(route);
|
||||
},
|
||||
screenBuilder: screenBuilder,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -3,8 +3,9 @@ import 'package:flutter/cupertino.dart';
|
||||
import '../screens/issue.dart';
|
||||
import '../screens/pull_request.dart';
|
||||
import '../screens/user.dart';
|
||||
import '../utils/utils.dart';
|
||||
import 'link.dart';
|
||||
import 'avatar.dart';
|
||||
import '../utils/utils.dart';
|
||||
|
||||
class EventItem extends StatelessWidget {
|
||||
final Event event;
|
||||
@ -39,10 +40,7 @@ class EventItem extends StatelessWidget {
|
||||
}) {
|
||||
var _spans = [
|
||||
createLinkSpan(
|
||||
context,
|
||||
event.actor.login,
|
||||
() => UserScreen(event.actor.login),
|
||||
)
|
||||
context, event.actor.login, () => UserScreen(event.actor.login))
|
||||
];
|
||||
_spans.addAll(spans);
|
||||
|
||||
|
@ -1,24 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import '../providers/settings.dart';
|
||||
|
||||
class Link extends StatelessWidget {
|
||||
final Widget child;
|
||||
final GestureTapCallback onTap;
|
||||
final WidgetBuilder screenBuilder;
|
||||
final Function beforeRedirect;
|
||||
final Color bgColor;
|
||||
|
||||
Link({@required this.child, @required this.onTap, this.bgColor});
|
||||
Link({
|
||||
@required this.child,
|
||||
this.screenBuilder,
|
||||
this.beforeRedirect,
|
||||
this.bgColor,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var theme = SettingsProvider.of(context).theme;
|
||||
return Material(
|
||||
child: Ink(
|
||||
color: bgColor ?? Colors.white,
|
||||
child: InkWell(
|
||||
splashColor: SettingsProvider.of(context).theme == ThemeMap.cupertino
|
||||
? Colors.transparent
|
||||
: null,
|
||||
onTap: onTap,
|
||||
child: child,
|
||||
splashColor: theme == ThemeMap.cupertino ? Colors.transparent : null,
|
||||
onTap: () {
|
||||
if (beforeRedirect != null) {
|
||||
beforeRedirect();
|
||||
}
|
||||
|
||||
if (screenBuilder != null) {
|
||||
switch (theme) {
|
||||
case ThemeMap.cupertino:
|
||||
Navigator.of(context)
|
||||
.push(CupertinoPageRoute(builder: screenBuilder));
|
||||
break;
|
||||
default:
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: screenBuilder));
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -139,15 +139,15 @@ class _ListScaffoldState extends State<ListScaffold> {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: widget.title,
|
||||
trailing: Link(
|
||||
child: Icon(
|
||||
widget.trailingIconData,
|
||||
size: 24,
|
||||
color: Colors.blueAccent,
|
||||
),
|
||||
onTap: widget.trailingOnTap,
|
||||
bgColor: Colors.transparent,
|
||||
),
|
||||
// trailing: Link(
|
||||
// child: Icon(
|
||||
// widget.trailingIconData,
|
||||
// size: 24,
|
||||
// color: Colors.blueAccent,
|
||||
// ),
|
||||
// beforeRedirect: widget.trailingOnTap,
|
||||
// bgColor: Colors.transparent,
|
||||
// ),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: CustomScrollView(
|
||||
|
@ -52,7 +52,7 @@ class _NotificationItemState extends State<NotificationItem> {
|
||||
NotificationPayload get payload => widget.payload;
|
||||
bool loading = false;
|
||||
|
||||
Widget _buildRoute() {
|
||||
Widget _buildRoute(BuildContext context) {
|
||||
switch (payload.type) {
|
||||
case 'Issue':
|
||||
return IssueScreen(payload.number, payload.owner, payload.name);
|
||||
@ -132,12 +132,8 @@ class _NotificationItemState extends State<NotificationItem> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Link(
|
||||
onTap: () {
|
||||
_markAsRead();
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (context) => _buildRoute()),
|
||||
);
|
||||
},
|
||||
screenBuilder: _buildRoute,
|
||||
beforeRedirect: _markAsRead,
|
||||
child: Opacity(
|
||||
opacity: payload.unread ? 1 : 0.5,
|
||||
child: Container(
|
||||
@ -154,10 +150,7 @@ class _NotificationItemState extends State<NotificationItem> {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Link(
|
||||
child: _buildCheckIcon(),
|
||||
onTap: _markAsRead,
|
||||
),
|
||||
Link(child: _buildCheckIcon(), beforeRedirect: _markAsRead),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -22,14 +22,7 @@ class RepoItem extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Link(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
RepoScreen(item['owner']['login'], item['name']),
|
||||
),
|
||||
);
|
||||
},
|
||||
screenBuilder: (_) => RepoScreen(item['owner']['login'], item['name']),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Row(
|
||||
|
@ -17,11 +17,7 @@ class UserName extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Link(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (_) => UserScreen(login)),
|
||||
);
|
||||
},
|
||||
screenBuilder: (_) => UserScreen(login),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(2),
|
||||
decoration: BoxDecoration(
|
||||
|
Loading…
x
Reference in New Issue
Block a user