import 'dart:convert'; import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:lszlgl/base/base_lifecycle_state.dart'; import 'package:lszlgl/base/base_vm.dart'; import 'package:lszlgl/config/borders.dart'; import 'package:lszlgl/main.dart'; import 'package:lszlgl/model/api_rsp.dart'; import 'package:lszlgl/model/rsp/storehouse_rsp.dart'; import 'package:lszlgl/network/my_api.dart'; import 'package:lszlgl/widget/page_widget.dart'; import 'package:lszlgl/widget/storehouse_item.dart'; class StoreHousePage extends StatefulWidget { final String houseNum; const StoreHousePage({super.key, required this.houseNum}); @override State createState() => _StoreHousePageState(); } class _StoreHousePageState extends BaseLifecycleState { final pageState = DataStatusModel().notifier>(); storehouseRsp? data; final ValueNotifier _title = ValueNotifier('仓房信息'); @override void onFirstShow(Duration timeStamp) { loadData(); } @override void onDestroy() { pageState.dispose(); } void loadData() async{ pageState.update(pageState.value.loading()); try{ // String jsonStr = await Future.delayed(const Duration(seconds: 3),()async{ // return rootBundle.loadString('assets/json/storehouse.json'); // }); // Map val = json.decode(jsonStr); // ApiRsp> res= ApiRsp>.fromJson( // val, // (json) => json is List // ? json // .map((i) => storehouseRsp.fromJson(i as Map)) // .toList() // : List.empty(), // ); var res = await MyApi.get(baseUrl: 'http://101.36.160.117:28088').getStoreMessage(widget.houseNum, 'zhijian'); if(res.data == null ){ pageState.update(pageState.value.empty()); }else{ data = res.data!.first; _title.value = data?.kqmc ?? '仓房信息' ; pageState.update(pageState.value.success(data: res.data!.first)); } }catch(e){ logger.e(e); pageState.update(pageState.value.error()); } } @override Widget build(BuildContext context) { return myScaffold( child: KeyboardDismissOnTap( dismissOnCapturedTaps: true, child: Column( children: [ ValueListenableBuilder( valueListenable: _title, builder: (_,String title,__){ return myAppBar(title: title); }, ), Expanded( child:Container( color: Colors.white, child: SingleChildScrollView( child: pageState.builder((v){ if(v.status == DataStatus.error){ return PageLoadingWidget.error(onTap: loadData); } if(v.status == DataStatus.empty){ return const PageLoadingWidget.empty(); } if(v.status == DataStatus.loading){ return const PageLoadingWidget.loading(); } return Column( //crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Padding(padding: const EdgeInsets.fromLTRB(22, 20, 22, 4), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text(data?.cfmc ?? '',style: TextStyles.titA,), const SizedBox(height: 12), Text('仓房编号:${data?.tycfbm}',style: TextStyles.titA), const SizedBox(height: 12), const Divider(thickness: 0.6,), const SizedBox(height: 6), StorehouseItem(special: true,left: data?.cflx,right: data?.cfzt), StorehouseItem(left: '保管员',right: data?.bgr), StorehouseItem(left: '交付使用日期', right: data?.jfsyrq), const SizedBox(height: 10), const Divider(thickness: 0.6,), ], ), ), const StoreHouseTit(tit: '仓房信息'), Padding(padding: const EdgeInsets.fromLTRB(22, 8, 22, 4), child:Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ StorehouseItem(left: '设计仓容',right: '${data?.ajsjcr}吨',), StorehouseItem(left: '设计使用年限',right: '${data?.sjsynx}年',), StorehouseItem(left: '装粮线高',right: '${data?.cnzlxg}米',), StorehouseItem(left: '长*宽*高',right: data?.ckg,), const SizedBox(height: 10), const Divider(thickness: 0.6,), ], ) ), const StoreHouseTit(tit: '粮食库存'), Container( padding: const EdgeInsets.symmetric(horizontal:22,vertical: 12), child: DottedBorder( strokeWidth: 0.8, color: Colors.grey, dashPattern:const[3,4], padding: const EdgeInsets.all(8), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ StorehouseItem(left: '粮食品种',right: data?.itemList?.first?.lspzmc), StorehouseItem(left: '粮食等级',right: data?.itemList?.first?.lsdjmc), StorehouseItem(left: '库存',right: '${data?.itemList?.first?.jjsl}kg'), StorehouseItem(left: '储存性质',right: data?.itemList?.first?.lsxzmc), StorehouseItem(left: '粮权归属单位',right: data?.itemList?.first?.lqgsdw), StorehouseItem(left: '入仓时间',right: data?.itemList?.first?.timeStr()), StorehouseItem(left: '产地',right: data?.itemList?.first?.cd), StorehouseItem(left: '收货年度',right: '${data?.itemList?.first?.shnd}年'), ], ), ), ) ], ); } ), ), ) ), ], ) ), ); } }