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

238 lines
9.6 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';
2021-02-27 10:41:57 +01:00
import 'package:git_touch/utils/locale.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 'package:flutter_gen/gen_l10n/S.dart';
2019-12-13 06:13:45 +01:00
2020-10-06 08:31:07 +02:00
class SettingsScreen extends StatelessWidget {
@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(
2021-05-16 09:16:35 +02:00
title: AppBarTitle(AppLocalizations.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,
2021-05-16 09:16:35 +02:00
TableView(headerText: AppLocalizations.of(context)!.system, items: [
if (auth.activeAccount!.platform == PlatformType.github) ...[
2020-10-06 08:31:07 +02:00
TableViewItem(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.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(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.reviewPermissions),
2020-01-29 06:23:17 +01:00
url:
'https://github.com/settings/connections/applications/$clientId',
2021-05-16 09:16:35 +02:00
rightWidget: Text(auth.activeAccount!.login),
2020-01-29 06:23:17 +01:00
),
2020-10-06 08:31:07 +02:00
],
2021-05-16 09:16:35 +02:00
if (auth.activeAccount!.platform == PlatformType.gitlab)
2020-10-06 08:31:07 +02:00
TableViewItem(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.gitlabStatus),
url: '${auth.activeAccount!.domain}/help',
2020-10-06 08:31:07 +02:00
rightWidget: FutureBuilder<String>(
future:
auth.fetchGitlab('/version').then((v) => v['version']),
builder: (context, snapshot) {
return Text(snapshot.data ?? '');
},
),
),
2021-05-16 09:16:35 +02:00
if (auth.activeAccount!.platform == PlatformType.gitea)
2020-10-06 07:53:07 +02:00
TableViewItem(
leftIconData: Octicons.info,
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.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(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.switchAccounts),
2020-10-06 08:31:07 +02:00
url: '/login',
2021-05-16 09:16:35 +02:00
rightWidget: Text(auth.activeAccount!.login),
2020-10-06 08:31:07 +02:00
),
2021-02-14 05:05:41 +01:00
TableViewItem(
2021-02-14 14:23:15 +01:00
text: Text('App Language'),
rightWidget: Text(theme.locale == null
2021-05-16 09:16:35 +02:00
? AppLocalizations.of(context)!.followSystem
: localeNameMap[theme.locale!] ?? theme.locale!),
2021-02-14 14:23:15 +01:00
onTap: () {
theme.showActions(context, [
2021-02-27 10:41:57 +01:00
for (final key in [
null,
...AppLocalizations.supportedLocales
.map((l) => l.toString())
.where((key) => localeNameMap[key] != null)
2021-02-14 14:23:15 +01:00
])
ActionItem(
2021-02-27 10:41:57 +01:00
text: key == null
2021-05-16 09:16:35 +02:00
? AppLocalizations.of(context)!.followSystem
2021-02-27 10:41:57 +01:00
: localeNameMap[key],
2021-02-14 14:23:15 +01:00
onTap: (_) async {
2021-05-30 18:08:38 +02:00
final res = await theme.showConfirm(
2021-02-14 14:23:15 +01:00
context,
2021-02-27 10:41:57 +01:00
Text(
'The app will reload to make the language setting take effect'),
2021-05-30 18:08:38 +02:00
);
if (res == true && theme.locale != key) {
await theme.setLocale(key);
2021-02-14 14:23:15 +01:00
auth.reloadApp();
}
},
)
]);
},
)
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(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.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 [
2021-05-16 09:16:35 +02:00
Tuple2(AppLocalizations.of(context)!.followSystem,
AppBrightnessType.followSystem),
2021-05-16 09:16:35 +02:00
Tuple2(AppLocalizations.of(context)!.light,
AppBrightnessType.light),
2021-05-16 09:16:35 +02:00
Tuple2(AppLocalizations.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(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.scaffoldTheme),
2020-01-27 07:43:10 +01:00
rightWidget: Text(theme.theme == AppThemeType.cupertino
2021-05-16 09:16:35 +02:00
? AppLocalizations.of(context)!.cupertino
: AppLocalizations.of(context)!.material),
2020-01-24 16:11:43 +01:00
onTap: () {
theme.showActions(context, [
for (var t in [
2021-05-16 09:16:35 +02:00
Tuple2(AppLocalizations.of(context)!.material,
AppThemeType.material),
2021-05-16 09:16:35 +02:00
Tuple2(AppLocalizations.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(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.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(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.markdownRenderEngine),
rightWidget: Text(theme.markdown == AppMarkdownType.flutter
2021-05-16 09:16:35 +02:00
? AppLocalizations.of(context)!.flutter
: AppLocalizations.of(context)!.webview),
onTap: () {
theme.showActions(context, [
for (var t in [
2021-05-16 09:16:35 +02:00
Tuple2(AppLocalizations.of(context)!.flutter,
AppMarkdownType.flutter),
2021-05-16 09:16:35 +02:00
Tuple2(AppLocalizations.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,
2021-05-16 09:16:35 +02:00
TableView(headerText: AppLocalizations.of(context)!.feedback, items: [
2020-01-27 07:43:10 +01:00
TableViewItem(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.submitAnIssue),
2021-02-14 15:17:22 +01:00
rightWidget: Text('git-touch/git-touch'),
2021-05-16 09:16:35 +02:00
url: (auth.activeAccount!.platform == PlatformType.github
2021-01-10 12:09:00 +01:00
? '/github'
2020-01-29 06:23:17 +01:00
: 'https://github.com') +
2021-02-14 15:17:22 +01:00
'/git-touch/git-touch/issues/new',
2020-01-27 07:43:10 +01:00
),
TableViewItem(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.rateThisApp),
2020-01-27 07:43:10 +01:00
onTap: () {
LaunchReview.launch(
androidAppId: 'io.github.pd4d10.gittouch',
iOSAppId: '1452042346',
);
},
),
TableViewItem(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.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,
2021-05-16 09:16:35 +02:00
TableView(headerText: AppLocalizations.of(context)!.about, items: [
2020-10-06 07:53:07 +02:00
TableViewItem(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.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(
2021-05-16 09:16:35 +02:00
text: Text(AppLocalizations.of(context)!.sourceCode),
2021-02-14 15:17:22 +01:00
rightWidget: Text('git-touch/git-touch'),
2021-05-16 09:16:35 +02: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') +
2021-02-14 15:17:22 +01:00
'/git-touch/git-touch',
2020-01-27 07:43:10 +01:00
),
])
2019-09-25 08:24:20 +02:00
],
),
);
}
}