Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Add feature to change user identifier in profile settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Nov 23, 2023
1 parent e0256ae commit f128244
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/controllers/profile_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class ProfileController {
return base64Encode(gzip.encode(utf8.encode(jsonEncode(data))));
}

Future<void> setTokenUuid(String tokenUuid) async {
_registeredDevice.data = tokenUuid;
await _registeredDevice.save();
}

Future<bool> _registerDevice() async {
final CollectionDataController watchlist =
CollectionDataController('animeWatchlist');
Expand Down Expand Up @@ -60,8 +65,7 @@ class ProfileController {
}

final String registeredDevice = jsonDecode(response!.body)['tokenUuid'];
_registeredDevice.data = registeredDevice;
await _registeredDevice.save();
await setTokenUuid(registeredDevice);

// Reset old data only if registered correctly
await watchlist.reset();
Expand Down
74 changes: 74 additions & 0 deletions lib/views/profile/profile_settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ProfileSettingsView extends StatefulWidget {
}

class _ProfileSettingsViewState extends State<ProfileSettingsView> {
final TextEditingController textEditingController = TextEditingController();

bool _checkIfSomethingIsRunning(
NotificationController value,
BuildContext context,
Expand Down Expand Up @@ -269,6 +271,78 @@ class _ProfileSettingsViewState extends State<ProfileSettingsView> {
);
},
),
CategoryButton(
label: 'Changer mon identifiant',
icon: const Icon(Icons.edit_outlined),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Changer mon identifiant'),
content: Column(
children: [
const Text(
'Êtes-vous sûr de vouloir changer votre identifiant ?',
),
const SizedBox(height: 16),
TextField(
controller: textEditingController,
decoration: const InputDecoration(
labelText: 'Nouvel identifiant',
),
),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Annuler'),
),
TextButton(
onPressed: () async {
Navigator.of(context).pop();
ScaffoldMessenger.of(context)
.showSnackBar(
const SnackBar(
content: Text(
'Changement de l\'identifiant...',
textAlign: TextAlign.center,
),
duration: Duration(seconds: 10),
),
);

await ProfileController.instance
.setTokenUuid(
textEditingController.text,
);
await ProfileController.instance.init();

if (!context.mounted) return;
ScaffoldMessenger.of(context)
.removeCurrentSnackBar();

ScaffoldMessenger.of(context)
.showSnackBar(
const SnackBar(
content: Text(
'Identifiant changé',
textAlign: TextAlign.center,
),
),
);
},
child: const Text('Changer'),
),
],
);
},
);
},
),
CategoryButton(
label: 'Suppression des données',
icon: const Icon(Icons.delete_forever_outlined),
Expand Down

0 comments on commit f128244

Please sign in to comment.