Added confirmation for when the user presses the logout button, to avoid logging out by accident.

(Optimal for Desktop, not tested on Android)
This commit is contained in:
HatimWayne 2022-09-17 23:17:32 +01:00
parent 4b9792c34a
commit 3639d2213c

View File

@ -65,8 +65,7 @@ class Settings extends HookConsumerWidget {
children: [ children: [
const Text( const Text(
" Account", " Account",
style: style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
), ),
if (auth.isAnonymous) if (auth.isAnonymous)
AdaptiveListTile( AdaptiveListTile(
@ -106,22 +105,60 @@ class Settings extends HookConsumerWidget {
trailing: ElevatedButton( trailing: ElevatedButton(
child: const Text("Logout"), child: const Text("Logout"),
style: ButtonStyle( style: ButtonStyle(
backgroundColor: backgroundColor: MaterialStateProperty.all(Colors.red),
MaterialStateProperty.all(Colors.red), foregroundColor: MaterialStateProperty.all(Colors.white),
foregroundColor:
MaterialStateProperty.all(Colors.white),
), ),
onPressed: () async { onPressed: () {
auth.logout(); showDialog(
GoRouter.of(context).pop(); context: context,
builder: (_) => Dialog(
child: Container(
height: 200,
width: 400,
decoration: BoxDecoration(color: Theme.of(context).backgroundColor, borderRadius: BorderRadius.circular(20), border: Border.all(color: Colors.white)),
child: Column(
children: [
Expanded(child: Center(child: Text("Are you sure you want to log out?", style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)))),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
decoration: BoxDecoration(color: Theme.of(context).primaryColor, borderRadius: BorderRadius.circular(20)),
child: TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: AutoSizeText("NO", style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold))),
),
SizedBox(width: 30),
Container(
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
decoration: BoxDecoration(color: Colors.transparent, borderRadius: BorderRadius.circular(20), border: Border.all(color: Colors.red)),
child: TextButton(
onPressed: () async {
Navigator.of(context).pop();
auth.logout();
GoRouter.of(context).pop();
},
child: AutoSizeText("YES", style: TextStyle(color: Colors.red, fontSize: 20, fontWeight: FontWeight.bold))),
),
],
),
),
],
),
),
),
);
}, },
), ),
); );
}), }),
const Text( const Text(
" Appearance", " Appearance",
style: style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
), ),
AdaptiveListTile( AdaptiveListTile(
leading: const Icon(Icons.dashboard_rounded), leading: const Icon(Icons.dashboard_rounded),
@ -218,14 +255,12 @@ class Settings extends HookConsumerWidget {
), ),
const Text( const Text(
" Playback", " Playback",
style: style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
), ),
AdaptiveListTile( AdaptiveListTile(
leading: const Icon(Icons.multitrack_audio_rounded), leading: const Icon(Icons.multitrack_audio_rounded),
title: const Text("Audio Quality"), title: const Text("Audio Quality"),
trailing: (context, update) => trailing: (context, update) => DropdownButton<AudioQuality>(
DropdownButton<AudioQuality>(
value: preferences.audioQuality, value: preferences.audioQuality,
items: const [ items: const [
DropdownMenuItem( DropdownMenuItem(
@ -262,8 +297,7 @@ class Settings extends HookConsumerWidget {
), ),
const Text( const Text(
" Search", " Search",
style: style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
), ),
AdaptiveListTile( AdaptiveListTile(
leading: const Icon(Icons.shopping_bag_rounded), leading: const Icon(Icons.shopping_bag_rounded),
@ -334,8 +368,7 @@ class Settings extends HookConsumerWidget {
"Track Match Algorithm", "Track Match Algorithm",
maxLines: 1, maxLines: 1,
), ),
trailing: (context, update) => trailing: (context, update) => DropdownButton<SpotubeTrackMatchAlgorithm>(
DropdownButton<SpotubeTrackMatchAlgorithm>(
value: preferences.trackMatchAlgorithm, value: preferences.trackMatchAlgorithm,
items: const [ items: const [
DropdownMenuItem( DropdownMenuItem(
@ -365,8 +398,7 @@ class Settings extends HookConsumerWidget {
), ),
const Text( const Text(
" Downloads", " Downloads",
style: style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
), ),
ListTile( ListTile(
leading: const Icon(Icons.file_download_outlined), leading: const Icon(Icons.file_download_outlined),
@ -391,8 +423,7 @@ class Settings extends HookConsumerWidget {
), ),
const Text( const Text(
" About", " About",
style: style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
), ),
AdaptiveListTile( AdaptiveListTile(
leading: const Icon( leading: const Icon(
@ -429,8 +460,7 @@ class Settings extends HookConsumerWidget {
trailing: Switch.adaptive( trailing: Switch.adaptive(
activeColor: Theme.of(context).primaryColor, activeColor: Theme.of(context).primaryColor,
value: preferences.checkUpdate, value: preferences.checkUpdate,
onChanged: (checked) => onChanged: (checked) => preferences.setCheckUpdate(checked),
preferences.setCheckUpdate(checked),
), ),
), ),
const About() const About()