2024-08-20 17:44:39 +08:00
|
|
|
import 'package:cpnav/pages/pass_track/view.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
2024-08-21 17:38:18 +08:00
|
|
|
import 'package:get/get.dart';
|
2024-08-26 18:25:21 +08:00
|
|
|
import 'package:scence_map/controllers/controller.dart';
|
|
|
|
|
2024-08-21 17:38:18 +08:00
|
|
|
|
|
|
|
ScenceMapController mapController = Get.put(ScenceMapController());
|
2024-08-20 17:44:39 +08:00
|
|
|
|
|
|
|
class IconContainer extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_IconContainerState createState() => _IconContainerState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _IconContainerState extends State<IconContainer> {
|
|
|
|
final Map<IconData, Color> _iconColors = {
|
|
|
|
Icons.article: Colors.green,
|
2024-08-21 17:38:18 +08:00
|
|
|
Icons.speed: const Color.fromARGB(255, 166, 182, 149),
|
|
|
|
Icons.thermostat: const Color.fromARGB(255, 166, 182, 149),
|
|
|
|
Icons.zoom_in: const Color.fromARGB(255, 166, 182, 149),
|
|
|
|
Icons.zoom_out: const Color.fromARGB(255, 166, 182, 149),
|
|
|
|
Icons.refresh: const Color.fromARGB(255, 166, 182, 149),
|
|
|
|
Icons.place: const Color.fromARGB(255, 166, 182, 149),
|
2024-08-20 17:44:39 +08:00
|
|
|
};
|
2024-08-21 17:38:18 +08:00
|
|
|
IconData? _selectedIcon;
|
|
|
|
|
|
|
|
void _handleTap1(IconData icon, VoidCallback onTap) {
|
|
|
|
setState(() {
|
|
|
|
_selectedIcon = icon;
|
|
|
|
_iconColors.forEach((key, value) {
|
|
|
|
_iconColors[key] = key == icon
|
|
|
|
? Colors.green // 点击后变浅的颜色
|
|
|
|
: const Color.fromARGB(255, 166, 182, 149); // 其他图标恢复原色
|
|
|
|
});
|
|
|
|
});
|
|
|
|
onTap();
|
|
|
|
}
|
2024-08-20 17:44:39 +08:00
|
|
|
|
2024-08-21 17:38:18 +08:00
|
|
|
void _handleTap2(IconData icon, VoidCallback onTap) {
|
2024-08-20 17:44:39 +08:00
|
|
|
setState(() {
|
2024-08-21 17:38:18 +08:00
|
|
|
_iconColors[icon] = Colors.green; // 点击后变浅的颜色
|
2024-08-20 17:44:39 +08:00
|
|
|
});
|
|
|
|
onTap();
|
|
|
|
Future.delayed(Duration(milliseconds: 200), () {
|
|
|
|
setState(() {
|
2024-08-21 17:38:18 +08:00
|
|
|
_iconColors[icon] = const Color.fromARGB(255, 166, 182, 149); // 恢复原色
|
2024-08-20 17:44:39 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var isPortrait = MediaQuery.of(context).orientation == Orientation.portrait;
|
|
|
|
return isPortrait
|
|
|
|
? Positioned(
|
|
|
|
right: 10,
|
|
|
|
bottom: 130,
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Container(
|
2024-08-21 17:38:18 +08:00
|
|
|
width: 42,
|
2024-08-20 17:44:39 +08:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.transparent,
|
|
|
|
border: Border.all(
|
|
|
|
color: Color.fromARGB(255, 54, 52, 52),
|
|
|
|
width: 1.0,
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2024-08-21 17:38:18 +08:00
|
|
|
_singleChange(Icons.article, () {}),
|
|
|
|
_singleChange(Icons.speed, () {
|
2024-08-20 17:44:39 +08:00
|
|
|
// 处理 speed 图标的点击事件
|
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_singleChange(Icons.thermostat, () {
|
2024-08-20 17:44:39 +08:00
|
|
|
// 处理 thermostat 图标的点击事件
|
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.zoom_in, () {
|
|
|
|
mapcontroller.scale = mapcontroller.scale * 0.5;
|
|
|
|
if (mapcontroller.scale < 0.2) {
|
|
|
|
mapcontroller.scale = 0.2;
|
|
|
|
const snackBar = SnackBar(
|
|
|
|
content: Text("当前已到放大比例极限"),
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
);
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
mapcontroller.rotation.value = 0.0;
|
|
|
|
mapcontroller.updateCount.value++;
|
2024-08-20 17:44:39 +08:00
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.zoom_out, () {
|
|
|
|
mapcontroller.scale = mapcontroller.scale / 0.5;
|
|
|
|
|
|
|
|
if (mapcontroller.scale > 200) {
|
|
|
|
mapcontroller.scale = 200;
|
|
|
|
// 提示最大比例
|
|
|
|
const snackBar = SnackBar(
|
|
|
|
content: Text("当前已到缩小比例极限"),
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
);
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
mapcontroller.rotation.value = 0.0;
|
|
|
|
mapcontroller.updateCount.value++;
|
2024-08-20 17:44:39 +08:00
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.refresh, () {
|
|
|
|
mapcontroller.scale = 1.0;
|
|
|
|
mapcontroller.rotation.value = 0.0;
|
|
|
|
mapcontroller.updateCount.value++;
|
2024-08-20 17:44:39 +08:00
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.place, () {
|
2024-08-20 17:44:39 +08:00
|
|
|
// 处理 place 图标的点击事件
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
))
|
|
|
|
: Positioned(
|
|
|
|
right: 10,
|
|
|
|
bottom: 15,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Container(
|
2024-08-21 17:38:18 +08:00
|
|
|
height: 42,
|
2024-08-20 17:44:39 +08:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.transparent,
|
|
|
|
border: Border.all(
|
|
|
|
color: Color.fromARGB(255, 54, 52, 52),
|
|
|
|
width: 1.0,
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2024-08-21 17:38:18 +08:00
|
|
|
_singleChange(Icons.article, () {
|
2024-08-20 17:44:39 +08:00
|
|
|
mapcontroller.scale = 1.0;
|
|
|
|
mapcontroller.rotation.value = 0.0;
|
|
|
|
mapcontroller.updateCount.value++;
|
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_singleChange(Icons.speed, () {
|
2024-08-20 17:44:39 +08:00
|
|
|
// 处理 speed 图标的点击事件
|
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_singleChange(Icons.thermostat, () {
|
2024-08-20 17:44:39 +08:00
|
|
|
// 处理 thermostat 图标的点击事件
|
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.zoom_in, () {
|
|
|
|
mapcontroller.scale = mapcontroller.scale * 0.5;
|
|
|
|
if (mapcontroller.scale < 0.2) {
|
|
|
|
mapcontroller.scale = 0.2;
|
|
|
|
const snackBar = SnackBar(
|
|
|
|
content: Text("当前已到放大比例极限"),
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
);
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
mapcontroller.rotation.value = 0.0;
|
|
|
|
mapcontroller.updateCount.value++;
|
2024-08-20 17:44:39 +08:00
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.zoom_out, () {
|
|
|
|
mapcontroller.scale = mapcontroller.scale / 0.5;
|
|
|
|
|
|
|
|
if (mapcontroller.scale > 200) {
|
|
|
|
mapcontroller.scale = 200;
|
|
|
|
// 提示最大比例
|
|
|
|
const snackBar = SnackBar(
|
|
|
|
content: Text("当前已到缩小比例极限"),
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
);
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|
|
|
|
|
|
|
|
mapcontroller.rotation.value = 0.0;
|
|
|
|
mapcontroller.updateCount.value++;
|
2024-08-20 17:44:39 +08:00
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.refresh, () {
|
|
|
|
mapcontroller.scale = 1.0;
|
|
|
|
mapcontroller.rotation.value = 0.0;
|
|
|
|
mapcontroller.updateCount.value++;
|
2024-08-20 17:44:39 +08:00
|
|
|
}),
|
2024-08-21 17:38:18 +08:00
|
|
|
_automChange(Icons.place, () {
|
2024-08-20 17:44:39 +08:00
|
|
|
// 处理 place 图标的点击事件
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2024-08-21 17:38:18 +08:00
|
|
|
//前三个单选
|
|
|
|
Widget _singleChange(IconData icon, VoidCallback onTap) {
|
2024-08-20 17:44:39 +08:00
|
|
|
return Container(
|
2024-08-21 17:38:18 +08:00
|
|
|
width: 33,
|
|
|
|
height: 33,
|
2024-08-20 17:44:39 +08:00
|
|
|
margin: EdgeInsets.symmetric(vertical: 2.0),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: _iconColors[icon],
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
),
|
|
|
|
child: InkWell(
|
|
|
|
child: Icon(
|
|
|
|
icon,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
2024-08-21 17:38:18 +08:00
|
|
|
onTap: () => _handleTap1(icon, onTap),
|
2024-08-20 17:44:39 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-21 17:38:18 +08:00
|
|
|
//后三个自动恢复
|
|
|
|
Widget _automChange(IconData icon, VoidCallback onTap) {
|
|
|
|
return Container(
|
|
|
|
width: 33,
|
|
|
|
height: 33,
|
|
|
|
margin: EdgeInsets.symmetric(vertical: 2.0),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: _iconColors[icon],
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
),
|
|
|
|
child: InkWell(
|
|
|
|
child: Icon(
|
|
|
|
icon,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
onTap: () => _handleTap2(icon, onTap),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|