2019-01-28 14:32:01 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-01-29 12:41:24 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/gestures.dart';
|
2019-02-05 13:57:05 +01:00
|
|
|
import '../providers/settings.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../screens/repo.dart';
|
2019-01-26 15:10:18 +01:00
|
|
|
export 'github.dart';
|
|
|
|
export 'octicons.dart';
|
|
|
|
export 'timeago.dart';
|
2019-01-28 14:32:01 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
// These keys are for development
|
|
|
|
var clientId = '9b7d1cc04a1db5710767';
|
|
|
|
var clientSecret = '710e085908dde6a8b55f7a9dc447ad5c0c5617d1';
|
|
|
|
|
2019-02-04 11:32:39 +01:00
|
|
|
Color convertColor(String cssHex) {
|
|
|
|
if (cssHex.startsWith('#')) {
|
|
|
|
cssHex = cssHex.substring(1);
|
|
|
|
}
|
|
|
|
return Color(int.parse('ff' + cssHex, radix: 16));
|
|
|
|
}
|
|
|
|
|
2019-02-05 13:57:05 +01:00
|
|
|
class Option<T> {
|
|
|
|
final T value;
|
|
|
|
final Widget widget;
|
|
|
|
Option({this.value, this.widget});
|
|
|
|
}
|
|
|
|
|
2019-02-07 13:28:48 +01:00
|
|
|
Future<bool> showConfirm(BuildContext context, String text) {
|
2019-02-07 07:35:19 +01:00
|
|
|
switch (SettingsProvider.of(context).theme) {
|
|
|
|
case ThemeMap.cupertino:
|
2019-02-06 06:06:11 +01:00
|
|
|
return showCupertinoDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return CupertinoAlertDialog(
|
|
|
|
title: Text(text),
|
|
|
|
actions: <Widget>[
|
|
|
|
CupertinoDialogAction(
|
|
|
|
child: const Text('cancel'),
|
|
|
|
isDefaultAction: true,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, false);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
CupertinoDialogAction(
|
|
|
|
child: const Text('OK'),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
content: Text(
|
|
|
|
text,
|
|
|
|
// style: dialogTextStyle
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
|
|
|
child: const Text('CANCEL'),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, false);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: const Text('OK'),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 13:57:05 +01:00
|
|
|
Future<T> showOptions<T>(BuildContext context, List<Option<T>> options) {
|
|
|
|
var builder = (BuildContext context) {
|
|
|
|
return CupertinoAlertDialog(
|
|
|
|
actions: options.map((option) {
|
|
|
|
return CupertinoDialogAction(
|
|
|
|
child: option.widget,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, option.value);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
switch (SettingsProvider.of(context).theme) {
|
|
|
|
case ThemeMap.cupertino:
|
2019-02-05 13:57:05 +01:00
|
|
|
return showCupertinoDialog<T>(
|
|
|
|
context: context,
|
|
|
|
builder: builder,
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return Dialog(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
PopupMenuItem(child: Text('a')),
|
|
|
|
PopupMenuItem(child: Text('b')),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:41:24 +01:00
|
|
|
TextSpan createLinkSpan(BuildContext context, String text, Function handle) {
|
|
|
|
return TextSpan(
|
|
|
|
text: text,
|
2019-02-02 17:28:51 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: Color(0xff0366d6),
|
|
|
|
fontWeight: FontWeight.w600,
|
2019-02-03 08:50:17 +01:00
|
|
|
// decoration: TextDecoration.underline,
|
2019-02-02 17:28:51 +01:00
|
|
|
),
|
2019-01-29 12:41:24 +01:00
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
..onTap = () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
CupertinoPageRoute(
|
|
|
|
builder: (context) {
|
|
|
|
return handle();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextSpan createRepoLinkSpan(BuildContext context, String owner, String name) {
|
|
|
|
return createLinkSpan(context, '$owner/$name', () => RepoScreen(owner, name));
|
|
|
|
}
|
|
|
|
|
2019-01-28 14:32:01 +01:00
|
|
|
class Palette {
|
2019-02-06 12:14:11 +01:00
|
|
|
static const green = Color(0xff2cbe4e);
|
|
|
|
static const purple = Color(0xff6f42c1);
|
|
|
|
static const red = Color(0xffcb2431);
|
|
|
|
static const gray = Color(0xff959da5);
|
2019-01-28 14:32:01 +01:00
|
|
|
}
|
|
|
|
|
2019-02-03 07:42:50 +01:00
|
|
|
final pageSize = 20;
|
2019-01-28 14:32:01 +01:00
|
|
|
|
|
|
|
final graphqlChunk1 = '''
|
|
|
|
title
|
|
|
|
createdAt
|
|
|
|
body
|
|
|
|
author {
|
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
''';
|
|
|
|
|
|
|
|
var graghqlChunk = '''
|
|
|
|
__typename
|
|
|
|
|
|
|
|
... on IssueComment {
|
|
|
|
createdAt
|
|
|
|
body
|
|
|
|
author {
|
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on Commit {
|
|
|
|
committedDate
|
|
|
|
oid
|
|
|
|
author {
|
|
|
|
user {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on ReferencedEvent {
|
|
|
|
createdAt
|
|
|
|
isCrossRepository
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
commit {
|
|
|
|
oid
|
|
|
|
url
|
|
|
|
}
|
|
|
|
commitRepository {
|
|
|
|
owner {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on RenamedTitleEvent {
|
|
|
|
createdAt
|
|
|
|
previousTitle
|
|
|
|
currentTitle
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on ClosedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on ReopenedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on CrossReferencedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
source {
|
|
|
|
__typename
|
|
|
|
... on Issue {
|
|
|
|
number
|
|
|
|
repository {
|
|
|
|
owner {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on PullRequest {
|
|
|
|
number
|
|
|
|
repository {
|
|
|
|
owner {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-29 06:34:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
... on LabeledEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
label {
|
|
|
|
name
|
|
|
|
color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on UnlabeledEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
label {
|
|
|
|
name
|
|
|
|
color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on MilestonedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
milestoneTitle
|
|
|
|
}
|
|
|
|
|
|
|
|
... on LockedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
lockReason
|
|
|
|
}
|
|
|
|
... on UnlockedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on AssignedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
user {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 14:32:01 +01:00
|
|
|
''';
|
|
|
|
|
2019-01-29 06:34:52 +01:00
|
|
|
var createWarning =
|
|
|
|
(String text) => Text(text, style: TextStyle(color: Colors.redAccent));
|
2019-01-28 14:32:01 +01:00
|
|
|
var warningSpan =
|
|
|
|
TextSpan(text: 'xxx', style: TextStyle(color: Colors.redAccent));
|