import 'package:flutter/material.dart'; import 'package:trackoffical_app/generated/assets.dart'; import 'package:trackoffical_app/model.dart'; import 'package:trackoffical_app/route.dart'; import 'package:trackoffical_app/screen.dart'; import 'package:trackoffical_app/service/api.dart'; import 'package:trackoffical_app/service/app.dart'; import 'package:trackoffical_app/widget/app_top_bar.dart'; import 'package:trackoffical_app/widget/ruler_picker.dart'; import 'package:get/get.dart'; import 'package:trackoffical_app/service/mock.dart'; import '../../styles/theme.dart'; import '../../utils.dart'; class HomeSaveUserInfoController extends GetxController { final weightKg = 45.0.obs; final heightCm = 150.obs; final sex = Sex.Male.obs; final rhr = 60.obs; final age = 12.obs; onSave(){ final userProfile = App.to.userProfile; userProfile.age.val = age.value; userProfile.sex = sex.value; userProfile.weightKg.val = weightKg.value; userProfile.heightCm.val = heightCm.value.toDouble(); userProfile.rhr.val = rhr.value; tryCatchApi(()async{ await ApiService.to.saveUserInfo(); Get.offAllNamed(RouteName.home); }); } } class HomeSaveUserInfoView extends GetView { const HomeSaveUserInfoView({super.key}); static Bindings bindings() { return BindingsBuilder(() { Get.put(HomeSaveUserInfoController()); }); } @override Widget build(BuildContext context) { return Scaffold( body: Stack( alignment: Alignment.topCenter, children: [ Container( height: context.height, ), Image.asset(Assets.imagesBkLogin, width: context.width, fit: BoxFit.fitWidth), Positioned( top: MediaQuery.of(context).padding.top + 6.0.wp, child: Text('下列身体数据计算运动消耗', style: TextStyle(color: Colors.white, fontSize: 6.6.wp),)), Positioned( top: MediaQuery.of(context).padding.top + 24.0.wp, left: 0, child: Container( height: context.height - MediaQuery.of(context).padding.top - 24.0.wp, width: context.width, decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(3.3.wp), topRight: Radius.circular(3.3.wp), )), child: _wContent(context) ) ) ], ), floatingActionButton: FloatingActionButton( backgroundColor: context.theme.colorScheme.primary, foregroundColor: Colors.white, onPressed: controller.onSave, child: const Text('确定')), ); } Widget _wContent(BuildContext context){ const color = Color(0xffff870d); return ListView(children: [ _listTitle(context, '您的性别是?',), Row( children: Sex.values .map((sex) => Obx(() => Expanded( child: ListTile( title: Text(sex.display()), leading: Radio( value: sex, groupValue: controller.sex.value, onChanged: (value) { controller.sex.value = value!; }, ))))) .toList()), Obx(() => _EditValue( title: '您的身高是?', value: controller.heightCm.value.toString(), unit: 'CM', )), RulerPicker( beginValue: 80, endValue: 300, initValue: controller.heightCm.value, onValueChange: (value) { controller.heightCm.value = value; }, ), Obx(() => _EditValue( title: '您的体重是?', value: controller.weightKg.value.toStringAsFixed(1), unit: 'KG', )), RulerPicker( beginValue: 250, endValue: 4000, initValue: (controller.weightKg.value * 10).toInt(), onBuildRulerScaleText: (index, scaleValue) { return (scaleValue ~/ 10).toString(); }, onValueChange: (value) { controller.weightKg.value = value.toDouble() / 10; }, ), Obx(() => _EditValue( title: '您的年龄是?', value: controller.age.value.toString(), unit: '岁', )), RulerPicker( beginValue: 4, endValue: 150, initValue: controller.age.value, onValueChange: (value) { controller.age.value = value; }, ), Obx(() => _EditValue( title: '您的静息心率(RHR)是?', value: controller.rhr.value.toString(), unit: '次/分钟', )), RulerPicker( beginValue: 30, endValue: 180, initValue: controller.rhr.value, onValueChange: (value) { controller.rhr.value = value; }, ), ]); } } Widget _listTitle(BuildContext context, String title, {Widget? end}){ return ListTile(leading: Icon(Icons.arrow_right, color: context.theme.colorScheme.primary), title: Text(title, style: TextStyle(color: Colors.black, fontSize: 4.4.wp),), trailing: end); } class _EditValue extends StatelessWidget { const _EditValue({ required this.title, required this.value, required this.unit, }); final String title; final String value; final String unit; @override Widget build(BuildContext context) { final primary = context.theme.colorScheme.primary; return Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Padding( padding: EdgeInsets.only(top: 0, bottom:0), child: _listTitle(context, title)), RichText( text: TextSpan( text: value, style: context.textTheme.titleLarge ?.copyWith(fontSize: 4.4.wp, color: primary), children: [ TextSpan(text: unit, style: TextStyle(fontSize: 3.3.wp)) ]), ), ], ); } } void main() async { Mock.initServices(); var c = HomeSaveUserInfoController(); Get.put(c); runPreview(const HomeSaveUserInfoView()); }