Skip to content

Commit

Permalink
Use unified alertDialog widget across entire app
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedon-dev committed Feb 5, 2025
1 parent 77ef44f commit fd8e364
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 540 deletions.
109 changes: 28 additions & 81 deletions lib/ui/screens/bug_report_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:system_info2/system_info2.dart';

import '/services/bug_report_manager.dart';
import '/ui/utils/toast_notification.dart';
import '/ui/widgets/alert_dialog.dart';
import '/utils/global_vars.dart';

class BugReportScreen extends StatefulWidget {
Expand Down Expand Up @@ -82,7 +83,19 @@ class _BugReportScreenState extends State<BugReportScreen> {
showDialog(
context: context,
builder: (BuildContext context) {
return buildExitDialog();
return ThemedDialog(
title: "Cancel bug report?",
primaryText: "Stay",
onPrimary: Navigator.of(context).pop,
secondaryText: "Cancel bug report",
onSecondary: () {
canPopYes = true;
// close popup
Navigator.pop(context);
// Go back a screen
Navigator.pop(context);
},
);
});
}
},
Expand All @@ -94,7 +107,16 @@ class _BugReportScreenState extends State<BugReportScreen> {
child: Padding(
padding: const EdgeInsets.all(8),
child: emptyDebugObject
? buildEmptyDialog()
? ThemedDialog(
title: "Create empty bug report?",
primaryText: "Continue",
onPrimary: () =>
setState(() => emptyDebugObject = false),
secondaryText: "Go back",
onSecondary: Navigator.of(context).pop,
content: const Text(
"Long tap anything in the app to create a specific bug report.\n\n"
"Ignore this message if you want to create a suggestion."))
: submissionType == ""
? buildSubmissionTypeDialog()
: Column(
Expand All @@ -103,83 +125,9 @@ class _BugReportScreenState extends State<BugReportScreen> {
children: buildMainList())))));
}

Widget buildExitDialog() {
return AlertDialog(
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
title: const Text("Cancel bug report?"),
content: const Text(
"Are you sure you want to cancel? Proper bug reports can help"
" immensely in improving the app."),
actionsAlignment: MainAxisAlignment.spaceEvenly,
actions: [
ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.surface),
child: Text("Cancel bug report",
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(color: Theme.of(context).colorScheme.onSurface)),
onPressed: () {
canPopYes = true;
// close popup
Navigator.pop(context);
// Go back a screen
Navigator.pop(context);
},
),
ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary),
child: Text("Stay",
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(color: Theme.of(context).colorScheme.onPrimary)),
// close popup
onPressed: () => Navigator.pop(context),
)
]);
;
}

Widget buildEmptyDialog() {
return AlertDialog(
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
title: const Text("Create empty bug report?"),
content: const Text(
"Long tap anything in the app to create a specific bug report.\n\n"
"Ignore this message if you want to create a suggestion."),
actionsAlignment: MainAxisAlignment.spaceEvenly,
actions: [
ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.surface),
// Go back a screen
onPressed: () => Navigator.pop(context),
child: Text("Go back",
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(color: Theme.of(context).colorScheme.onSurface)),
),
ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary),
onPressed: () => setState(() => emptyDebugObject = false),
child: Text("Continue",
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(color: Theme.of(context).colorScheme.onPrimary)),
)
]);
}

Widget buildSubmissionTypeDialog() {
return AlertDialog(
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
title: const Text("Select submission type"),
return ThemedDialog(
title: "Select submission type",
content: Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(
Expand All @@ -201,9 +149,8 @@ class _BugReportScreenState extends State<BugReportScreen> {
}

Widget buildIssueTypeDialog() {
return AlertDialog(
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
title: const Text("Select problem type"),
return ThemedDialog(
title: "Select problem type",
content: Column(
mainAxisSize: MainAxisSize.min,
children: List.generate(
Expand Down
64 changes: 28 additions & 36 deletions lib/ui/screens/fake_apps/fake_reminders.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';

import '/ui/widgets/alert_dialog.dart';
import '/utils/global_vars.dart';

class FakeRemindersScreen extends StatefulWidget {
Expand Down Expand Up @@ -48,43 +49,34 @@ class _FakeRemindersScreenState extends State<FakeRemindersScreen> {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text("Add Reminder"),
content: TextField(
controller: _controller,
decoration:
const InputDecoration(hintText: "Enter reminder"),
),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context); // Close the dialog
},
child: const Text("Cancel"),
),
TextButton(
onPressed: () async {
if (_controller.text.trim().toLowerCase() ==
"stop concealing") {
logger.i("Unconcealing app");
widget.parentStopConcealing();
Navigator.pop(context); // Close the dialog
return;
}
if (_controller.text.isNotEmpty) {
snapshot.data!.add(_controller.text);
await sharedStorage.setStringList(
"appearance_fake_reminders_list",
snapshot.data!);
setState(() {});
_controller.clear(); // Clear the text field
Navigator.pop(context); // Close the dialog
}
},
child: const Text("Add"),
return ThemedDialog(
title: "Add Reminder",
content: TextField(
controller: _controller,
decoration:
const InputDecoration(hintText: "Enter reminder"),
),
],
);
primaryText: "Add",
onPrimary: () async {
if (_controller.text.trim().toLowerCase() ==
"stop concealing") {
logger.i("Unconcealing app");
widget.parentStopConcealing();
Navigator.pop(context); // Close the dialog
return;
}
if (_controller.text.isNotEmpty) {
snapshot.data!.add(_controller.text);
await sharedStorage.setStringList(
"appearance_fake_reminders_list",
snapshot.data!);
setState(() {});
_controller.clear(); // Clear the text field
Navigator.pop(context); // Close the dialog
}
},
secondaryText: "Cancel",
onSecondary: () => Navigator.pop(context));
},
);
},
Expand Down
89 changes: 43 additions & 46 deletions lib/ui/screens/settings/settings_comments.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';

import '/ui/widgets/alert_dialog.dart';
import '/ui/widgets/options_switch.dart';
import '/utils/global_vars.dart';

Expand Down Expand Up @@ -53,52 +54,48 @@ class _CommentsScreenState extends State<CommentsScreen> {
onTap: () => showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Comment text filters"),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Center(child: const Text("Ok")),
),
],
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
FutureBuilder<bool?>(
future: sharedStorage
.getBool("comments_filter_links"),
builder: (context, snapshot) {
return OptionsSwitch(
title: "Hide comments with links",
subTitle: "Comments with links "
"will be hidden",
switchState:
snapshot.data ?? false,
onToggled: (value) async =>
await sharedStorage.setBool(
"comments_filter_links",
value));
}),
FutureBuilder<bool?>(
future: sharedStorage.getBool(
"comments_filter_non_ascii"),
builder: (context, snapshot) {
return OptionsSwitch(
title: "Hide non-ascii comments",
subTitle: "Hide comments with non"
"-ascii (non-english) text",
switchState:
snapshot.data ?? false,
onToggled: (value) async =>
await sharedStorage.setBool(
"comments_filter_non_ascii",
value));
})
],
),
);
return ThemedDialog(
title: "Comment text filters",
primaryText: "Ok",
onPrimary: Navigator.of(context).pop,
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
FutureBuilder<bool?>(
future: sharedStorage.getBool(
"comments_filter_links"),
builder: (context, snapshot) {
return OptionsSwitch(
title:
"Hide comments with links",
subTitle:
"Comments with links "
"will be hidden",
switchState:
snapshot.data ?? false,
onToggled: (value) async =>
await sharedStorage.setBool(
"comments_filter_links",
value));
}),
FutureBuilder<bool?>(
future: sharedStorage.getBool(
"comments_filter_non_ascii"),
builder: (context, snapshot) {
return OptionsSwitch(
title:
"Hide non-ascii comments",
subTitle:
"Hide comments with non"
"-ascii (non-english) text",
switchState:
snapshot.data ?? false,
onToggled: (value) async =>
await sharedStorage.setBool(
"comments_filter_non_ascii",
value));
})
]));
})),
],
))));
Expand Down
Loading

0 comments on commit fd8e364

Please sign in to comment.