weight_page.dart 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import 'package:flutter/material.dart';
  2. import 'package:get_it/get_it.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:sport/provider/login_info_model.dart';
  5. import 'package:sport/provider/user_model.dart';
  6. import 'package:sport/router/navigator_util.dart';
  7. import 'package:sport/widgets/appbar.dart';
  8. import 'package:sport/widgets/button_cancel.dart';
  9. import 'package:sport/widgets/button_primary.dart';
  10. import 'package:sport/widgets/dialog/request_dialog.dart';
  11. import 'package:sport/widgets/ruler_widget.dart';
  12. class WeightPage extends StatefulWidget {
  13. final bool update;
  14. const WeightPage({Key? key, this.update = false}) : super(key: key);
  15. @override
  16. State<StatefulWidget> createState() => _PageState();
  17. }
  18. class _PageState extends State<WeightPage> {
  19. late ValueNotifier<double> _valueNotifier;
  20. @override
  21. void initState() {
  22. super.initState();
  23. _valueNotifier = ValueNotifier(60.0);
  24. var user = Provider.of<UserModel>(context, listen: false);
  25. var weight = user.user.weight;
  26. if (weight == null || weight == 0) {
  27. weight = user.user.gender == 1 ? 65.0 : 50.0;
  28. }
  29. _valueNotifier.value = weight;
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. return Scaffold(
  34. backgroundColor: Colors.white,
  35. appBar: buildAppBar(context),
  36. body: SingleChildScrollView(
  37. child: Column(
  38. children: [
  39. SizedBox(
  40. height: 50.0,
  41. ),
  42. Text(
  43. "体重信息填写",
  44. style: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 25.0),
  45. ),
  46. if (widget.update == false)
  47. Padding(
  48. padding: const EdgeInsets.all(8.0),
  49. child: Text(
  50. "真实填写个人信息会让运动数据更精确",
  51. style: Theme.of(context).textTheme.bodyText1!,
  52. ),
  53. ),
  54. SizedBox(
  55. height: 30.0,
  56. ),
  57. Row(
  58. mainAxisSize: MainAxisSize.min,
  59. crossAxisAlignment: CrossAxisAlignment.end,
  60. children: [
  61. Container(
  62. width: 20,
  63. ),
  64. ValueListenableBuilder<double>(
  65. valueListenable: _valueNotifier,
  66. builder: (_, value, __) => Text(
  67. "${value.toStringAsFixed(1)}",
  68. style: Theme.of(context).textTheme.headline1!.copyWith(
  69. fontSize: 40.0,
  70. fontFamily: "DIN",
  71. ),
  72. )),
  73. Container(
  74. width: 20,
  75. child: Padding(
  76. padding: const EdgeInsets.only(bottom: 8.0),
  77. child: Text(
  78. " kg",
  79. style: Theme.of(context).textTheme.subtitle1!,
  80. ),
  81. ),
  82. ),
  83. ],
  84. ),
  85. NotificationListener<RulerValue>(
  86. child: RulerWidget(
  87. initialIndex: _valueNotifier.value,
  88. ),
  89. onNotification: (v) {
  90. _valueNotifier.value = v.value;
  91. return true;
  92. },
  93. ),
  94. widget.update == false
  95. ? Container(
  96. margin: EdgeInsets.all(25),
  97. child: PrimaryButton(
  98. content: "完成",
  99. callback: () async {
  100. await _updateInfo();
  101. NavigatorUtil.goHomePage(context);
  102. },
  103. ),
  104. )
  105. : Padding(
  106. padding: const EdgeInsets.all(16.0),
  107. child: Row(
  108. children: [
  109. Expanded(
  110. child: Padding(
  111. padding: const EdgeInsets.all(8.0),
  112. child: CancelButton(
  113. content: "取消",
  114. callback: () {
  115. Navigator.maybePop(context);
  116. },
  117. ),
  118. )),
  119. Expanded(
  120. child: Padding(
  121. padding: const EdgeInsets.all(8.0),
  122. child: PrimaryButton(
  123. content: "完成",
  124. callback: () async {
  125. await _updateInfo();
  126. Navigator.maybePop(context);
  127. },
  128. ),
  129. )),
  130. ],
  131. ),
  132. )
  133. ],
  134. ),
  135. ));
  136. }
  137. _updateInfo() async {
  138. await request(context, () async {
  139. LoginInfoModel _loginInfoModel = GetIt.I();
  140. await _loginInfoModel.updateUserInfoEx(context, weight: _valueNotifier.value, ignoreNameCard: 1);
  141. });
  142. }
  143. }