BasicInfoContext.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_habit/common/BaseArchitectural.dart';
  3. import 'package:flutter_habit/common/I18N.dart';
  4. import 'package:flutter_habit/common/provider/DataProvider.dart';
  5. import 'package:flutter_habit/common/provider/UserProvider.dart';
  6. import 'package:flutter_habit/common/utils/ConvertUtils.dart';
  7. import 'package:flutter_habit/view/context/widget/BaseCard.dart';
  8. import 'package:flutter_habit/view/context/widget/DateValueMultiLineChart.dart';
  9. import 'package:flutter_habit/view/context/widget/DateValueSingleLineChart.dart';
  10. import 'package:provider/provider.dart';
  11. class BasicInfoContext extends StatelessWidget {
  12. @override
  13. Widget build(BuildContext context) {
  14. return MultiProvider(
  15. providers: [
  16. ChangeNotifierProvider<BasicInfoContextService>(
  17. create: (_) => BasicInfoContextService(context)),
  18. ],
  19. child: _BasicInfoContextView(),
  20. );
  21. }
  22. }
  23. // service
  24. class BasicInfoContextService extends BaseService {
  25. BasicInfoContextService(BuildContext context) : super(context);
  26. void changeSizeOfWeightChartCard(BuildContext context) {
  27. DataProvider dataProvider =
  28. Provider.of<DataProvider>(context, listen: false);
  29. switch (dataProvider.weightChartSize) {
  30. case 7:
  31. dataProvider.weightChartSize = 30;
  32. break;
  33. case 30:
  34. dataProvider.weightChartSize = 90;
  35. break;
  36. case 90:
  37. dataProvider.weightChartSize = 7;
  38. break;
  39. }
  40. dataProvider.notifyListeners();
  41. }
  42. void changeSizeOfBwhChartCard(BuildContext context) {
  43. DataProvider dataProvider =
  44. Provider.of<DataProvider>(context, listen: false);
  45. switch (dataProvider.bwhChartSize) {
  46. case 7:
  47. dataProvider.bwhChartSize = 30;
  48. break;
  49. case 30:
  50. dataProvider.bwhChartSize = 90;
  51. break;
  52. case 90:
  53. dataProvider.bwhChartSize = 7;
  54. break;
  55. }
  56. dataProvider.notifyListeners();
  57. }
  58. }
  59. // view
  60. class _BasicInfoContextView extends StatelessWidget {
  61. @override
  62. Widget build(BuildContext context) {
  63. return ListView(
  64. children: <Widget>[
  65. baseInfoCard(context),
  66. weightChartCard(context),
  67. bwhChartCard(context),
  68. ],
  69. );
  70. }
  71. Widget baseInfoCard(BuildContext context) {
  72. DataProvider dataProvider =
  73. Provider.of<DataProvider>(context, listen: true);
  74. UserProvider userProvider =
  75. Provider.of<UserProvider>(context, listen: true);
  76. return BaseCard(
  77. title: Text(
  78. userProvider.userName ?? "Habit",
  79. maxLines: 1,
  80. style: Theme.of(context).textTheme.titleLarge.copyWith(fontSize: 35),
  81. ),
  82. subtitle: Text(I18N.of("基本信息")),
  83. child: Row(
  84. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  85. children: <Widget>[
  86. userProvider.photo == null
  87. ? Icon(
  88. Icons.account_box,
  89. size: 170,
  90. color: Theme.of(context).unselectedWidgetColor,
  91. )
  92. : Padding(
  93. padding: EdgeInsets.all(20),
  94. child: ClipRRect(
  95. borderRadius: BorderRadius.circular(10),
  96. child: Image.memory(
  97. userProvider.photo,
  98. width: 130,
  99. height: 130,
  100. ),
  101. ),
  102. ),
  103. Column(
  104. crossAxisAlignment: CrossAxisAlignment.start,
  105. children: <Widget>[
  106. Text(
  107. "${I18N.of("身高")}: ${ConvertUtils.packString(dataProvider.height)} cm",
  108. style: TextStyle(height: 1.5),
  109. ),
  110. Text(
  111. "${I18N.of("体重")}: ${ConvertUtils.packString(dataProvider.weight)} kg",
  112. style: TextStyle(height: 1.5),
  113. ),
  114. Text(
  115. "${I18N.of("BMI")}: ${ConvertUtils.packString(dataProvider.bmi)} kg/m²",
  116. style: TextStyle(height: 1.5),
  117. ),
  118. Text(
  119. "${I18N.of("胸围")}: ${ConvertUtils.packString(dataProvider.breastLine)} cm",
  120. style: TextStyle(height: 1.5),
  121. ),
  122. Text(
  123. "${I18N.of("腰围")}: ${ConvertUtils.packString(dataProvider.hipLine)} cm",
  124. style: TextStyle(height: 1.5),
  125. ),
  126. Text(
  127. "${I18N.of("臀围")}: ${ConvertUtils.packString(dataProvider.waistLine)} cm",
  128. style: TextStyle(height: 1.5),
  129. ),
  130. ],
  131. ),
  132. Container(),
  133. ],
  134. ),
  135. );
  136. }
  137. Widget weightChartCard(BuildContext context) {
  138. BasicInfoContextService service =
  139. Provider.of<BasicInfoContextService>(context, listen: false);
  140. DataProvider dataProvider =
  141. Provider.of<DataProvider>(context, listen: true);
  142. return BaseCard(
  143. title: Text(
  144. "${I18N.of("体重信息")} (kg)",
  145. style: Theme.of(context).textTheme.titleLarge,
  146. ),
  147. subtitle: Container(
  148. height: 25,
  149. child: TextButton(
  150. child: Text("< ${dataProvider.weightChartSize} >"),
  151. onPressed: () => service.changeSizeOfWeightChartCard(context),
  152. ),
  153. ),
  154. child: DateValueSingleLineChart(
  155. size: dataProvider.weightChartSize,
  156. sports: dataProvider.weightFlSpots,
  157. ),
  158. );
  159. }
  160. Widget bwhChartCard(BuildContext context) {
  161. BasicInfoContextService service =
  162. Provider.of<BasicInfoContextService>(context, listen: false);
  163. DataProvider dataProvider =
  164. Provider.of<DataProvider>(context, listen: true);
  165. return BaseCard(
  166. title: Text(
  167. "${I18N.of("三围信息")} (cm)",
  168. style: Theme.of(context).textTheme.titleLarge,
  169. ),
  170. subtitle: Container(
  171. height: 25,
  172. child: TextButton(
  173. child: Text("< ${dataProvider.bwhChartSize} >"),
  174. onPressed: () => service.changeSizeOfBwhChartCard(context),
  175. ),
  176. ),
  177. child: DateValueMultiLineChart(
  178. size: dataProvider.bwhChartSize,
  179. lineNameSportsMap: {
  180. I18N.of("胸围") : dataProvider.brestLineFlSpots,
  181. I18N.of("腰围") : dataProvider.waistLineFlSpots,
  182. I18N.of("臀围") : dataProvider.hipLineFlSpots
  183. },
  184. ),
  185. );
  186. }
  187. }