Added User Profile Screen

This commit is contained in:
2026-02-18 21:42:48 +08:00
parent 35eae623d8
commit 372928d8e7
6 changed files with 606 additions and 5 deletions
+32
View File
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import '../models/profile.dart';
import 'auth_provider.dart';
@@ -36,6 +37,37 @@ final profilesProvider = StreamProvider<List<Profile>>((ref) {
.map((rows) => rows.map(Profile.fromMap).toList());
});
/// Controller for the current user's profile (update full name / password).
final profileControllerProvider = Provider<ProfileController>((ref) {
final client = ref.watch(supabaseClientProvider);
return ProfileController(client);
});
class ProfileController {
ProfileController(this._client);
final SupabaseClient _client;
/// Update the `profiles.full_name` for the given user id.
Future<void> updateFullName({
required String userId,
required String fullName,
}) async {
await _client
.from('profiles')
.update({'full_name': fullName})
.eq('id', userId);
}
/// Update the current user's password (works for OAuth users too).
Future<void> updatePassword(String password) async {
if (password.length < 8) {
throw Exception('Password must be at least 8 characters');
}
await _client.auth.updateUser(UserAttributes(password: password));
}
}
final isAdminProvider = Provider<bool>((ref) {
final profileAsync = ref.watch(currentProfileProvider);
return profileAsync.maybeWhen(