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-08-31 15:37:29 +02:00
|
|
|
import 'package:primer/primer.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-02-15 07:41:19 +01:00
|
|
|
export 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
2019-01-28 14:32:01 +01:00
|
|
|
|
2019-03-10 09:09:26 +01:00
|
|
|
class StorageKeys {
|
|
|
|
static const account = 'account';
|
|
|
|
static const github = 'github';
|
|
|
|
static const theme = 'theme';
|
|
|
|
static const newsFilter = 'news.filter';
|
|
|
|
}
|
|
|
|
|
2019-02-04 11:32:39 +01:00
|
|
|
Color convertColor(String cssHex) {
|
|
|
|
if (cssHex.startsWith('#')) {
|
|
|
|
cssHex = cssHex.substring(1);
|
|
|
|
}
|
2019-03-12 12:00:31 +01:00
|
|
|
if (cssHex.length == 3) {
|
|
|
|
cssHex = cssHex.split('').map((char) => char + char).join('');
|
|
|
|
}
|
2019-02-04 11:32:39 +01:00
|
|
|
return Color(int.parse('ff' + cssHex, radix: 16));
|
|
|
|
}
|
|
|
|
|
2019-02-10 05:16:52 +01:00
|
|
|
void nextTick(Function callback, [int milliseconds = 0]) {
|
2019-02-08 16:20:28 +01:00
|
|
|
// FIXME:
|
2019-02-10 05:16:52 +01:00
|
|
|
Future.delayed(Duration(milliseconds: 0)).then((_) {
|
2019-02-08 03:48:25 +01:00
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-10 06:17:25 +01:00
|
|
|
class DialogOption<T> {
|
|
|
|
final T value;
|
|
|
|
final Widget widget;
|
|
|
|
DialogOption({this.value, this.widget});
|
|
|
|
}
|
|
|
|
|
2019-04-05 15:19:00 +02:00
|
|
|
Future<T> showDialogOptions<T>(
|
|
|
|
BuildContext context, List<DialogOption<T>> options) {
|
|
|
|
var title = Text('Pick your reaction');
|
|
|
|
var cancelWidget = Text('Cancel');
|
2019-02-05 13:57:05 +01:00
|
|
|
|
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,
|
2019-04-05 15:19:00 +02:00
|
|
|
builder: (BuildContext context) {
|
|
|
|
return CupertinoAlertDialog(
|
|
|
|
title: title,
|
|
|
|
actions: options.map((option) {
|
|
|
|
return CupertinoDialogAction(
|
|
|
|
child: option.widget,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, option.value);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}).toList()
|
|
|
|
..add(
|
|
|
|
CupertinoDialogAction(
|
|
|
|
child: cancelWidget,
|
|
|
|
isDestructiveAction: true,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, null);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2019-02-05 13:57:05 +01:00
|
|
|
);
|
|
|
|
default:
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
2019-04-05 15:19:00 +02:00
|
|
|
return SimpleDialog(
|
|
|
|
title: title,
|
|
|
|
children: options.map<Widget>((option) {
|
|
|
|
return SimpleDialogOption(
|
|
|
|
child: option.widget,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, option.value);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}).toList()
|
|
|
|
..add(SimpleDialogOption(
|
|
|
|
child: cancelWidget,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.pop(context, null);
|
|
|
|
},
|
|
|
|
)),
|
2019-02-05 13:57:05 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:41:24 +01:00
|
|
|
TextSpan createLinkSpan(BuildContext context, String text, Function handle) {
|
|
|
|
return TextSpan(
|
|
|
|
text: text,
|
2019-08-31 15:37:29 +02:00
|
|
|
style: TextStyle(fontWeight: FontWeight.w600),
|
2019-02-11 17:31:06 +01:00
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
..onTap = () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
CupertinoPageRoute(
|
|
|
|
builder: (context) {
|
|
|
|
return handle();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2019-01-29 12:41:24 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-01-28 14:32:01 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
// final pageSize = 5;
|
2019-02-09 07:20:21 +01:00
|
|
|
final pageSize = 30;
|
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));
|
2019-02-09 06:36:15 +01:00
|
|
|
|
|
|
|
var repoChunk = '''
|
|
|
|
owner {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
name
|
|
|
|
description
|
|
|
|
isPrivate
|
|
|
|
isFork
|
|
|
|
stargazers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
forks {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
primaryLanguage {
|
|
|
|
color
|
|
|
|
name
|
|
|
|
}
|
|
|
|
''';
|