Files
slogan/app/lib/features/profile/body_provider.dart
T
admin b53c57e02d Add 'app/' from commit 'a11a66886941bba128d89c1124115e1b1c87a128'
git-subtree-dir: app
git-subtree-mainline: 6ebd902c6b
git-subtree-split: a11a668869
2026-08-04 14:59:55 +08:00

66 lines
1.7 KiB
Dart

import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/auth/auth_provider.dart';
class BodyState {
final int height;
final int weight;
final int skinTone;
final int bust;
final int waist;
final int hip;
final int shoulder;
const BodyState({
this.height = 170,
this.weight = 60,
this.skinTone = 3,
this.bust = 88,
this.waist = 70,
this.hip = 92,
this.shoulder = 42,
});
}
class BodyNotifier extends AsyncNotifier<BodyState> {
@override
Future<BodyState> build() async {
final api = ref.read(apiClientProvider);
final data = await api.get<Map<String, dynamic>>('/body-measurement/get');
return BodyState(
height: (data['height'] as num?)?.toInt() ?? 170,
weight: (data['weight'] as num?)?.toInt() ?? 60,
skinTone: (data['skin_tone'] as num?)?.toInt() ?? 3,
bust: (data['bust'] as num?)?.toInt() ?? 88,
waist: (data['waist'] as num?)?.toInt() ?? 70,
hip: (data['hip'] as num?)?.toInt() ?? 92,
shoulder: (data['shoulder'] as num?)?.toInt() ?? 42,
);
}
Future<void> save(int height, int weight, int skinTone, int bust,
int waist, int hip, int shoulder) async {
final api = ref.read(apiClientProvider);
await api.post('/body-measurement/save', {
'height': height,
'weight': weight,
'skin_tone': skinTone,
'bust': bust,
'waist': waist,
'hip': hip,
'shoulder': shoulder,
});
state = AsyncData(BodyState(
height: height,
weight: weight,
skinTone: skinTone,
bust: bust,
waist: waist,
hip: hip,
shoulder: shoulder));
}
}
final bodyProvider =
AsyncNotifierProvider<BodyNotifier, BodyState>(BodyNotifier.new);