142 lines
5.5 KiB
Dart
142 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:okane/i18n/strings.g.dart';
|
|
import 'package:okane/ui/state/settings.dart';
|
|
import 'package:okane/ui/utils.dart';
|
|
|
|
class SettingsPage extends StatelessWidget {
|
|
const SettingsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListView(
|
|
children: [
|
|
BlocBuilder<SettingsCubit, SettingsWrapper>(
|
|
builder:
|
|
(context, state) => ListTile(
|
|
title: Text(t.pages.settings.colorSchemes.title),
|
|
subtitle: switch (state.settings.colorScheme) {
|
|
ColorSchemeSettings.dark => Text(
|
|
t.pages.settings.colorSchemes.dark,
|
|
),
|
|
ColorSchemeSettings.light => Text(
|
|
t.pages.settings.colorSchemes.light,
|
|
),
|
|
ColorSchemeSettings.system => Text(
|
|
t.pages.settings.colorSchemes.system,
|
|
),
|
|
},
|
|
onTap: () async {
|
|
final colorScheme = await showDialogOrModal(
|
|
context: context,
|
|
builder:
|
|
(context) => ListView(
|
|
shrinkWrap: true,
|
|
children:
|
|
ColorSchemeSettings.values
|
|
.map(
|
|
(s) => ListTile(
|
|
leading:
|
|
state.settings.colorScheme == s
|
|
? Icon(Icons.check)
|
|
: null,
|
|
title: Text(switch (s) {
|
|
ColorSchemeSettings.dark =>
|
|
t.pages.settings.colorSchemes.dark,
|
|
ColorSchemeSettings.light =>
|
|
t.pages.settings.colorSchemes.light,
|
|
ColorSchemeSettings.system =>
|
|
t.pages.settings.colorSchemes.system,
|
|
}),
|
|
onTap: () {
|
|
Navigator.of(context).pop(s);
|
|
},
|
|
),
|
|
)
|
|
.toList(),
|
|
),
|
|
);
|
|
if (colorScheme == null) {
|
|
return;
|
|
}
|
|
|
|
await GetIt.I.get<SettingsCubit>().setSettings(
|
|
state.settings.copyWith(colorScheme: colorScheme),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
|
|
BlocBuilder<SettingsCubit, SettingsWrapper>(
|
|
builder:
|
|
(context, state) => ListTile(
|
|
title: Text("Sentry"),
|
|
subtitle: Text(
|
|
"When enabled sends errors to the configured Sentry DSN.",
|
|
),
|
|
trailing: IconButton(
|
|
icon: Icon(Icons.clear),
|
|
onPressed:
|
|
state.settings.sentryDsn == null
|
|
? null
|
|
: () async {
|
|
final result = await confirm(
|
|
context,
|
|
"Clear Sentry DSN",
|
|
"Are you sure you want to clear the Sentry DSN?",
|
|
);
|
|
if (!result) {
|
|
return;
|
|
}
|
|
|
|
await GetIt.I.get<SettingsCubit>().setSettings(
|
|
state.settings.copyWith(sentryDsn: null),
|
|
);
|
|
},
|
|
),
|
|
onTap: () async {
|
|
final controller = TextEditingController(
|
|
text: state.settings.sentryDsn ?? '',
|
|
);
|
|
final result = await showDialogOrModal<String>(
|
|
context: context,
|
|
builder: (context) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: controller,
|
|
decoration: InputDecoration(hintText: "Sentry DSN"),
|
|
),
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
OutlinedButton(
|
|
child: Text("Apply"),
|
|
onPressed: () {
|
|
Navigator.of(context).pop(controller.text);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
if (result == null) {
|
|
return;
|
|
}
|
|
|
|
await GetIt.I.get<SettingsCubit>().setSettings(
|
|
state.settings.copyWith(sentryDsn: result),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|