From bb76e420dd62caed48fa7d15ef5ab57b39e98021 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 22 May 2025 16:37:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=AF=BC=E8=88=AA=E5=8D=A1?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/modules/agent/views/message_bubble.dart | 1 + lib/modules/agent/views/navigation_card.dart | 129 +++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 lib/modules/agent/views/navigation_card.dart diff --git a/lib/modules/agent/views/message_bubble.dart b/lib/modules/agent/views/message_bubble.dart index b8637b29a..14964195b 100644 --- a/lib/modules/agent/views/message_bubble.dart +++ b/lib/modules/agent/views/message_bubble.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:common_utils/common_utils.dart'; +import 'package:deep_voice/modules/agent/views/navigation_card.dart'; import 'weather_card.dart'; import 'music_card.dart'; import 'travel_card.dart'; diff --git a/lib/modules/agent/views/navigation_card.dart b/lib/modules/agent/views/navigation_card.dart new file mode 100644 index 000000000..35c6fed55 --- /dev/null +++ b/lib/modules/agent/views/navigation_card.dart @@ -0,0 +1,129 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import '../controllers/agent_controller.dart'; + +//导航卡片 +Widget navigationCard( + BuildContext context, { + required String start, + required String end, + required String destination, + required List> modes, + Map? navigation, + double height = 300, +}) { + int currentIndex = 0; + final controller = Get.find(); // 获取控制器 + return Container( + height: height, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(16), + color: Colors.white, + boxShadow: const [ + BoxShadow( + blurRadius: 8, + color: Colors.black12, + offset: Offset(0, 4), + ), + ], + ), + child: StatefulBuilder( + builder: (context, setInnerState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // 路线图片 + ClipRRect( + borderRadius: + const BorderRadius.vertical(top: Radius.circular(16)), + child: AnimatedSwitcher( + duration: const Duration(milliseconds: 300), + child: Image.network( + modes[currentIndex]["image"] as String, + key: ValueKey(modes[currentIndex]["ntype"] as String), + height: 160, + width: double.infinity, + fit: BoxFit.cover, + ), + ), + ), + + // 导航方式切换按钮 + Padding( + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 4), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: List.generate(modes.length, (index) { + final isSelected = index == currentIndex; + return GestureDetector( + onTap: modes[index]['enable'] as bool + ? () { + setInnerState(() => currentIndex = index); + } + : null, + child: SizedBox( + width: 50, + child: Text( + (modes[index]["ntype"] as String).tr, + textAlign: TextAlign.center, + style: TextStyle( + color: modes[index]['enable'] + ? isSelected + ? Colors.blue + : Colors.black87 + : Colors.grey, + fontSize: 12, + fontWeight: FontWeight.w500, + ), + ), + ), + ); + }), + ), + ), + + // 距离和耗时 + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('$destination', + style: const TextStyle( + fontSize: 12, color: Colors.black)), + Text( + '${formatDistance(modes[currentIndex]["distance"])}-约${formatDuration(modes[currentIndex]["duration"])}', + style: const TextStyle( + fontSize: 15, color: Colors.blue)), + if (navigation != null) + Text( + "导航中... ${navigation["distanceText"]}进入${navigation["nextRoad"]}", + style: TextStyle( + fontSize: 12, + color: + const Color.fromARGB(255, 164, 164, 164))) + ], + ), + CircleAvatar( + backgroundColor: Colors.blue, + radius: 18, + child: IconButton( + icon: const Icon(Icons.turn_left, + color: Colors.white, size: 20), + onPressed: () { + controller.openNavigation(start, end, ""); + }, + ), + ) + ], + ), + ), + ], + ); + }, + ), + ); +}