git-subtree-dir: app git-subtree-mainline:6ebd902c6bgit-subtree-split:a11a668869
66 lines
1.7 KiB
Dart
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);
|