123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import 'package:flutter/material.dart';
- import 'package:get_it/get_it.dart';
- import 'package:provider/provider.dart';
- import 'package:sport/provider/login_info_model.dart';
- import 'package:sport/provider/user_model.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/widgets/appbar.dart';
- import 'package:sport/widgets/button_cancel.dart';
- import 'package:sport/widgets/button_primary.dart';
- import 'package:sport/widgets/dialog/request_dialog.dart';
- import 'package:sport/widgets/ruler_widget.dart';
- class WeightPage extends StatefulWidget {
- final bool update;
- const WeightPage({Key? key, this.update = false}) : super(key: key);
- @override
- State<StatefulWidget> createState() => _PageState();
- }
- class _PageState extends State<WeightPage> {
- late ValueNotifier<double> _valueNotifier;
- @override
- void initState() {
- super.initState();
- _valueNotifier = ValueNotifier(60.0);
- var user = Provider.of<UserModel>(context, listen: false);
- var weight = user.user.weight;
- if (weight == null || weight == 0) {
- weight = user.user.gender == 1 ? 65.0 : 50.0;
- }
- _valueNotifier.value = weight;
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.white,
- appBar: buildAppBar(context),
- body: SingleChildScrollView(
- child: Column(
- children: [
- SizedBox(
- height: 50.0,
- ),
- Text(
- "体重信息填写",
- style: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 25.0),
- ),
- if (widget.update == false)
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- "真实填写个人信息会让运动数据更精确",
- style: Theme.of(context).textTheme.bodyText1!,
- ),
- ),
- SizedBox(
- height: 30.0,
- ),
- Row(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- Container(
- width: 20,
- ),
- ValueListenableBuilder<double>(
- valueListenable: _valueNotifier,
- builder: (_, value, __) => Text(
- "${value.toStringAsFixed(1)}",
- style: Theme.of(context).textTheme.headline1!.copyWith(
- fontSize: 40.0,
- fontFamily: "DIN",
- ),
- )),
- Container(
- width: 20,
- child: Padding(
- padding: const EdgeInsets.only(bottom: 8.0),
- child: Text(
- " kg",
- style: Theme.of(context).textTheme.subtitle1!,
- ),
- ),
- ),
- ],
- ),
- NotificationListener<RulerValue>(
- child: RulerWidget(
- initialIndex: _valueNotifier.value,
- ),
- onNotification: (v) {
- _valueNotifier.value = v.value;
- return true;
- },
- ),
- widget.update == false
- ? Container(
- margin: EdgeInsets.all(25),
- child: PrimaryButton(
- content: "完成",
- callback: () async {
- await _updateInfo();
- NavigatorUtil.goHomePage(context);
- },
- ),
- )
- : Padding(
- padding: const EdgeInsets.all(16.0),
- child: Row(
- children: [
- Expanded(
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: CancelButton(
- content: "取消",
- callback: () {
- Navigator.maybePop(context);
- },
- ),
- )),
- Expanded(
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: PrimaryButton(
- content: "完成",
- callback: () async {
- await _updateInfo();
- Navigator.maybePop(context);
- },
- ),
- )),
- ],
- ),
- )
- ],
- ),
- ));
- }
- _updateInfo() async {
- await request(context, () async {
- LoginInfoModel _loginInfoModel = GetIt.I();
- await _loginInfoModel.updateUserInfoEx(context, weight: _valueNotifier.value, ignoreNameCard: 1);
- });
- }
- }
|