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.
161 lines
5.8 KiB
161 lines
5.8 KiB
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.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>(); // 获取控制器
|
|
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
|
|
|
return Container(
|
|
height: height.h,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(16.r),
|
|
color: isDarkMode ? const Color(0xFF1E1E1E) : Colors.white,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
blurRadius: 8,
|
|
color: Colors.black.withValues(alpha: isDarkMode ? 0.3 : 0.12),
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: StatefulBuilder(
|
|
builder: (context, setInnerState) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 路线图片
|
|
ClipRRect(
|
|
borderRadius:
|
|
BorderRadius.vertical(top: Radius.circular(16.r)),
|
|
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.h,
|
|
width: double.infinity,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
|
|
// 导航方式切换按钮
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 4.w),
|
|
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.w,
|
|
child: Text(
|
|
(modes[index]["ntype"] as String).tr,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
color: modes[index]['enable']
|
|
? isSelected
|
|
? Theme.of(context).primaryColor
|
|
: isDarkMode ? Colors.white.withValues(alpha: 0.9) : Colors.black87
|
|
: Colors.grey,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
|
|
// 距离和耗时
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 8.w),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(destination,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.white.withValues(alpha: 0.9) : Colors.black87)),
|
|
Text(
|
|
'${formatDistance(modes[currentIndex]["distance"])}-约${formatDuration(modes[currentIndex]["duration"])}',
|
|
style: TextStyle(
|
|
fontSize: 15.sp,
|
|
color: Theme.of(context).primaryColor)),
|
|
if (navigation != null)
|
|
Text(
|
|
"导航中... ${navigation["distanceText"]}进入${navigation["nextRoad"]}",
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
color: isDarkMode ? Colors.grey[400] : Colors.grey[600]))
|
|
],
|
|
),
|
|
CircleAvatar(
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
radius: 18.r,
|
|
child: IconButton(
|
|
icon: Icon(Icons.turn_left,
|
|
color: Colors.white, size: 20.sp),
|
|
onPressed: () {
|
|
controller.openNavigation(start, end, "");
|
|
},
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|