2024-09-04 17:56:48 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:scence_map/controllers/controller.dart';
|
|
|
|
|
|
|
|
class PilePointTable extends StatefulWidget {
|
|
|
|
final List<PilePoint> pilePoints;
|
|
|
|
final Function(List<PilePoint>) onUpdate;
|
|
|
|
|
|
|
|
PilePointTable({required this.pilePoints, required this.onUpdate});
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PilePointTableState createState() => _PilePointTableState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PilePointTableState extends State<PilePointTable> {
|
|
|
|
List<bool> _selected = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_selected = List<bool>.filled(widget.pilePoints.length, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _deleteSelected() {
|
|
|
|
setState(() {
|
|
|
|
widget.pilePoints
|
|
|
|
.removeWhere((point) => _selected[widget.pilePoints.indexOf(point)]);
|
|
|
|
_selected = List<bool>.filled(widget.pilePoints.length, false);
|
|
|
|
widget.onUpdate(widget.pilePoints);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('桩点列表'),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.delete),
|
|
|
|
onPressed: _deleteSelected,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
child: Table(
|
|
|
|
border: const TableBorder(
|
|
|
|
verticalInside: BorderSide(color: Colors.grey, width: 1.0),
|
|
|
|
horizontalInside: BorderSide(color: Colors.grey, width: 1.0),
|
|
|
|
),
|
|
|
|
columnWidths: const {
|
|
|
|
0: IntrinsicColumnWidth(),
|
|
|
|
1: IntrinsicColumnWidth(),
|
|
|
|
2: IntrinsicColumnWidth(),
|
|
|
|
3: IntrinsicColumnWidth(),
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
const TableRow(
|
|
|
|
children: [
|
|
|
|
Center(child: Text('选择')),
|
|
|
|
Center(child: Text('ID')),
|
|
|
|
Center(child: Text('X')),
|
|
|
|
Center(child: Text('Y')),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
...List<TableRow>.generate(
|
|
|
|
widget.pilePoints.length,
|
|
|
|
(index) => TableRow(
|
|
|
|
children: [
|
|
|
|
TableCell(
|
|
|
|
verticalAlignment: TableCellVerticalAlignment.middle,
|
|
|
|
child: Padding(
|
2024-09-04 18:10:55 +08:00
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 12.0, vertical: 0),
|
2024-09-04 17:56:48 +08:00
|
|
|
child: Checkbox(
|
|
|
|
value: _selected[index],
|
|
|
|
onChanged: (bool? value) {
|
|
|
|
setState(() {
|
|
|
|
_selected[index] = value ?? false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TableCell(
|
|
|
|
verticalAlignment: TableCellVerticalAlignment.middle,
|
|
|
|
child: Padding(
|
2024-09-04 18:10:55 +08:00
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 12.0, vertical: 0),
|
2024-09-04 17:56:48 +08:00
|
|
|
child: Text(widget.pilePoints[index].id.toString()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TableCell(
|
|
|
|
verticalAlignment: TableCellVerticalAlignment.middle,
|
|
|
|
child: Padding(
|
2024-09-04 18:10:55 +08:00
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 12.0, vertical: 0),
|
2024-09-04 17:56:48 +08:00
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () => _editPilePoint(context, index, 'x'),
|
2024-09-04 18:10:55 +08:00
|
|
|
child: Text(widget.pilePoints[index].x.toString()),
|
2024-09-04 17:56:48 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TableCell(
|
|
|
|
verticalAlignment: TableCellVerticalAlignment.middle,
|
|
|
|
child: Padding(
|
2024-09-04 18:10:55 +08:00
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 12.0, vertical: 0),
|
2024-09-04 17:56:48 +08:00
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () => _editPilePoint(context, index, 'y'),
|
2024-09-04 18:10:55 +08:00
|
|
|
child: Text(widget.pilePoints[index].y.toString()),
|
2024-09-04 17:56:48 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _editPilePoint(BuildContext context, int index, String field) {
|
|
|
|
TextEditingController controller = TextEditingController(
|
|
|
|
text: field == 'x'
|
|
|
|
? widget.pilePoints[index].x.toString()
|
|
|
|
: widget.pilePoints[index].y.toString(),
|
|
|
|
);
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text('编辑桩点'),
|
|
|
|
content: TextField(
|
|
|
|
controller: controller,
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
decoration: InputDecoration(labelText: field == 'x' ? 'X' : 'Y'),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
if (field == 'x') {
|
|
|
|
widget.pilePoints[index].x = double.parse(controller.text);
|
|
|
|
} else {
|
|
|
|
widget.pilePoints[index].y = double.parse(controller.text);
|
|
|
|
}
|
|
|
|
widget.onUpdate(widget.pilePoints);
|
|
|
|
});
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Text('保存'),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Text('取消'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|