You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
5.4 KiB
157 lines
5.4 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import '../controllers/agent_controller.dart';
|
|
|
|
String formatDistance(String distanceStr) {
|
|
final distance = double.tryParse(distanceStr);
|
|
if (distance == null) return distanceStr; // 如果无法解析,则返回原始字符串
|
|
|
|
if (distance >= 1000) {
|
|
final km = distance / 1000;
|
|
return '${km.toStringAsFixed(1)} 公里';
|
|
} else {
|
|
return '${distance.toStringAsFixed(0)} 米';
|
|
}
|
|
}
|
|
|
|
String formatDuration(String secondsStr) {
|
|
int totalSeconds = int.tryParse(secondsStr) ?? 0;
|
|
Duration duration = Duration(seconds: totalSeconds);
|
|
|
|
int hours = duration.inHours;
|
|
int minutes = duration.inMinutes.remainder(60);
|
|
int seconds = duration.inSeconds.remainder(60);
|
|
|
|
List<String> parts = [];
|
|
if (hours > 0) parts.add('$hours小时');
|
|
if (minutes > 0) parts.add('$minutes分钟');
|
|
if (seconds > 0 || parts.isEmpty) parts.add('$seconds秒');
|
|
|
|
return parts.join('');
|
|
}
|
|
|
|
//导航卡片
|
|
Widget navigationCard(
|
|
BuildContext context, {
|
|
required String start,
|
|
required String end,
|
|
required String destination,
|
|
required List<Map<String, dynamic>> modes,
|
|
Map<String, dynamic>? navigation,
|
|
double height = 300,
|
|
}) {
|
|
int currentIndex = 0;
|
|
final controller = Get.find<AgentController>(); // 获取控制器
|
|
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<String>(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, "");
|
|
},
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|