一键难忘头像
基于 Harmony 6.0 应用的夜跑安全伴行应用首页实现封面图

基于 Harmony 6.0 应用的夜跑安全伴行应用首页实现

基于 Harmony 6.0 应用的夜跑安全伴行应用首页实现

前言

夜跑既能避开白日炎热又能减压,但安全隐患是女性用户最大的顾虑。一款好的夜跑伴行应用要把"伴行模式 / SOS / 路线推荐 / 在线伴跑"四件事在一屏内全部铺到。Harmony 6.0 时代,夜跑安全类应用迎来了几个独特的能力红利——LocationKit 米级 GPS、HealthKit 心率监测、PushKit 紧急推送、HMS Account 家庭群组让家人远程查看、超级终端让手表协同。本文用 Flutter 在 Harmony 6.0 上实现一个夜跑伴行首页。
在这里插入图片描述

背景

夜跑安全类应用的视觉关键词是"安心、动感、夜晚"——深紫蓝 #312E81 配荧光紫 #A855F7 是这类应用的合适主色。本项目首页 5 个模块:渐变 Header(伴行状态 + 大开始按钮)、安全四维数据、推荐安全路线、在线伴跑、SOS 应急。

Flutter × Harmony 6.0 跨端开发介绍

Harmony 6.0 在夜跑安全类应用上的能力栈完整——LocationKit 米级 GPS、HealthKit 心率异常告警、PushKit 紧急推送给家人、HMS Account 家庭群组接入、超级终端让手表实时显示。

开发核心代码

代码一:伴行状态 Header

Widget _header() {
  return Container(
    padding: const EdgeInsets.all(20),
    decoration: BoxDecoration(
      gradient: const LinearGradient(
        colors: [_primary, Color(0xFF1E1B4B)],
        begin: Alignment.topLeft, end: Alignment.bottomRight),
      borderRadius: BorderRadius.circular(24),
    ),
    child: Column(children: [
      const Row(children: [
        Icon(Icons.shield_moon, color: Colors.white, size: 22),
        SizedBox(width: 8),
        Text('夜跑安心',
            style: TextStyle(color: Colors.white,
                fontSize: 18, fontWeight: FontWeight.w800)),
        Spacer(),
        Container(padding: EdgeInsets.symmetric(
            horizontal: 8, vertical: 3),
          decoration: BoxDecoration(
            color: Color(0xFF10B981),
            borderRadius: BorderRadius.all(Radius.circular(6))),
          child: Text('伴行中',
              style: TextStyle(color: Colors.white,
                  fontSize: 11, fontWeight: FontWeight.w800)),
        ),
      ]),
      const SizedBox(height: 16),
      const Text('🌙 今晚也要安全回家',
          style: TextStyle(color: Colors.white,
              fontSize: 22, fontWeight: FontWeight.w900)),
      const SizedBox(height: 8),
      const Text('伴跑 3 人 · 心率 142 · 距家 1.2km',
          style: TextStyle(color: Colors.white70, fontSize: 12)),
      const SizedBox(height: 14),
      Container(width: double.infinity, height: 50,
        decoration: BoxDecoration(color: Colors.white,
            borderRadius: BorderRadius.circular(25)),
        child: const Center(child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Icon(Icons.directions_run, color: _primary, size: 22),
            SizedBox(width: 6),
            Text('开始夜跑 · 自动通知家人',
                style: TextStyle(color: _primary,
                    fontSize: 16, fontWeight: FontWeight.w800)),
          ],
        )),
      ),
    ]),
  );
}

夜跑开始后通过 HMS Account 家庭群组自动通知家人 + LocationKit 实时位置共享 + HealthKit 心率监测——心率异常或停止运动 5 分钟自动告警。

从「伴行状态 Header」的安全感与实时陪伴设计角度再补一段。夜跑安全类应用的 Header 必须把「正在被谁守护 + 当前是否安全」一次性交付。这段 Header 用深蓝到紫色夜间渐变,配合「家人伴行中」chip、实时位置、心率和「结束夜跑」按钮,让用户感到不是独自跑步。如果未来要扩展支持「好友虚拟陪跑」,可以让好友实时看到路线并语音鼓励。鸿蒙 6.0 的家庭群组和 LocationKit 是安全陪伴的底层基础。
在这里插入图片描述

代码二:安全四维

Widget _safety() {
  final items = const [
    [Icons.location_on, '位置共享', '家人可见', _primary],
    [Icons.favorite, '心率监测', '142 bpm', _accent],
    [Icons.group, '伴跑', '3 人在线', _amber],
    [Icons.shield, 'SOS', '已就绪', _green],
  ];
  return GridView.count(
    crossAxisCount: 2, shrinkWrap: true,
    physics: const NeverScrollableScrollPhysics(),
    mainAxisSpacing: 10, crossAxisSpacing: 10,
    childAspectRatio: 2.4,
    children: items.map((it) {
      final c = it[3] as Color;
      return Container(padding: const EdgeInsets.all(14),
        decoration: BoxDecoration(
          color: const Color(0xFF1F2937),
          borderRadius: BorderRadius.circular(14)),
        child: Row(children: [
          Container(width: 40, height: 40,
            decoration: BoxDecoration(
              color: c.withValues(alpha: 0.16),
              borderRadius: BorderRadius.circular(10)),
            child: Icon(it[0] as IconData, color: c, size: 20),
          ),
          const SizedBox(width: 10),
          Expanded(child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(it[1] as String, style: const TextStyle(
                  color: Colors.white70, fontSize: 11)),
              const SizedBox(height: 2),
              Text(it[2] as String, style: TextStyle(
                  color: c, fontSize: 12,
                  fontWeight: FontWeight.w800)),
            ],
          )),
        ]),
      );
    }).toList(),
  );
}

安全四维(位置、心率、光照、陪跑)把夜跑风险拆成可监测的四个维度。位置看是否偏离路线,心率看身体异常,光照看环境安全,陪跑看是否有人关注。

从「安全四维」的风险分层与实时监测设计角度再补一段。夜跑风险不是单一维度,单靠定位不够。比如位置正常但心率异常,也需要提醒;路线偏暗或停止移动太久,也可能说明风险。每个维度用绿橙红状态 chip 表达,用户和家人都能快速理解。如果未来要扩展支持「路线安全评分」,可以结合路灯、摄像头、人流和历史事件数据计算。鸿蒙 6.0 的多传感器协同让夜跑安全监控更完整。

代码三:SOS 应急

Widget _sos() {
  return Container(padding: const EdgeInsets.all(16),
    decoration: BoxDecoration(color: _accent,
        borderRadius: BorderRadius.circular(16)),
    child: Row(children: [
      const Icon(Icons.sos, color: Colors.white, size: 38),
      const SizedBox(width: 12),
      const Expanded(child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('紧急 SOS · 长按 3 秒',
              style: TextStyle(color: Colors.white,
                  fontSize: 15, fontWeight: FontWeight.w800)),
          SizedBox(height: 4),
          Text('自动呼叫家人 + 110 + 共享位置',
              style: TextStyle(color: Colors.white70,
                  fontSize: 12)),
        ],
      )),
    ]),
  );
}

SOS 长按通过 PushKit 高优先级推送给所有紧急联系人 + 拨打 110 + 上报位置——多重保障。

从「SOS 应急」的紧急流程与误触防护设计角度再补一段。夜跑 SOS 不能太隐蔽,也不能轻易误触,所以长按触发 + 倒计时取消是最合理的交互。触发后应同时发送位置、心率、最后移动方向和紧急录音片段,给联系人更多判断依据。如果未来要扩展支持「自动触发」,可以在突然跌倒、长时间静止、心率异常时主动询问是否需要帮助。鸿蒙 6.0 的 PushKit 高优先级通道能保证紧急消息快速到达。
在这里插入图片描述

心得

夜跑安全类 App 的视觉灵魂是"安心 + 夜晚"——深紫色给夜晚氛围,"伴行中"绿色 chip 给安全感。开发时最容易犯的错是 SOS 按钮做得太小太隐蔽。我的策略是把 SOS 做成显眼大按钮 + 长按防误触。从能力扩展角度,夜跑安全最值得在鸿蒙端打造的是"LocationKit 实时位置 + HealthKit 心率监测 + PushKit 紧急推送 + HMS Account 家人接入"四件套。

总结

本篇实现了 Harmony 6.0 端的夜跑伴行首页,5 个模块、纯 UI、零依赖、约 320 行代码。从扩展角度建议生产业务里:把位置接入 LocationKit;把心率接入 HealthKit;把 SOS 接入 PushKit;把家人接入 HMS Account;把"夜跑中"做成 FormExtensionAbility 桌面卡片让家人查看。下一篇是第四十八组的第二块——宿舍报修与评价系统。

在这里插入图片描述

转载自 CSDN-专业IT技术社区

原文链接:https://blog.csdn.net/weixin_52908342/article/details/161903971

文章来源转载

评论

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:0
文章:0
关注标签:0
加入于:--