Skip to content

Commit

Permalink
Move debug menu to settings and enable it only in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
evgfilim1 committed Jan 31, 2024
1 parent 0a68638 commit 43240f2
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 99 deletions.
131 changes: 41 additions & 90 deletions lib/screens/debug_menu_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:provider/provider.dart";

import "../utils/bug_report/stub.dart"
if (dart.library.io) "../utils/bug_report/native.dart"
if (dart.library.html) "../utils/bug_report/web.dart";
import "../utils/errors.dart";
import "../utils/game_controller.dart";
import "../utils/ui.dart";
Expand Down Expand Up @@ -35,100 +30,56 @@ class _DebugMenuScreenState extends State<DebugMenuScreen> {
final controller = context.watch<GameController>();
_seedController.text = controller.playerRandomSeed.toString();
return Scaffold(
appBar: AppBar(title: const Text("Отладочное меню")),
appBar: AppBar(title: const Text("Меню отладки")),
body: ListView(
children: [
if (kDebugMode)
TextFieldListTile(
leading: const Icon(Icons.casino),
title: const Text("Зерно генератора ролей"),
subtitle: const Text("При изменении игра будет перезапущена"),
textField: TextField(
controller: _seedController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "Зерно генератора ролей",
),
TextFieldListTile(
leading: const Icon(Icons.casino),
title: const Text("Зерно генератора ролей"),
subtitle: const Text("При изменении игра будет перезапущена"),
textField: TextField(
controller: _seedController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "Зерно генератора ролей",
),
onSaved: () async {
final seed = int.tryParse(_seedController.text);
if (seed != null) {
final res = await showDialog<bool>(
context: context,
builder: (context) => const ConfirmationDialog(
title: Text("Применить настройки?"),
content: Text("Текущая игра будет перезапущена. Продолжить?"),
),
);
if (res ?? false) {
controller.restart(seed: seed);
if (!context.mounted) {
throw ContextNotMountedError();
}
showSnackBar(
context,
const SnackBar(content: Text("Игра перезапущена")),
);
}
}
},
)
else
ListTile(
leading: const Icon(Icons.casino),
title: const Text("Зерно генератора ролей"),
subtitle: const Text("Нажмите для копирования"),
onTap: () async {
await Clipboard.setData(ClipboardData(text: _seedController.text));
if (!context.mounted) {
throw ContextNotMountedError();
}
showSnackBar(
context,
const SnackBar(content: Text("Текст скопирован в буфер обмена")),
);
},
),
ListTile(
leading: const Icon(Icons.bug_report),
title: const Text("Сообщить о проблеме"),
onTap: () {
showSimpleDialog(
context: context,
title: const Text("Сообщить о проблеме"),
content: const Text(
"Для сообщения о проблеме нужно поделиться файлом или скопированным текстом"
" мне в ЛС в Telegram.",
),
extraActions: [
TextButton(
onPressed: () async {
await reportBug(context);
if (!context.mounted) {
throw ContextNotMountedError();
}
Navigator.pop(context);
},
child: const Text("Сформировать отчёт"),
onSaved: () async {
final seed = int.tryParse(_seedController.text);
if (seed != null) {
final res = await showDialog<bool>(
context: context,
builder: (context) => const ConfirmationDialog(
title: Text("Применить настройки?"),
content: Text("Текущая игра будет перезапущена. Продолжить?"),
),
],
);
);
if (res ?? false) {
controller.restart(seed: seed);
if (!context.mounted) {
throw ContextNotMountedError();
}
showSnackBar(
context,
const SnackBar(content: Text("Игра перезапущена")),
);
}
}
},
),
if (kDebugMode)
TextFieldListTile(
leading: const Icon(Icons.arrow_forward),
title: const Text("Перейти к экрану"),
textField: TextField(
controller: _pathController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "Путь",
),
TextFieldListTile(
leading: const Icon(Icons.arrow_forward),
title: const Text("Перейти к экрану"),
textField: TextField(
controller: _pathController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "Путь",
),
onSaved: () => Navigator.pushNamed(context, _pathController.text),
),
onSaved: () => Navigator.pushNamed(context, _pathController.text),
),
],
),
);
Expand Down
37 changes: 37 additions & 0 deletions lib/screens/settings/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import "package:flutter/material.dart";
import "package:package_info_plus/package_info_plus.dart";
import "package:provider/provider.dart";

import "../../utils/bug_report/stub.dart"
if (dart.library.io) "../../utils/bug_report/native.dart"
if (dart.library.html) "../../utils/bug_report/web.dart";
import "../../utils/errors.dart";
import "../../utils/game_controller.dart";
import "../../utils/ui.dart";
import "../../utils/updates_checker.dart";
import "../../widgets/notification_dot.dart";
Expand Down Expand Up @@ -46,6 +50,7 @@ class SettingsScreen extends StatelessWidget {
final packageInfo = context.read<PackageInfo>();
final appVersion = packageInfo.version;
final checker = context.watch<UpdatesChecker>();
final controller = context.watch<GameController>();
const updaterUnavailableReason = kIsWeb
? "в браузере"
: kDebugMode
Expand Down Expand Up @@ -79,6 +84,12 @@ class SettingsScreen extends StatelessWidget {
),
),
),
if (kDebugMode)
ListTile(
leading: const Icon(Icons.bug_report),
title: const Text("Меню отладки"),
onTap: () => Navigator.pushNamed(context, "/debug"),
),
ListTile(
enabled: updaterUnavailableReason == null,
leading: const Icon(Icons.refresh),
Expand All @@ -93,6 +104,32 @@ class SettingsScreen extends StatelessWidget {
trailing: checker.hasUpdate ? const NotificationDot(size: 8) : null,
onTap: () => _checkForUpdates(context),
),
ListTile(
leading: const Icon(Icons.bug_report),
title: const Text("Сообщить о проблеме"),
onTap: () {
showSimpleDialog(
context: context,
title: const Text("Сообщить о проблеме"),
content: Text(
"Для сообщения о проблеме нужно поделиться файлом мне в ЛС в Telegram.\n\n"
"Зерно генерации ролей: ${controller.playerRandomSeed}",
),
extraActions: [
TextButton(
onPressed: () async {
await reportBug(context);
if (!context.mounted) {
throw ContextNotMountedError();
}
Navigator.pop(context);
},
child: const Text("Сформировать отчёт"),
),
],
);
},
),
ListTile(
leading: const Icon(Icons.info),
title: const Text("О приложении"),
Expand Down
10 changes: 1 addition & 9 deletions lib/widgets/app_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AppDrawer extends StatelessWidget {
),
ListTile(
leading: const Icon(Icons.format_list_numbered),
title: const Text("Официальные правила"),
title: const Text("Официальные правила ФИИМ"),
onTap: () {
Navigator.pop(context);
launchUrlOrCopy(context, "https://mafiaworldtour.com/fiim-rules");
Expand All @@ -55,14 +55,6 @@ class AppDrawer extends StatelessWidget {
Navigator.pushNamed(context, "/settings");
},
),
ListTile(
leading: const Icon(Icons.bug_report),
title: const Text("Отладочное меню"),
onTap: () {
Navigator.pop(context);
Navigator.pushNamed(context, "/debug");
},
),
],
),
);
Expand Down

0 comments on commit 43240f2

Please sign in to comment.