first commit

This commit is contained in:
Lucas Saburido
2026-05-13 16:26:45 +01:00
commit cabf2025cd
252 changed files with 13524 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
import 'dart:typed_data';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/supabase/supabase_providers.dart';
import '../../data/services/profile_service.dart';
import '../../domain/models/profile_model.dart';
import '../../domain/models/profile_stats_model.dart';
final profileServiceProvider = Provider<ProfileService>((ref) {
final client = ref.watch(supabaseProvider);
return ProfileService(client);
});
final myProfileProvider = FutureProvider<ProfileModel>((ref) {
return ref.watch(profileServiceProvider).fetchMyProfile();
});
final myProfileStatsProvider = FutureProvider<ProfileStatsModel>((ref) {
return ref.watch(profileServiceProvider).fetchMyStats();
});
final profileControllerProvider =
AutoDisposeAsyncNotifierProvider<ProfileController, void>(
ProfileController.new,
);
class ProfileController extends AutoDisposeAsyncNotifier<void> {
@override
Future<void> build() async {}
Future<void> updateUsername(String username) async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
await ref.read(profileServiceProvider).updateUsername(username.trim());
ref.invalidate(myProfileProvider);
});
}
Future<void> updateBio(String bio) async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
await ref.read(profileServiceProvider).updateBio(bio.trim());
ref.invalidate(myProfileProvider);
});
}
Future<void> uploadAvatar({
required Uint8List bytes,
required String extension,
}) async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
await ref.read(profileServiceProvider).uploadAvatar(
bytes: bytes,
extension: extension,
);
ref.invalidate(myProfileProvider);
});
}
Future<void> saveProfile({
required String username,
required String bio,
}) async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
await ref.read(profileServiceProvider).updateProfile(
username: username.trim(),
bio: bio.trim(),
);
ref.invalidate(myProfileProvider);
});
}
}