退出登录+机器状态+切换设备+历史作业记录+设备信息
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import 'package:cc_ui_kit/cc_ui_kit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
|
||||
import '../../../../core/app/app_user_cubit.dart';
|
||||
import '../../../../core/router/route_paths.dart';
|
||||
import '../../../devices/presentation/bloc/devices_cubit.dart';
|
||||
import '../../../devices/presentation/bloc/devices_state.dart';
|
||||
// 导入你的主题文件以获取 offWhite
|
||||
@@ -391,8 +393,10 @@ class ImmersionHeader extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
CCPrimaryButton(
|
||||
onPressed: () {
|
||||
context.push(RoutePaths.machineDetails);
|
||||
print("通过按钮进入详情");
|
||||
},
|
||||
|
||||
text: "详情",
|
||||
width: 80,
|
||||
height: 30,
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'dart:math';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
class CoordTransform {
|
||||
static const double pi = 3.1415926535897932384626;
|
||||
static const double a = 6378245.0;
|
||||
static const double ee = 0.00669342162296594323;
|
||||
|
||||
static bool outOfChina(double lat, double lon) {
|
||||
return lon < 72.004 || lon > 137.8347 || lat < 0.8293 || lat > 55.8271;
|
||||
}
|
||||
|
||||
/// WGS84 → GCJ02(GPS → 高德)
|
||||
static LatLng wgs84ToGcj02(double lat, double lon) {
|
||||
if (outOfChina(lat, lon)) {
|
||||
return LatLng(lat, lon);
|
||||
}
|
||||
|
||||
double dLat = _transformLat(lon - 105.0, lat - 35.0);
|
||||
double dLon = _transformLon(lon - 105.0, lat - 35.0);
|
||||
double radLat = lat / 180.0 * pi;
|
||||
double magic = sin(radLat);
|
||||
magic = 1 - ee * magic * magic;
|
||||
double sqrtMagic = sqrt(magic);
|
||||
|
||||
dLat = (dLat * 180.0) /
|
||||
((a * (1 - ee)) / (magic * sqrtMagic) * pi);
|
||||
dLon = (dLon * 180.0) /
|
||||
(a / sqrtMagic * cos(radLat) * pi);
|
||||
|
||||
return LatLng(lat + dLat, lon + dLon);
|
||||
}
|
||||
|
||||
static double _transformLat(double x, double y) {
|
||||
return -100.0 +
|
||||
2.0 * x +
|
||||
3.0 * y +
|
||||
0.2 * y * y +
|
||||
0.1 * x * y +
|
||||
0.2 * sqrt(x.abs());
|
||||
}
|
||||
|
||||
static double _transformLon(double x, double y) {
|
||||
return 300.0 +
|
||||
x +
|
||||
2.0 * y +
|
||||
0.1 * x * x +
|
||||
0.1 * x * y +
|
||||
0.1 * sqrt(x.abs());
|
||||
}
|
||||
}
|
||||
178
lib/features/home/presentation/widgets/map/test_amap_page.dart
Normal file
178
lib/features/home/presentation/widgets/map/test_amap_page.dart
Normal file
@@ -0,0 +1,178 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import 'CoordTransform/coord_transform.dart';
|
||||
|
||||
class AmapFlutterMapPage extends StatefulWidget {
|
||||
const AmapFlutterMapPage({super.key});
|
||||
|
||||
@override
|
||||
State<AmapFlutterMapPage> createState() => _AmapFlutterMapPageState();
|
||||
}
|
||||
|
||||
class _AmapFlutterMapPageState extends State<AmapFlutterMapPage> {
|
||||
final MapController _mapController = MapController();
|
||||
static const String amapKey = "bbb1f0f20eed6bf679eddf2625630aba";
|
||||
|
||||
LatLng _currentCenter = const LatLng(39.908823, 116.397470);
|
||||
bool _isLoading = true;
|
||||
// 新增:标记页面是否已销毁,防止异步操作访问已释放的控制器
|
||||
bool _isDisposed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_checkAndGetLocation();
|
||||
});
|
||||
}
|
||||
|
||||
// 新增:页面销毁时标记状态
|
||||
@override
|
||||
void dispose() {
|
||||
_isDisposed = true; // 先标记销毁状态
|
||||
// _mapController.dispose(); // 再销毁控制器
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _checkAndGetLocation() async {
|
||||
var status = await Permission.location.status;
|
||||
if (status.isDenied) {
|
||||
status = await Permission.location.request();
|
||||
if (status.isDenied) {
|
||||
if (!_isDisposed) { // 防护:页面没销毁才弹提示
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('定位权限被拒绝,无法获取当前位置')),
|
||||
);
|
||||
setState(() { _isLoading = false; });
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (status.isPermanentlyDenied) {
|
||||
if (!_isDisposed) { // 防护:页面没销毁才弹提示
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('定位权限被永久拒绝,请去设置开启'),
|
||||
action: SnackBarAction(label: '去设置', onPressed: openAppSettings),
|
||||
),
|
||||
);
|
||||
setState(() { _isLoading = false; });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
await _getCurrentLocation();
|
||||
}
|
||||
|
||||
Future<void> _getCurrentLocation() async {
|
||||
if (_isDisposed) return;
|
||||
|
||||
setState(() { _isLoading = true; });
|
||||
print('📍 开始定位...');
|
||||
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
if (!_isDisposed) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('定位服务未启用,请开启定位服务')),
|
||||
);
|
||||
setState(() { _isLoading = false; });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.bestForNavigation,
|
||||
forceAndroidLocationManager: true,
|
||||
timeLimit: const Duration(seconds: 8),
|
||||
);
|
||||
|
||||
if (_isDisposed) return;
|
||||
|
||||
// ⭐⭐⭐ 关键修复点:WGS84 → GCJ02 ⭐⭐⭐
|
||||
final gcjPoint = CoordTransform.wgs84ToGcj02(
|
||||
position.latitude,
|
||||
position.longitude,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_currentCenter = gcjPoint;
|
||||
_isLoading = false;
|
||||
});
|
||||
|
||||
if (!_isDisposed) {
|
||||
_mapController.move(gcjPoint, 15.0);
|
||||
}
|
||||
|
||||
print('✅ 定位成功(GCJ02): ${gcjPoint.latitude}, ${gcjPoint.longitude}');
|
||||
} catch (e) {
|
||||
if (!_isDisposed) {
|
||||
setState(() { _isLoading = false; });
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('定位失败: $e'),
|
||||
action: SnackBarAction(
|
||||
label: '重试',
|
||||
onPressed: _checkAndGetLocation,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('路径规划'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.my_location),
|
||||
onPressed: _checkAndGetLocation,
|
||||
tooltip: '定位到我的位置',
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: FlutterMap(
|
||||
mapController: _mapController,
|
||||
options: MapOptions(
|
||||
center: _currentCenter,
|
||||
zoom: 15.0,
|
||||
minZoom: 3.0,
|
||||
maxZoom: 18.0,
|
||||
interactiveFlags: InteractiveFlag.all,
|
||||
),
|
||||
children: [
|
||||
TileLayer(
|
||||
urlTemplate:
|
||||
"https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}&key=$amapKey",
|
||||
subdomains: const ['1', '2', '3', '4'],
|
||||
tileProvider: NetworkTileProvider(),
|
||||
),
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
Marker(
|
||||
point: _currentCenter,
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: const Icon(Icons.location_on, color: Colors.red, size: 40),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
228
lib/features/home/presentation/widgets/map/testmap_pages.dart
Normal file
228
lib/features/home/presentation/widgets/map/testmap_pages.dart
Normal file
@@ -0,0 +1,228 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
import '../path_list_pages.dart';
|
||||
|
||||
class MapPageEnterprise extends StatefulWidget {
|
||||
const MapPageEnterprise({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MapPageEnterprise> createState() => _MapPageEnterpriseState();
|
||||
}
|
||||
|
||||
class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
final MapController _mapController = MapController();
|
||||
|
||||
LatLng? _currentLatLng;
|
||||
StreamSubscription<Position>? _positionSub;
|
||||
bool _hasMovedOnce = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initLocationEnterprise();
|
||||
}
|
||||
|
||||
/// ===============================
|
||||
/// 企业级定位初始化(已修复坐标系)
|
||||
/// ===============================
|
||||
Future<void> _initLocationEnterprise() async {
|
||||
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) return;
|
||||
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
if (permission != LocationPermission.whileInUse &&
|
||||
permission != LocationPermission.always) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1️⃣ 首次强制获取定位
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.bestForNavigation,
|
||||
);
|
||||
|
||||
final gcj = wgs84ToGcj02(position.latitude, position.longitude);
|
||||
_updateLocation(gcj, moveMap: true);
|
||||
|
||||
// 2️⃣ 实时监听(不再强制移动地图)
|
||||
_positionSub = Geolocator.getPositionStream(
|
||||
locationSettings: const LocationSettings(
|
||||
accuracy: LocationAccuracy.bestForNavigation,
|
||||
distanceFilter: 2,
|
||||
),
|
||||
).listen((pos) {
|
||||
final gcj = wgs84ToGcj02(pos.latitude, pos.longitude);
|
||||
_updateLocation(gcj, moveMap: false);
|
||||
});
|
||||
}
|
||||
|
||||
/// ===============================
|
||||
/// 更新位置
|
||||
/// ===============================
|
||||
void _updateLocation(LatLng latLng, {bool moveMap = false}) {
|
||||
setState(() {
|
||||
_currentLatLng = latLng;
|
||||
});
|
||||
|
||||
if (moveMap && !_hasMovedOnce) {
|
||||
_hasMovedOnce = true;
|
||||
_mapController.move(latLng, 17);
|
||||
}
|
||||
}
|
||||
|
||||
/// 手动回到当前位置
|
||||
void _moveToCurrentLocation() {
|
||||
if (_currentLatLng == null) return;
|
||||
_mapController.move(_currentLatLng!, 17);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_positionSub?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenHeight = MediaQuery.of(context).size.height;
|
||||
final menuHeight = 16 * 6; // 假设 VerticalFloatMenu 有 6 个选项,每个高度为 56
|
||||
final maxTop = screenHeight - menuHeight;
|
||||
return Scaffold(
|
||||
body:
|
||||
SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
FlutterMap(
|
||||
mapController: _mapController,
|
||||
options: MapOptions(
|
||||
initialCenter:
|
||||
_currentLatLng ?? const LatLng(39.9042, 116.4074),
|
||||
initialZoom: 15,
|
||||
maxZoom: 18,
|
||||
),
|
||||
children: [
|
||||
/// 高德瓦片(GCJ-02)
|
||||
TileLayer(
|
||||
urlTemplate:
|
||||
'https://webrd02.is.autonavi.com/appmaptile'
|
||||
'?style=8&x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1'
|
||||
'&key=bbb1f0f20eed6bf679eddf2625630aba',
|
||||
),
|
||||
|
||||
/// 当前定位 Marker
|
||||
if (_currentLatLng != null)
|
||||
MarkerLayer(
|
||||
markers: [
|
||||
Marker(
|
||||
point: _currentLatLng!,
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: const Icon(
|
||||
Icons.my_location,
|
||||
color: Colors.blue,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Positioned(
|
||||
height: 336,
|
||||
right: 16,
|
||||
top: maxTop > 10 ? 11 : maxTop, // 确保不超出屏幕范围
|
||||
child: FloatingActionButton(
|
||||
onPressed: _moveToCurrentLocation,
|
||||
child: new VerticalFloatMenu(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// =======================================================
|
||||
/// 坐标转换:WGS84 -> GCJ02(国内高德/腾讯通用)
|
||||
/// =======================================================
|
||||
|
||||
const double _pi = 3.14159265358979324;
|
||||
const double _a = 6378245.0;
|
||||
const double _ee = 0.00669342162296594323;
|
||||
|
||||
LatLng wgs84ToGcj02(double lat, double lon) {
|
||||
if (_outOfChina(lat, lon)) {
|
||||
return LatLng(lat, lon);
|
||||
}
|
||||
double dLat = _transformLat(lon - 105.0, lat - 35.0);
|
||||
double dLon = _transformLon(lon - 105.0, lat - 35.0);
|
||||
double radLat = lat / 180.0 * _pi;
|
||||
double magic = sin(radLat);
|
||||
magic = 1 - _ee * magic * magic;
|
||||
double sqrtMagic = sqrt(magic);
|
||||
dLat = (dLat * 180.0) /
|
||||
((_a * (1 - _ee)) / (magic * sqrtMagic) * _pi);
|
||||
dLon = (dLon * 180.0) / (_a / sqrtMagic * cos(radLat) * _pi);
|
||||
double mgLat = lat + dLat;
|
||||
double mgLon = lon + dLon;
|
||||
return LatLng(mgLat, mgLon);
|
||||
}
|
||||
|
||||
bool _outOfChina(double lat, double lon) {
|
||||
return lon < 72.004 ||
|
||||
lon > 137.8347 ||
|
||||
lat < 0.8293 ||
|
||||
lat > 55.8271;
|
||||
}
|
||||
|
||||
double _transformLat(double x, double y) {
|
||||
double ret = -100.0 +
|
||||
2.0 * x +
|
||||
3.0 * y +
|
||||
0.2 * y * y +
|
||||
0.1 * x * y +
|
||||
0.2 * sqrt(x.abs());
|
||||
ret += (20.0 * sin(6.0 * x * _pi) +
|
||||
20.0 * sin(2.0 * x * _pi)) *
|
||||
2.0 /
|
||||
3.0;
|
||||
ret += (20.0 * sin(y * _pi) +
|
||||
40.0 * sin(y / 3.0 * _pi)) *
|
||||
2.0 /
|
||||
3.0;
|
||||
ret += (160.0 * sin(y / 12.0 * _pi) +
|
||||
320 * sin(y * _pi / 30.0)) *
|
||||
2.0 /
|
||||
3.0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
double _transformLon(double x, double y) {
|
||||
double ret = 300.0 +
|
||||
x +
|
||||
2.0 * y +
|
||||
0.1 * x * x +
|
||||
0.1 * x * y +
|
||||
0.1 * sqrt(x.abs());
|
||||
ret += (20.0 * sin(6.0 * x * _pi) +
|
||||
20.0 * sin(2.0 * x * _pi)) *
|
||||
2.0 /
|
||||
3.0;
|
||||
ret += (20.0 * sin(x * _pi) +
|
||||
40.0 * sin(x / 3.0 * _pi)) *
|
||||
2.0 /
|
||||
3.0;
|
||||
ret += (150.0 * sin(x / 12.0 * _pi) +
|
||||
300.0 * sin(x / 30.0 * _pi)) *
|
||||
2.0 /
|
||||
3.0;
|
||||
return ret;
|
||||
}
|
||||
86
lib/features/home/presentation/widgets/path_list_pages.dart
Normal file
86
lib/features/home/presentation/widgets/path_list_pages.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 垂直侧边功能菜单组件 - 纯白不透明长方形、独立可复用
|
||||
class VerticalFloatMenu extends StatefulWidget {
|
||||
// 外部可传点击回调,获取选中的索引和名称(可选)
|
||||
final Function(int index, String name)? onItemTap;
|
||||
|
||||
const VerticalFloatMenu({super.key, this.onItemTap});
|
||||
|
||||
@override
|
||||
State<VerticalFloatMenu> createState() => _VerticalFloatMenuState();
|
||||
}
|
||||
|
||||
class _VerticalFloatMenuState extends State<VerticalFloatMenu> {
|
||||
// 默认选中「编辑」项(索引4),与原设计一致
|
||||
int _selectedIndex = 4;
|
||||
|
||||
// 菜单配置:图标+名称,和原截图完全对应
|
||||
final List<Map<String, dynamic>> _menuItems = const [
|
||||
{"icon": Icons.crop_free, "name": "圈地"},
|
||||
{"icon": Icons.format_list_bulleted, "name": "列表"},
|
||||
{"icon": Icons.train, "name": "场站"},
|
||||
{"icon": Icons.navigation, "name": "定位"},
|
||||
{"icon": Icons.edit_note, "name": "编辑"},
|
||||
{"icon": Icons.videocam, "name": "监控"},
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 纯白不透明 + 固定长方形宽度,无阴影/圆角(纯基础样式)
|
||||
return Container(
|
||||
width: 56, // 适配悬浮按钮的窄长方形宽度,可自行微调
|
||||
color: Colors.white, // 纯白不透明背景,核心要求
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min, // 高度自适应子项,不占多余空间
|
||||
children: _menuItems
|
||||
.asMap()
|
||||
.entries
|
||||
.map((entry) => _buildMenuItem(
|
||||
entry.value["icon"],
|
||||
entry.key,
|
||||
entry.value["name"],
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建单个菜单项(含选中高亮、点击事件)
|
||||
Widget _buildMenuItem(IconData icon, int index, String name) {
|
||||
final isSelected = _selectedIndex == index;
|
||||
return InkWell(
|
||||
// 点击切换选中状态+触发外部回调
|
||||
onTap: () {
|
||||
setState(() => _selectedIndex = index);
|
||||
if (widget.onItemTap != null) widget.onItemTap!(index, name);
|
||||
},
|
||||
child: Container(
|
||||
width: double.infinity, // 撑满父容器宽度,保证点击区域
|
||||
height: 56, // 单个项固定高度,视觉均匀
|
||||
alignment: Alignment.center,
|
||||
// 选中项高亮背景(浅蓝,可自行改色)
|
||||
color: isSelected ? Colors.lightBlue[50] : Colors.white,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: isSelected ? Colors.lightBlue : Colors.black,
|
||||
size: 22, // 图标大小微调,适配窄宽度
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
fontSize: 10, // 文字大小适配窄宽度
|
||||
color: isSelected ? Colors.lightBlue : Colors.black,
|
||||
height: 1, // 取消文字默认行高,避免高度过高
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:fpdart/fpdart.dart' hide State;
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/usecases/device_work_hostrirty_usecase.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/entities/device_run_hostrity_entity.dart';
|
||||
import 'package:maibu_satabot_v2/features/devices/domain/errors/device_failure.dart';
|
||||
|
||||
class WorkParamsCard extends StatelessWidget {
|
||||
import '../../../../core/di/injection.dart';
|
||||
import '../../../devices/presentation/bloc/devices_cubit.dart';
|
||||
|
||||
class WorkParamsCard extends StatefulWidget {
|
||||
const WorkParamsCard({super.key});
|
||||
|
||||
@override
|
||||
State<WorkParamsCard> createState() => _WorkParamsCardState();
|
||||
}
|
||||
|
||||
class _WorkParamsCardState extends State<WorkParamsCard> {
|
||||
List<DeviceRunStatisticsEntity>? _statistics;
|
||||
String? _errorMessage;
|
||||
bool _isLoading = false; // 默认不加载
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final deviceState = context.watch<DevicesCubit>().state;
|
||||
final currentDevice = deviceState.selectedDevice;
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
// 极淡的阴影
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.02),
|
||||
@@ -23,13 +42,11 @@ class WorkParamsCard extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题行
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
// 左侧蓝色装饰条
|
||||
Container(
|
||||
width: 4,
|
||||
height: 16,
|
||||
@@ -49,27 +66,28 @@ class WorkParamsCard extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
// 刷新状态
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.refresh, size: 14, color: Colors.grey[400]),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'刚刚更新',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[400]),
|
||||
),
|
||||
],
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_handleInfoTap(currentDevice); // 包装在同步函数中
|
||||
}, // 点击事件处理
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.info, size: 14, color: Colors.grey[400]),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'查看详情',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[400]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 数据展示行
|
||||
IntrinsicHeight(
|
||||
// 关键:使分割线高度自动充满
|
||||
child: Row(
|
||||
children: [
|
||||
_buildParamItem('作业面积', '0', '亩'),
|
||||
_buildParamItem('作业面积', '0', '亩'), // 默认值
|
||||
_buildDivider(),
|
||||
_buildParamItem('作业里程', '0', 'km'),
|
||||
_buildDivider(),
|
||||
@@ -82,6 +100,185 @@ class WorkParamsCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// 点击事件处理
|
||||
Future<void> _handleInfoTap(DeviceEntity? currentDevice) async {
|
||||
print("点击触摸了历史作业");
|
||||
setState(() {
|
||||
_isLoading = true; // 开始加载
|
||||
_errorMessage = null; // 清除错误信息
|
||||
});
|
||||
print("开始历史作业");
|
||||
try {
|
||||
final useCase = DeviceWorkHostrirty(sl());
|
||||
print("发送获取历史作业记录开始");
|
||||
//displayName
|
||||
final deviceId = currentDevice?.deviceName.toString() ?? '';
|
||||
final params = BindDeviceParams(deviceId, 'your_device_alias');
|
||||
final result = await useCase(params);
|
||||
print("发送获取历史作业记录结束");
|
||||
result.fold(
|
||||
(failure) {
|
||||
setState(() {
|
||||
_errorMessage = failure.message;
|
||||
_isLoading = false;
|
||||
});
|
||||
},
|
||||
(data) {
|
||||
setState(() {
|
||||
_statistics = data;
|
||||
_isLoading = false;
|
||||
});
|
||||
_showDetailsDialog(context, _statistics!); // 展示弹窗
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
print("捕获异常: $e");
|
||||
setState(() {
|
||||
_errorMessage = '请求失败: $e';
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 弹窗展示详情
|
||||
// 弹窗展示详情(从底部弹出)
|
||||
// 弹窗展示详情(从底部弹出,覆盖底部导航栏)
|
||||
void _showDetailsDialog(BuildContext context, List<DeviceRunStatisticsEntity> data) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true, // 支持全屏高度
|
||||
useRootNavigator: true, // 覆盖底部导航栏
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)), // 顶部圆角
|
||||
),
|
||||
builder: (context) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height * 0.75, // 占据屏幕 75% 高度
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 顶部拖拽指示器
|
||||
Center(
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 标题
|
||||
const Text(
|
||||
'历史记录详情',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 内容区域
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: data.map((item) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.withOpacity(0.05), // 浅蓝背景
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.blue.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildDetailRow(Icons.calendar_today, '开始时间', item.startTime),
|
||||
_buildDetailRow(Icons.calendar_today_outlined, '结束时间', item.endTime),
|
||||
_buildDetailRow(Icons.square_foot, '工作面积', '${item.workArea} 亩'),
|
||||
_buildDetailRow(
|
||||
Icons.directions_car,
|
||||
'工作距离',
|
||||
'${item.distance?.toStringAsFixed(2) ?? '未计算'} km',
|
||||
),
|
||||
_buildDetailRow(Icons.timer, '花费时间', '${item.time} 小时'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 关闭按钮
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'关闭',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 构建详情行
|
||||
Widget _buildDetailRow(IconData icon, String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: Colors.blue),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'$label: ',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.black54,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 构建单个参数项
|
||||
Widget _buildParamItem(String label, String value, String unit) {
|
||||
return Expanded(
|
||||
@@ -116,7 +313,7 @@ class WorkParamsCard extends StatelessWidget {
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black,
|
||||
fontFamily: 'Inter', // 建议使用数字显示更漂亮的字体
|
||||
fontFamily: 'Inter',
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
|
||||
Reference in New Issue
Block a user