import 'package:flutter/material.dart'; import 'package:lszlgl/base/base_lifecycle_state.dart'; import 'package:lszlgl/main.dart'; import 'package:lszlgl/model/rsp/deviation_loaction_rsp.dart'; import 'package:lszlgl/model/rsp/sample_task_rsp.dart'; import 'package:lszlgl/network/my_api.dart'; import 'package:lszlgl/widget/button.dart'; import 'package:lszlgl/widget/card_item.dart'; class DeviationLocationWidget extends StatefulWidget { final DeviationLoactionRsp rsp; // final SampleTaskItem req; // 扦样信息 取区域code用 final Function(SampleTaskItem req) pCodeCallBack; const DeviationLocationWidget({super.key,required this.rsp, required this.req ,required this.pCodeCallBack}); @override State createState() => _DeviationLocationWidgetState(); } class _DeviationLocationWidgetState extends State { final CityList = [].notifier>(); final citysel = null.notifier(); final QuList = [].notifier>(); final qusel = null.notifier(); /// 获取行政区划列表 Future?> getDistrictList(num level, {num? id}) async { MyNavigator.showLoading(); try { var rsp = await MyApi.get().districtList(level, id: id); List list = (rsp.data ?? []).map((e) => CardMenuData(e.uname, e.id)).toList(); MyNavigator.dismissLoading(); return list; } catch (e) { logger.e(e); } MyNavigator.dismissLoading(); return null; } void getCityList(num? code) async{ var cityList = await getDistrictList(2, id: code); if (cityList == null) return; CityList.value = cityList; } void getquList(num? code) async{ var quList = await getDistrictList(3, id: code); if (quList == null) return; QuList.value = quList; } @override void initState() { super.initState(); // 获取市列表 if(widget.rsp.errorBj ==2 || widget.rsp.errorBj ==4 ){ getCityList(widget.req.shengXzqh); } if(widget.rsp.errorBj ==3){ getquList(widget.req.shiXzqh); } } @override Widget build(BuildContext context) { return PopScope( canPop: false, child: SafeArea( child: SingleChildScrollView( padding: EdgeInsets.fromLTRB(12, 22, 12, MediaQuery.of(context).viewInsets.bottom), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.min, children: [ const Text( '扦样位置确认', style: TextStyle(fontSize: 14), textAlign: TextAlign.center, ), const SizedBox(height: 28), if(widget.rsp.errorBj == 1) Text( widget.rsp.errorZn ?? '', style: const TextStyle(fontSize: 14,fontWeight: FontWeight.bold), textAlign: TextAlign.center, ), if(widget.rsp.errorBj == 2) ...[ const Text('您目前定位所在位置与任务不符,请选择您当前所在的市县',style: TextStyle(fontSize: 14,color: Colors.grey),), const SizedBox(height: 18), CardWidgets.buildMenu( false, '市/州', CityList, citysel, (_, sel) { widget.req.shiXzqh = sel.value; widget.req.quXzqh = null; qusel.value = null; getquList(sel.value!); }, showTopLine: true ), CardWidgets.buildMenu( false, '区县', QuList, qusel, (_, sel) => widget.req.quXzqh = sel.value, ), ], if(widget.rsp.errorBj == 3) ...[ const Text('您目前定位所在位置与任务不符,请选择您当前所在的区县',style: TextStyle(fontSize: 14,color: Colors.grey),), const SizedBox(height: 18), CardWidgets.buildMenu( false, '区县', QuList, qusel, (_, sel) => widget.req.quXzqh = sel.value, showTopLine: true, ), ], if(widget.rsp.errorBj == 4) ...[ const Text('您目前定位所在位置与任务不符,请选择您当前所在的市',style: TextStyle(fontSize: 14,color: Colors.grey),), const SizedBox(height: 18), CardWidgets.buildMenu( false, '市/州', CityList, citysel, (_, sel) => widget.req.shiXzqh = sel.value, showTopLine: true ) ], const SizedBox(height: 32), Row( children: [ Expanded( child: MyButton( '返回', onTap: (){ if(widget.rsp.errorBj == 2){ widget.req.shiXzqh = null; widget.req.quXzqh = null; } if(widget.rsp.errorBj == 3){ widget.req.quXzqh = null; } if(widget.rsp.errorBj == 4){ widget.req.shiXzqh = null; } Navigator.pop(context); }, radius: 10, fountSize: 15, padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16), fountColor: const Color(0xFF25A6EE), backgroundColor: const Color(0xFFDFF4FD), border: Border.all(color: const Color(0xFF25A6EE))), ), const SizedBox(width: 46), Expanded( child: MyButton( '确定', onTap: (){ if(widget.rsp.errorBj == 2 && widget.req.shiXzqh ==null){ MyNavigator.showToast('市/州不能为空'); return; } if(widget.rsp.errorBj == 2 && widget.req.quXzqh ==null){ MyNavigator.showToast('区县不能为空'); return; } if(widget.rsp.errorBj == 3 && widget.req.quXzqh ==null){ MyNavigator.showToast('区县不能为空'); return; } if(widget.rsp.errorBj == 4 && widget.req.shiXzqh ==null){ MyNavigator.showToast('市/州不能为空'); return; } widget.pCodeCallBack.call(widget.req); Navigator.pop(context); }, radius: 10, fountSize: 15, padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16), gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]), ), ), ], ), const SizedBox(height: 22), ], ), ), ), ); } }