git-touch-android-ios-app/lib/screens/settings.dart

205 lines
7.9 KiB
Dart
Raw Normal View History

2019-09-04 16:59:33 +02:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
2020-01-27 07:43:10 +01:00
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/theme.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/single.dart';
2019-09-04 16:59:33 +02:00
import 'package:git_touch/utils/utils.dart';
2020-01-24 16:11:43 +01:00
import 'package:git_touch/widgets/action_button.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2020-01-13 14:07:28 +01:00
import 'package:git_touch/widgets/table_view.dart';
2020-01-27 07:43:10 +01:00
import 'package:launch_review/launch_review.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
2020-01-13 14:07:28 +01:00
import 'package:tuple/tuple.dart';
import '../generated/l10n.dart';
2019-12-13 06:13:45 +01:00
2020-10-06 08:31:07 +02:00
class SettingsScreen extends StatelessWidget {
2020-01-13 14:07:28 +01:00
Widget _buildRightWidget(BuildContext context, bool checked) {
final theme = Provider.of<ThemeModel>(context);
2019-09-04 16:59:33 +02:00
if (!checked) return null;
2020-01-27 08:11:51 +01:00
return Icon(Icons.check, color: theme.palette.primary, size: 24);
2019-09-04 16:59:33 +02:00
}
@override
Widget build(BuildContext context) {
2020-01-13 14:07:28 +01:00
final theme = Provider.of<ThemeModel>(context);
2020-01-27 07:43:10 +01:00
final auth = Provider.of<AuthModel>(context);
final code = Provider.of<CodeModel>(context);
2019-09-25 11:06:36 +02:00
return SingleScaffold(
title: AppBarTitle(S.of(context).settings),
2019-09-25 11:06:36 +02:00
body: Column(
2019-09-25 08:24:20 +02:00
children: <Widget>[
2019-10-02 10:09:54 +02:00
CommonStyle.verticalGap,
TableView(headerText: S.of(context).system, items: [
2020-10-06 08:31:07 +02:00
if (auth.activeAccount.platform == PlatformType.github) ...[
TableViewItem(
text: Text(S.of(context).githubStatus),
2020-10-06 08:31:07 +02:00
url: 'https://www.githubstatus.com/',
),
2020-01-29 06:23:17 +01:00
TableViewItem(
text: Text(S.of(context).reviewPermissions),
2020-01-29 06:23:17 +01:00
url:
'https://github.com/settings/connections/applications/$clientId',
rightWidget: Text(auth.activeAccount.login),
),
2020-10-06 08:31:07 +02:00
],
if (auth.activeAccount.platform == PlatformType.gitlab)
TableViewItem(
text: Text(S.of(context).gitlabStatus),
2020-10-06 08:31:07 +02:00
url: '${auth.activeAccount.domain}/help',
rightWidget: FutureBuilder<String>(
future:
auth.fetchGitlab('/version').then((v) => v['version']),
builder: (context, snapshot) {
return Text(snapshot.data ?? '');
},
),
),
2020-10-06 07:53:07 +02:00
if (auth.activeAccount.platform == PlatformType.gitea)
TableViewItem(
leftIconData: Octicons.info,
text: Text(S.of(context).giteaStatus),
2020-10-06 07:53:07 +02:00
url: '/gitea/status',
rightWidget: FutureBuilder<String>(
future: auth.fetchGitea('/version').then((v) => v['version']),
builder: (context, snapshot) {
return Text(snapshot.data ?? '');
},
),
2020-10-06 08:31:07 +02:00
),
TableViewItem(
text: Text(S.of(context).switchAccounts),
2020-10-06 08:31:07 +02:00
url: '/login',
rightWidget: Text(auth.activeAccount.login),
),
2020-01-27 07:43:10 +01:00
]),
2019-10-02 10:09:54 +02:00
CommonStyle.verticalGap,
2020-01-27 07:43:10 +01:00
TableView(headerText: 'theme', items: [
2020-01-24 16:11:43 +01:00
TableViewItem(
text: Text(S.of(context).brightness),
2020-01-27 07:43:10 +01:00
rightWidget: Text(theme.brighnessValue == AppBrightnessType.light
? 'Light'
: theme.brighnessValue == AppBrightnessType.dark
? 'Dark'
: 'Follow system'),
2020-01-24 16:11:43 +01:00
onTap: () {
theme.showActions(context, [
for (var t in [
Tuple2(S.of(context).followSystem,
AppBrightnessType.followSystem),
Tuple2(S.of(context).light, AppBrightnessType.light),
Tuple2(S.of(context).dark, AppBrightnessType.dark),
2020-01-24 16:11:43 +01:00
])
ActionItem(
text: t.item1,
onTap: (_) {
2020-01-27 07:43:10 +01:00
if (theme.brighnessValue != t.item2)
theme.setBrightness(t.item2);
2020-01-24 16:11:43 +01:00
},
)
]);
},
),
TableViewItem(
text: Text(S.of(context).scaffoldTheme),
2020-01-27 07:43:10 +01:00
rightWidget: Text(theme.theme == AppThemeType.cupertino
? S.of(context).cupertino
: S.of(context).material),
2020-01-24 16:11:43 +01:00
onTap: () {
theme.showActions(context, [
for (var t in [
Tuple2(S.of(context).material, AppThemeType.material),
Tuple2(S.of(context).cupertino, AppThemeType.cupertino),
2020-01-24 16:11:43 +01:00
])
ActionItem(
text: t.item1,
onTap: (_) {
2020-01-27 07:43:10 +01:00
if (theme.theme != t.item2) {
theme.setTheme(t.item2);
}
2020-01-24 16:11:43 +01:00
},
)
]);
},
),
2020-01-27 03:47:34 +01:00
TableViewItem(
text: Text(S.of(context).codeTheme),
2020-01-27 03:47:34 +01:00
url: '/choose-code-theme',
2020-01-27 07:43:10 +01:00
rightWidget: Text('${code.fontFamily}, ${code.fontSize}pt'),
2020-01-27 03:47:34 +01:00
),
TableViewItem(
text: Text(S.of(context).markdownRenderEngine),
rightWidget: Text(theme.markdown == AppMarkdownType.flutter
? S.of(context).flutter
: S.of(context).webview),
onTap: () {
theme.showActions(context, [
for (var t in [
Tuple2(S.of(context).flutter, AppMarkdownType.flutter),
Tuple2(S.of(context).webview, AppMarkdownType.webview),
])
ActionItem(
text: t.item1,
onTap: (_) {
if (theme.markdown != t.item2) {
theme.setMarkdown(t.item2);
}
},
)
]);
},
),
2020-01-24 16:11:43 +01:00
]),
2020-01-27 07:43:10 +01:00
CommonStyle.verticalGap,
TableView(headerText: S.of(context).feedback, items: [
2020-01-27 07:43:10 +01:00
TableViewItem(
text: Text(S.of(context).submitAnIssue),
2020-01-27 07:43:10 +01:00
rightWidget: Text('pd4d10/git-touch'),
2020-01-29 06:23:17 +01:00
url: (auth.activeAccount.platform == PlatformType.github
? ''
: 'https://github.com') +
2020-10-03 08:39:35 +02:00
'/github/pd4d10/git-touch/issues/new',
2020-01-27 07:43:10 +01:00
),
TableViewItem(
text: Text(S.of(context).rateThisApp),
2020-01-27 07:43:10 +01:00
onTap: () {
LaunchReview.launch(
androidAppId: 'io.github.pd4d10.gittouch',
iOSAppId: '1452042346',
);
},
),
TableViewItem(
text: Text(S.of(context).email),
2020-01-27 07:43:10 +01:00
rightWidget: Text('pd4d10@gmail.com'),
hideRightChevron: true,
url: 'mailto:pd4d10@gmail.com',
),
]),
CommonStyle.verticalGap,
TableView(headerText: S.of(context).about, items: [
2020-10-06 07:53:07 +02:00
TableViewItem(
text: Text(S.of(context).version),
2020-10-06 07:53:07 +02:00
rightWidget: FutureBuilder<String>(
future:
PackageInfo.fromPlatform().then((info) => info.version),
builder: (context, snapshot) {
return Text(snapshot.data ?? '');
},
)),
2020-01-27 07:43:10 +01:00
TableViewItem(
text: Text(S.of(context).sourceCode),
2020-01-27 07:43:10 +01:00
rightWidget: Text('pd4d10/git-touch'),
2020-01-29 06:23:17 +01:00
url: (auth.activeAccount.platform == PlatformType.github
2020-10-03 08:39:35 +02:00
? '/github'
2020-01-29 06:23:17 +01:00
: 'https://github.com') +
'/pd4d10/git-touch',
2020-01-27 07:43:10 +01:00
),
])
2019-09-25 08:24:20 +02:00
],
),
);
}
}