[Flutter] Force a username before subscribing

This commit is contained in:
2025-12-18 15:27:27 +01:00
parent e98882a0c6
commit e15d70dd0e
7 changed files with 103 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import 'package:simplecloudnotifier/state/app_auth.dart';
import 'package:simplecloudnotifier/state/application_log.dart';
import 'package:simplecloudnotifier/utils/navi.dart';
import 'package:simplecloudnotifier/utils/toaster.dart';
import 'package:simplecloudnotifier/utils/dialogs.dart';
import 'package:simplecloudnotifier/utils/ui.dart';
class ChannelScannerResultChannelSubscribe extends StatefulWidget {
@@ -172,6 +173,38 @@ class _ChannelScannerResultChannelSubscribeState extends State<ChannelScannerRes
void _onSubscribe() async {
final auth = Provider.of<AppAuth>(context, listen: false);
// Check if username is set
try {
final user = await auth.loadUser();
if (user.username == null || user.username!.isEmpty) {
// Show modal to set username
var newusername = await UIDialogs.showUsernameRequiredDialog(context);
if (newusername == null) return; // User cancelled
newusername = newusername.trim();
if (newusername.isEmpty) {
Toaster.error("Error", 'Username cannot be empty');
return;
}
// Update username via API
try {
await APIClient.updateUser(auth, auth.userID!, username: newusername);
await auth.loadUser(force: true); // Refresh cached user
Toaster.success("Success", 'Username set');
} catch (e) {
Toaster.error("Error", 'Failed to set username: ${e.toString()}');
return;
}
}
} catch (e) {
Toaster.error("Error", 'Failed to load user data: ${e.toString()}');
return;
}
// Proceed with subscription
try {
var sub = await APIClient.subscribeToChannelbyID(auth, widget.value.channelID, subscribeKey: widget.value.subscribeKey);
if (sub.confirmed) {