123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- import 'package:flutter/material.dart';
- import 'package:flutter_habit/common/BaseArchitectural.dart';
- import 'package:flutter_habit/common/I18N.dart';
- import 'package:flutter_habit/common/provider/DataProvider.dart';
- import 'package:flutter_habit/common/provider/UserProvider.dart';
- import 'package:flutter_habit/common/utils/ConvertUtils.dart';
- import 'package:flutter_habit/view/context/widget/BaseCard.dart';
- import 'package:flutter_habit/view/context/widget/DateValueMultiLineChart.dart';
- import 'package:flutter_habit/view/context/widget/DateValueSingleLineChart.dart';
- import 'package:provider/provider.dart';
- class BasicInfoContext extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MultiProvider(
- providers: [
- ChangeNotifierProvider<BasicInfoContextService>(
- create: (_) => BasicInfoContextService(context)),
- ],
- child: _BasicInfoContextView(),
- );
- }
- }
- // service
- class BasicInfoContextService extends BaseService {
- BasicInfoContextService(BuildContext context) : super(context);
- void changeSizeOfWeightChartCard(BuildContext context) {
- DataProvider dataProvider =
- Provider.of<DataProvider>(context, listen: false);
- switch (dataProvider.weightChartSize) {
- case 7:
- dataProvider.weightChartSize = 30;
- break;
- case 30:
- dataProvider.weightChartSize = 90;
- break;
- case 90:
- dataProvider.weightChartSize = 7;
- break;
- }
- dataProvider.notifyListeners();
- }
- void changeSizeOfBwhChartCard(BuildContext context) {
- DataProvider dataProvider =
- Provider.of<DataProvider>(context, listen: false);
- switch (dataProvider.bwhChartSize) {
- case 7:
- dataProvider.bwhChartSize = 30;
- break;
- case 30:
- dataProvider.bwhChartSize = 90;
- break;
- case 90:
- dataProvider.bwhChartSize = 7;
- break;
- }
- dataProvider.notifyListeners();
- }
- }
- // view
- class _BasicInfoContextView extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return ListView(
- children: <Widget>[
- baseInfoCard(context),
- weightChartCard(context),
- bwhChartCard(context),
- ],
- );
- }
- Widget baseInfoCard(BuildContext context) {
- DataProvider dataProvider =
- Provider.of<DataProvider>(context, listen: true);
- UserProvider userProvider =
- Provider.of<UserProvider>(context, listen: true);
- return BaseCard(
- title: Text(
- userProvider.userName ?? "Habit",
- maxLines: 1,
- style: Theme.of(context).textTheme.titleLarge.copyWith(fontSize: 35),
- ),
- subtitle: Text(I18N.of("基本信息")),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- userProvider.photo == null
- ? Icon(
- Icons.account_box,
- size: 170,
- color: Theme.of(context).unselectedWidgetColor,
- )
- : Padding(
- padding: EdgeInsets.all(20),
- child: ClipRRect(
- borderRadius: BorderRadius.circular(10),
- child: Image.memory(
- userProvider.photo,
- width: 130,
- height: 130,
- ),
- ),
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- "${I18N.of("身高")}: ${ConvertUtils.packString(dataProvider.height)} cm",
- style: TextStyle(height: 1.5),
- ),
- Text(
- "${I18N.of("体重")}: ${ConvertUtils.packString(dataProvider.weight)} kg",
- style: TextStyle(height: 1.5),
- ),
- Text(
- "${I18N.of("BMI")}: ${ConvertUtils.packString(dataProvider.bmi)} kg/m²",
- style: TextStyle(height: 1.5),
- ),
- Text(
- "${I18N.of("胸围")}: ${ConvertUtils.packString(dataProvider.breastLine)} cm",
- style: TextStyle(height: 1.5),
- ),
- Text(
- "${I18N.of("腰围")}: ${ConvertUtils.packString(dataProvider.hipLine)} cm",
- style: TextStyle(height: 1.5),
- ),
- Text(
- "${I18N.of("臀围")}: ${ConvertUtils.packString(dataProvider.waistLine)} cm",
- style: TextStyle(height: 1.5),
- ),
- ],
- ),
- Container(),
- ],
- ),
- );
- }
- Widget weightChartCard(BuildContext context) {
- BasicInfoContextService service =
- Provider.of<BasicInfoContextService>(context, listen: false);
- DataProvider dataProvider =
- Provider.of<DataProvider>(context, listen: true);
- return BaseCard(
- title: Text(
- "${I18N.of("体重信息")} (kg)",
- style: Theme.of(context).textTheme.titleLarge,
- ),
- subtitle: Container(
- height: 25,
- child: TextButton(
- child: Text("< ${dataProvider.weightChartSize} >"),
- onPressed: () => service.changeSizeOfWeightChartCard(context),
- ),
- ),
- child: DateValueSingleLineChart(
- size: dataProvider.weightChartSize,
- sports: dataProvider.weightFlSpots,
- ),
- );
- }
- Widget bwhChartCard(BuildContext context) {
- BasicInfoContextService service =
- Provider.of<BasicInfoContextService>(context, listen: false);
- DataProvider dataProvider =
- Provider.of<DataProvider>(context, listen: true);
- return BaseCard(
- title: Text(
- "${I18N.of("三围信息")} (cm)",
- style: Theme.of(context).textTheme.titleLarge,
- ),
- subtitle: Container(
- height: 25,
- child: TextButton(
- child: Text("< ${dataProvider.bwhChartSize} >"),
- onPressed: () => service.changeSizeOfBwhChartCard(context),
- ),
- ),
- child: DateValueMultiLineChart(
- size: dataProvider.bwhChartSize,
- lineNameSportsMap: {
- I18N.of("胸围") : dataProvider.brestLineFlSpots,
- I18N.of("腰围") : dataProvider.waistLineFlSpots,
- I18N.of("臀围") : dataProvider.hipLineFlSpots
- },
- ),
- );
- }
- }
|