报修 房间选择
This commit is contained in:
@@ -19,12 +19,16 @@ class RoomPickerPage extends StatefulWidget {
|
||||
class _RoomPickerPageState extends State<RoomPickerPage> {
|
||||
late Map<String, dynamic> editedData;
|
||||
RxList rooms = [].obs;
|
||||
late FixedExtentScrollController scrollController;
|
||||
DeviceListController deviceListController = Get.find();
|
||||
int selectedIndex = 0;
|
||||
Key key = Key(DateTime.now().toString());
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
editedData = Map.from(widget.data); // 创建副本
|
||||
editedData = Map.from(widget.data);
|
||||
getRoomList();
|
||||
scrollController = FixedExtentScrollController(initialItem: 0);
|
||||
}
|
||||
|
||||
getRoomList() async {
|
||||
@@ -32,18 +36,34 @@ class _RoomPickerPageState extends State<RoomPickerPage> {
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.room_list;
|
||||
String queryUrl = "$serviceAddress$serviceName$serviceApi";
|
||||
requestWithLog(
|
||||
|
||||
await requestWithLog(
|
||||
logTitle: '查询房间列表',
|
||||
method: MyHttpMethod.get,
|
||||
queryUrl: queryUrl,
|
||||
onSuccess: (res) {
|
||||
rooms.assignAll(res.data);
|
||||
setState(() => selectedIndex = 0);
|
||||
// 如果传入 roomName,匹配对应索引
|
||||
String? roomName = widget.data['roomName'];
|
||||
if (roomName != null && roomName.isNotEmpty) {
|
||||
int index = rooms.indexWhere((e) => e['name'] == roomName);
|
||||
if (index != -1) {
|
||||
selectedIndex = index;
|
||||
} else {
|
||||
selectedIndex = 0; // 找不到时默认选第一个
|
||||
}
|
||||
} else {
|
||||
selectedIndex = 0;
|
||||
}
|
||||
scrollController =
|
||||
FixedExtentScrollController(initialItem: selectedIndex);
|
||||
setState(() {
|
||||
key = Key(DateTime.now().toString());
|
||||
}); // 更新 UI
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
int selectedIndex = 0;
|
||||
BoxConstraints? bodysize;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -172,6 +192,8 @@ class _RoomPickerPageState extends State<RoomPickerPage> {
|
||||
// 滚轮列表
|
||||
Obx(
|
||||
() => ListWheelScrollView.useDelegate(
|
||||
key: key,
|
||||
controller: scrollController,
|
||||
itemExtent: 120.rpx,
|
||||
perspective: 0.003,
|
||||
physics: const FixedExtentScrollPhysics(),
|
||||
|
||||
Reference in New Issue
Block a user