123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import 'package:flutter/material.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:sport/application.dart';
- import 'package:sport/bean/sport_detail.dart';
- import 'package:sport/utils/sport_utils.dart';
- import 'package:sport/widgets/button_cancel.dart';
- import 'package:sport/widgets/button_primary.dart';
- class SportReferencePage extends StatefulWidget {
- final RecordsTodaySum sum;
- const SportReferencePage({Key? key, required this.sum}) : super(key: key);
- @override
- State<StatefulWidget> createState() => _PageState();
- }
- class _PageState extends State<SportReferencePage> {
- int _index = 0;
- int _consume = 0;
- @override
- void initState() {
- super.initState();
- _consume = widget.sum.consume;
- SharedPreferences.getInstance().then((value) {
- setState(() {
- _index = value.getInt("sport_type") ?? 0;
- });
- });
- }
- @override
- Widget build(BuildContext context) {
- return Dialog(
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
- child: FutureBuilder<SharedPreferences>(
- future: SharedPreferences.getInstance(),
- builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) => Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Container(
- width: double.infinity,
- margin: EdgeInsets.all(16.0),
- padding: EdgeInsets.only(top: 14),
- child: Center(
- child: Text(
- "消耗$_consume大卡,相当于",
- style: Theme.of(context).textTheme.headline1,
- ),
- ),
- ),
- ListView(
- padding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
- physics: NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- children: SPORT_TYPE
- .map(
- (e) => InkWell(
- onTap: () async {
- setState(() {
- _index = SPORT_TYPE.indexOf(e);
- });
- },
- child: Container(
- decoration: BoxDecoration(border: Border.all(color: Color(0xffF3F3F3), width: 1), borderRadius: BorderRadius.circular(10.0)),
- padding: const EdgeInsets.symmetric(horizontal: 11, vertical: 10),
- margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
- child: Row(
- children: [
- Image.asset(
- "lib/assets/img/${e['i']}.png",
- height: 24,
- ),
- SizedBox(
- width: 10,
- ),
- Text(
- "${e['name']}运动",
- style: Theme.of(context).textTheme.subtitle1,
- ),
- Text(
- SPORT_TYPE.indexOf(e) == 0
- ? " ${SportUtils.calSportTypeDataStr(SPORT_TYPE.indexOf(e), SportUtils.calSportTypeData(SPORT_TYPE.indexOf(e), widget.sum.consume - widget.sum.consume_jog, weight) + widget.sum.distance_jog / 1000.0)} "
- : " ${SportUtils.calSportTypeDataStr(SPORT_TYPE.indexOf(e), SportUtils.calSportTypeData(SPORT_TYPE.indexOf(e), widget.sum.consume, weight))} ",
- style: Theme.of(context).textTheme.subtitle1,
- ),
- Text(
- "${e['unit']}",
- style: Theme.of(context).textTheme.subtitle1,
- ),
- Expanded(child: Container()),
- (SPORT_TYPE.indexOf(e) == _index)
- ? Image.asset(
- "lib/assets/img/pop_icon_connected.png",
- height: 20,
- )
- : Image.asset(
- "lib/assets/img/pop_icon_choose_normal.png",
- height: 20,
- ),
- ],
- ),
- )),
- )
- .toList(),
- ),
- Padding(
- padding: const EdgeInsets.only(
- bottom: 20,
- left: 12,
- right: 12,
- ),
- 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 {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- await prefs.setInt("sport_type", _index);
- Navigator.maybePop(context, true);
- },
- ),
- )),
- ],
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
|