123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:permission_handler/permission_handler.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:sport/services/app_lifecycle_state.dart';
- import 'package:sport/widgets/appbar.dart';
- import 'package:sport/widgets/button_primary.dart';
- import 'package:sport/widgets/game_run.dart';
- class SettingHealthKitPage extends StatefulWidget {
- @override
- State<StatefulWidget> createState() => _PageState();
- }
- class _PageState extends LifecycleState<SettingHealthKitPage> {
- bool _connected = false;
- @override
- void initState() {
- super.initState();
- SharedPreferences.getInstance().then((value) {
- setState(() {
- _connected = value.containsKey("HEALTH_KIT_CONNECTED");
- });
- });
- }
- @override
- void dispose() {
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.white,
- appBar: buildAppBar(context, title: "连接苹果健康"),
- body: SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.all(20.0),
- child: Column(
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 58.0),
- child: Center(
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Image.asset(
- "lib/assets/img/logo_img.png",
- width: 60.0,
- ),
- Container(
- width: 6,
- height: 6,
- decoration: BoxDecoration(shape: BoxShape.circle, color: Theme.of(context).accentColor),
- margin: EdgeInsets.only(left: 12.0),
- ),
- Container(
- width: 6,
- height: 6,
- decoration: BoxDecoration(shape: BoxShape.circle, color: Theme.of(context).scaffoldBackgroundColor),
- margin: EdgeInsets.symmetric(horizontal: 12.0),
- ),
- Container(
- width: 6,
- height: 6,
- decoration: BoxDecoration(shape: BoxShape.circle, color: Theme.of(context).scaffoldBackgroundColor),
- margin: EdgeInsets.only(right: 12.0),
- ),
- Image.asset(
- "lib/assets/img/icon_ioshealthy.png",
- width: 60.0,
- ),
- ],
- ),
- ),
- ),
- Text(
- "连接【健康】后,“趣动”会同步并更新你的活动能量和体能训练数据到苹果健康中心。你也可以进入【健康】的数据来源中,选择并修改“趣动”更新的健康数据类型",
- style: Theme.of(context).textTheme.subtitle1,
- ),
- SizedBox(
- height: 58.0,
- ),
- if (_connected)
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 12.0),
- child: Text(
- "您已连接过【健康】,可以【健康】去查看设置",
- ),
- ),
- _connected
- ? PrimaryButton(
- content: "查看设置",
- callback: () async {
- openAppSettings();
- },
- )
- : PrimaryButton(
- content: "前往连接",
- callback: () async {
- if (Platform.isIOS) {
- await connectHealthKit();
- SharedPreferences p = await SharedPreferences.getInstance();
- await p.setBool("HEALTH_KIT_CONNECTED", true);
- Navigator.pop(context);
- }
- },
- ),
- SizedBox(
- height: 24.0,
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
|