This commit is contained in:
tanlinxing 2024-09-10 16:01:04 +08:00
parent 42fb5c2193
commit 680afe5b41
4 changed files with 90 additions and 75 deletions

View File

@ -1,5 +1,6 @@
import 'package:cpnav/appbar.dart';
import 'package:cpnav/pages/pass_track/controller.dart';
import 'package:cpnav/pages/pass_track/bottomIcon/iconController.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
@ -10,6 +11,7 @@ void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); //
Get.put(PassTrackController('WXLMB', 'cp_road'));
Get.put(IconController());
runApp(const MyApp());
}

View File

@ -4,49 +4,17 @@ import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:scence_map/controller.dart';
import 'iconController.dart';
ScenceMapController mapController = Get.put(ScenceMapController());
class IconContainer extends StatefulWidget {
@override
_IconContainerState createState() => _IconContainerState();
}
class _IconContainerState extends State<IconContainer> {
final Map<IconData, Color> _iconColors = {
Icons.article: Colors.green,
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),
};
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();
}
void _handleTap2(IconData icon, VoidCallback onTap) {
setState(() {
_iconColors[icon] = Colors.green; //
});
onTap();
Future.delayed(Duration(milliseconds: 200), () {
setState(() {
_iconColors[icon] = const Color.fromARGB(255, 166, 182, 149); //
});
});
}
// class IconContainer extends StatefulWidget {
// @override
// _IconContainerState createState() => _IconContainerState();
// }
// class _IconContainerState extends State<IconContainer> {
class IconContainer extends GetView<IconController> {
@override
Widget build(BuildContext context) {
var isPortrait = MediaQuery.of(context).orientation == Orientation.portrait;
@ -203,12 +171,13 @@ class _IconContainerState extends State<IconContainer> {
//
Widget _singleChange(IconData icon, VoidCallback onTap) {
return Obx(() {
return Container(
width: 33,
height: 33,
margin: const EdgeInsets.symmetric(vertical: 2.0),
decoration: BoxDecoration(
color: _iconColors[icon],
color: controller.iconColors[icon],
border: Border.all(
color: Colors.white,
),
@ -219,19 +188,21 @@ class _IconContainerState extends State<IconContainer> {
icon,
color: Colors.white,
),
onTap: () => _handleTap1(icon, onTap),
onTap: () => controller.handleTap1(icon, onTap),
),
);
});
}
//
Widget _automChange(IconData icon, VoidCallback onTap) {
return Obx(() {
return Container(
width: 33,
height: 33,
margin: const EdgeInsets.symmetric(vertical: 2.0),
decoration: BoxDecoration(
color: _iconColors[icon],
color: controller.iconColors[icon],
border: Border.all(
color: Colors.white,
),
@ -242,8 +213,9 @@ class _IconContainerState extends State<IconContainer> {
icon,
color: Colors.white,
),
onTap: () => _handleTap2(icon, onTap),
onTap: () => controller.handleTap2(icon, onTap),
),
);
});
}
}

View File

@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class IconController extends GetxController {
final RxMap<IconData, Color> iconColors = {
Icons.article: Colors.green,
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),
}.obs;
// IconData? _selectedIcon;
late IconData selectedIcon;
@override
void onInit() {
super.onInit();
handleTap1(Icons.close, () {}); // onTap事件(, onTap)
handleTap2(Icons.close, () {});
}
void handleTap1(IconData icon, VoidCallback onTap) {
selectedIcon = icon;
iconColors.forEach((key, value) {
iconColors[key] = key == icon
? Colors.green //
: const Color.fromARGB(255, 166, 182, 149); //
});
onTap();
}
void handleTap2(IconData icon, VoidCallback onTap) {
iconColors[icon] = Colors.green; //
onTap();
Future.delayed(Duration(milliseconds: 200), () {
iconColors[icon] = const Color.fromARGB(255, 166, 182, 149); //
});
}
}

View File

@ -9,7 +9,7 @@ import 'package:scence_map/controller.dart';
import 'package:scence_map/scence_map.dart';
import 'package:syncfusion_flutter_sliders/sliders.dart';
import 'iconContainer.dart';
import 'bottomIcon/iconContainer.dart';
import "controller.dart";
import "package:pass_track/pass_track.dart";
import "package:pass_track/pass_track_platform_interface.dart";