12345
This commit is contained in:
parent
42fb5c2193
commit
680afe5b41
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
41
lib/pages/pass_track/bottomIcon/iconController.dart
Normal file
41
lib/pages/pass_track/bottomIcon/iconController.dart
Normal 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); // 恢复原色
|
||||
});
|
||||
}
|
||||
}
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user