2024-07-30 18:20:27 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2024-07-31 19:04:11 +08:00
|
|
|
import 'package:get/get.dart';
|
2024-07-30 18:20:27 +08:00
|
|
|
|
|
|
|
class MulButton extends StatefulWidget {
|
2024-08-01 14:08:34 +08:00
|
|
|
final List<Color> signalColorList;
|
2024-07-31 23:37:51 +08:00
|
|
|
final Function(int, bool) onSelectionChanged;
|
2024-07-30 18:20:27 +08:00
|
|
|
|
|
|
|
MulButton({
|
2024-08-01 14:08:34 +08:00
|
|
|
required this.signalColorList,
|
2024-07-30 18:20:27 +08:00
|
|
|
required this.onSelectionChanged,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
_MulButtonState createState() => _MulButtonState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MulButtonState extends State<MulButton> {
|
2024-08-01 14:08:34 +08:00
|
|
|
late List<bool> selectedSignal;
|
2024-07-30 18:20:27 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-08-01 14:08:34 +08:00
|
|
|
selectedSignal =
|
|
|
|
List.generate(widget.signalColorList.length, (index) => false);
|
2024-07-30 18:20:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateSelection(int index, bool value) {
|
|
|
|
setState(() {
|
2024-08-01 14:08:34 +08:00
|
|
|
selectedSignal[index] = value;
|
2024-07-31 23:37:51 +08:00
|
|
|
// List<Color> selected = [];
|
|
|
|
// for (int i = 0; i < selectedColors.length; i++) {
|
|
|
|
// if (selectedColors[i]) {
|
|
|
|
// selected.add(widget.colors[i]);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
widget.onSelectionChanged(index, value); // 通知父组件
|
2024-07-30 18:20:27 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Wrap(
|
|
|
|
spacing: 8.0, // 水平间距
|
|
|
|
runSpacing: 4.0, // 垂直间距
|
|
|
|
alignment: WrapAlignment.start,
|
2024-08-01 14:08:34 +08:00
|
|
|
children: List.generate(widget.signalColorList.length, (index) {
|
2024-07-30 18:20:27 +08:00
|
|
|
return Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Checkbox(
|
2024-08-01 14:08:34 +08:00
|
|
|
value: selectedSignal[index],
|
2024-07-30 18:20:27 +08:00
|
|
|
onChanged: (bool? value) {
|
|
|
|
if (value != null) {
|
|
|
|
updateSelection(index, value);
|
|
|
|
}
|
|
|
|
},
|
2024-08-01 14:08:34 +08:00
|
|
|
activeColor: widget.signalColorList[index],
|
2024-07-30 18:20:27 +08:00
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(4), // 设置边角
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
2024-08-01 14:08:34 +08:00
|
|
|
colorToString(widget.signalColorList[index]),
|
|
|
|
style: TextStyle(color: widget.signalColorList[index]),
|
2024-07-30 18:20:27 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String colorToString(Color color) {
|
2024-08-01 14:08:34 +08:00
|
|
|
if (color == Color.fromARGB(255, 255, 0, 0)) return 'GPS(G)';
|
|
|
|
if (color == Color.fromARGB(255, 0, 255, 0)) return 'GLONASS(R)';
|
|
|
|
if (color == Color.fromARGB(255, 0, 0, 255)) return 'GALILEO(E)';
|
|
|
|
if (color == Color.fromARGB(255, 255, 255, 0)) return 'BEIDOU(B)';
|
|
|
|
if (color == Color.fromARGB(255, 0, 255, 255)) return 'QZSS(Q)';
|
2024-07-30 18:20:27 +08:00
|
|
|
return 'Unknown Color';
|
|
|
|
}
|
|
|
|
}
|