implement changing username
This commit is contained in:
@@ -13,6 +13,7 @@ import 'package:simplecloudnotifier/state/application_log.dart';
|
||||
import 'package:simplecloudnotifier/state/globals.dart';
|
||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||
import 'package:simplecloudnotifier/types/immediate_future.dart';
|
||||
import 'package:simplecloudnotifier/utils/dialogs.dart';
|
||||
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||
import 'package:simplecloudnotifier/utils/toaster.dart';
|
||||
import 'package:simplecloudnotifier/utils/ui.dart';
|
||||
@@ -359,13 +360,15 @@ class _AccountRootPageState extends State<AccountRootPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
UI.buttonIconOnly(
|
||||
onPressed: () {/*TODO*/},
|
||||
onPressed: _changeUsername,
|
||||
icon: FontAwesomeIcons.pen,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
if (!user.isPro)
|
||||
UI.buttonIconOnly(
|
||||
onPressed: () {/*TODO*/},
|
||||
onPressed: () {
|
||||
Toaster.info("Not Implemented", "Account Upgrading will be implemented in a later version"); // TODO
|
||||
},
|
||||
icon: FontAwesomeIcons.cartCircleArrowUp,
|
||||
),
|
||||
],
|
||||
@@ -502,4 +505,31 @@ class _AccountRootPageState extends State<AccountRootPage> {
|
||||
void _deleteAccount() async {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void _changeUsername() async {
|
||||
final acc = AppAuth();
|
||||
if (!acc.isAuth()) return;
|
||||
|
||||
var newusername = await UIDialogs.showTextInput(context, 'Change your public username', 'Enter new username');
|
||||
if (newusername == null) return;
|
||||
|
||||
newusername = newusername.trim();
|
||||
if (newusername == '') {
|
||||
Toaster.error("Error", 'Username cannot be empty');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final user = await APIClient.updateUser(acc, acc.userID!, username: newusername);
|
||||
setState(() {
|
||||
futureUser = ImmediateFuture.ofValue(user);
|
||||
});
|
||||
Toaster.success("Success", 'Username changed');
|
||||
|
||||
_backgroundRefresh();
|
||||
} catch (exc, trace) {
|
||||
Toaster.error("Error", 'Failed to update username');
|
||||
ApplicationLog.error('Failed to update username: ' + exc.toString(), trace: trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user