2022-09-24 20:46:37 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2019-01-29 12:41:24 +01:00
|
|
|
import 'package:flutter/gestures.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2019-09-23 14:33:27 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-10-02 08:58:11 +02:00
|
|
|
import 'package:git_touch/widgets/border_view.dart';
|
2022-09-22 19:50:45 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
2019-09-13 17:34:19 +02:00
|
|
|
import 'package:intl/intl.dart';
|
2019-08-31 15:37:29 +02:00
|
|
|
import 'package:primer/primer.dart';
|
2019-09-23 14:33:27 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-11-02 16:56:10 +01:00
|
|
|
import 'package:tuple/tuple.dart';
|
2022-09-12 16:59:17 +02:00
|
|
|
import 'package:universal_io/io.dart';
|
2019-09-28 18:25:14 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2022-09-12 16:59:17 +02:00
|
|
|
|
2022-09-17 14:35:45 +02:00
|
|
|
export 'package:flutter/material.dart'
|
|
|
|
show Colors, Brightness, Card, ExpansionTile, IconButton; // TODO: remove
|
2021-02-14 15:17:22 +01:00
|
|
|
export 'package:flutter_vector_icons/flutter_vector_icons.dart'
|
|
|
|
show Octicons, Ionicons;
|
2019-01-28 14:32:01 +01:00
|
|
|
|
2022-09-12 16:59:17 +02:00
|
|
|
export 'extensions.dart';
|
|
|
|
|
2019-03-10 09:09:26 +01:00
|
|
|
class StorageKeys {
|
2020-01-16 05:45:04 +01:00
|
|
|
@deprecated
|
2019-03-10 09:09:26 +01:00
|
|
|
static const account = 'account';
|
2020-01-16 05:45:04 +01:00
|
|
|
@deprecated
|
2019-03-10 09:09:26 +01:00
|
|
|
static const github = 'github';
|
2022-09-17 14:46:39 +02:00
|
|
|
@deprecated
|
2020-01-16 05:52:47 +01:00
|
|
|
static const iTheme = 'theme';
|
2022-09-17 15:57:43 +02:00
|
|
|
|
|
|
|
static const accounts = 'accounts';
|
2020-01-16 05:52:47 +01:00
|
|
|
static const iBrightness = 'brightness';
|
|
|
|
static const codeTheme = 'code-theme';
|
|
|
|
static const codeThemeDark = 'code-theme-dark';
|
|
|
|
static const iCodeFontSize = 'code-font-size';
|
|
|
|
static const codeFontFamily = 'code-font-family';
|
2021-02-14 03:27:34 +01:00
|
|
|
static const iMarkdown = 'markdown';
|
|
|
|
static const iDefaultAccount = 'default-account';
|
2021-02-14 05:05:41 +01:00
|
|
|
static const locale = 'locale';
|
2020-05-01 12:05:49 +02:00
|
|
|
|
|
|
|
static getDefaultStartTabKey(String platform) =>
|
|
|
|
'default-start-tab-$platform';
|
2019-03-10 09:09:26 +01:00
|
|
|
}
|
|
|
|
|
2019-10-02 10:09:54 +02:00
|
|
|
class CommonStyle {
|
2020-01-11 10:57:22 +01:00
|
|
|
static const padding = EdgeInsets.symmetric(horizontal: 16, vertical: 12);
|
2022-09-06 18:28:12 +02:00
|
|
|
static const border = BorderView();
|
2019-10-02 10:09:54 +02:00
|
|
|
static const verticalGap = SizedBox(height: 18);
|
|
|
|
static final monospace = Platform.isIOS ? 'Menlo' : 'monospace'; // FIXME:
|
|
|
|
}
|
|
|
|
|
2019-09-23 14:33:27 +02:00
|
|
|
TextSpan createLinkSpan(
|
|
|
|
BuildContext context,
|
2021-05-16 09:16:35 +02:00
|
|
|
String? text,
|
2019-12-12 13:29:56 +01:00
|
|
|
String url,
|
2019-09-23 14:33:27 +02:00
|
|
|
) {
|
2019-12-21 10:26:26 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2019-01-29 12:41:24 +01:00
|
|
|
return TextSpan(
|
|
|
|
text: text,
|
2019-09-24 13:58:34 +02:00
|
|
|
style: TextStyle(
|
2022-09-24 20:46:37 +02:00
|
|
|
color: AntTheme.of(context).colorPrimary,
|
2019-09-24 13:58:34 +02:00
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
2019-02-11 17:31:06 +01:00
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
..onTap = () {
|
2022-09-22 19:50:45 +02:00
|
|
|
context.pushUrl(url);
|
2019-02-11 17:31:06 +01:00
|
|
|
},
|
2019-01-29 12:41:24 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-02 16:56:10 +01:00
|
|
|
Tuple2<String, String> parseRepositoryFullName(String fullName) {
|
|
|
|
final ls = fullName.split('/');
|
|
|
|
assert(ls.length == 2);
|
|
|
|
return Tuple2(ls[0], ls[1]);
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:22:41 +01:00
|
|
|
class GithubPalette {
|
2019-11-08 13:23:09 +01:00
|
|
|
static const open = Color(0xff2cbe4e);
|
|
|
|
static const closed = PrimerColors.red600;
|
|
|
|
static const merged = PrimerColors.purple500;
|
2019-01-28 14:32:01 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
// final pageSize = 5;
|
2022-09-06 18:28:12 +02:00
|
|
|
const PAGE_SIZE = 30;
|
2019-01-28 14:32:01 +01:00
|
|
|
|
2019-09-03 15:39:00 +02:00
|
|
|
List<T> join<T>(T seperator, List<T> xs) {
|
2022-09-24 07:41:46 +02:00
|
|
|
final result = <T>[];
|
2019-09-03 15:39:00 +02:00
|
|
|
xs.asMap().forEach((index, x) {
|
|
|
|
if (x == null) return;
|
|
|
|
|
|
|
|
result.add(x);
|
|
|
|
if (index < xs.length - 1) {
|
|
|
|
result.add(seperator);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<T> joinAll<T>(T seperator, List<List<T>> xss) {
|
2022-09-24 07:41:46 +02:00
|
|
|
final result = <T>[];
|
2019-09-03 15:39:00 +02:00
|
|
|
xss.asMap().forEach((index, x) {
|
2021-06-13 19:23:16 +02:00
|
|
|
if (x.isEmpty) return;
|
2019-09-03 15:39:00 +02:00
|
|
|
|
|
|
|
result.addAll(x);
|
|
|
|
if (index < xss.length - 1) {
|
|
|
|
result.add(seperator);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-13 17:34:19 +02:00
|
|
|
final numberFormat = NumberFormat();
|
|
|
|
|
2021-05-16 09:16:35 +02:00
|
|
|
bool isNotNullOrEmpty(String? text) {
|
2019-09-14 17:48:01 +02:00
|
|
|
return text != null && text.isNotEmpty;
|
|
|
|
}
|
|
|
|
|
2022-09-20 20:00:03 +02:00
|
|
|
Future<void> launchStringUrl(String? url) async {
|
2019-09-29 07:32:53 +02:00
|
|
|
if (url == null) return;
|
|
|
|
|
2022-09-06 18:40:53 +02:00
|
|
|
final uri = Uri.parse(url);
|
|
|
|
if (await canLaunchUrl(uri)) {
|
|
|
|
await launchUrl(uri);
|
2019-09-29 07:32:53 +02:00
|
|
|
} else {
|
|
|
|
// TODO: fallback
|
|
|
|
}
|
|
|
|
}
|
2019-12-13 06:13:45 +01:00
|
|
|
|
2020-01-01 08:58:49 +01:00
|
|
|
final dateFormat = DateFormat.yMMMMd();
|
2020-01-29 11:50:17 +01:00
|
|
|
|
2020-01-30 12:24:59 +01:00
|
|
|
int sortByKey<T>(T key, T a, T b) {
|
|
|
|
if (a == key && b != key) return -1;
|
|
|
|
if (a != key && b == key) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-30 18:41:51 +02:00
|
|
|
|
|
|
|
const TOTAL_COUNT_FALLBACK = 999; // TODO:
|
2021-06-13 20:13:11 +02:00
|
|
|
|
|
|
|
class ListPayload<T, K> {
|
|
|
|
ListPayload({
|
|
|
|
required this.cursor,
|
|
|
|
required this.hasMore,
|
2021-06-14 05:28:12 +02:00
|
|
|
required this.items,
|
2021-06-13 20:13:11 +02:00
|
|
|
});
|
2022-09-21 18:28:21 +02:00
|
|
|
K cursor;
|
|
|
|
bool hasMore;
|
|
|
|
Iterable<T> items;
|
2021-06-13 20:13:11 +02:00
|
|
|
}
|
2022-09-22 19:50:45 +02:00
|
|
|
|
|
|
|
extension MyHelper on BuildContext {
|
2022-09-23 20:22:17 +02:00
|
|
|
Future<void> pushUrl(String url, {bool replace = false}) async {
|
2022-09-22 19:50:45 +02:00
|
|
|
// Fimber.d(url);
|
|
|
|
if (url.startsWith('/')) {
|
|
|
|
if (replace) {
|
|
|
|
this.replace(url);
|
|
|
|
} else {
|
|
|
|
push(url);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
launchStringUrl(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|