Flutter app for Asset Management
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

282 rindas
11 KiB

  1. import 'package:assetstock/util/dbHandler.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'asset_details.dart';
  5. import 'util/prefsKey.dart';
  6. import 'main.dart';
  7. import 'util/Models.dart';
  8. import 'package:matrix_gesture_detector/matrix_gesture_detector.dart';
  9. class AssetLogs extends StatefulWidget {
  10. AssetLogs({Key key}) : super(key: key);
  11. @override
  12. _AssetLogsState createState() => _AssetLogsState();
  13. }
  14. class _AssetLogsState extends State<AssetLogs> {
  15. List<Asset> nonAuditedAsset = [];
  16. double widthtb = 900;
  17. double scale=1;
  18. final searchCon = TextEditingController();
  19. final scaleCon = TextEditingController();
  20. String search = '';
  21. fetchData()async{
  22. var dbName = await DBHelper.database.getDbName();
  23. var bUnit = await DBHelper.database.getBUnit();
  24. // result.
  25. var result = await util.JsonDataPostRaw({"bUnit":bUnit,"dbName" : dbName , "redirect" : "FALSE" , "auditedData" : "FALSE"}, "${prefs.getString(keyClass.hostAddress)??"http://172.16.4.144:3000"}/admin/data/dbDetail");
  26. if(result['STATUS']!=0){
  27. var arrayList = result['DATA']['nonAuditedData'];
  28. nonAuditedAsset.clear();
  29. for(int i = 0 ; i <arrayList.length ; i++){
  30. // print(arrayList[i]);
  31. nonAuditedAsset.add(Asset.fromJson(arrayList[i]));
  32. }
  33. setState(() {
  34. });
  35. }
  36. else{
  37. print(result);
  38. util.showToast('ALERT', "Can't reach the server.");
  39. Navigator.pop(context);
  40. }
  41. }
  42. tableRow(idxAsset,index){
  43. return InkWell(
  44. onTap: ()async{
  45. var redirect = await showDialog(
  46. context: context,
  47. builder: (context)=>AlertDialog(
  48. title: Text('Pick nonAuditAsset'),
  49. content: Text("Select Asset ${idxAsset.tag_number}"),
  50. actions: [
  51. FlatButton(
  52. onPressed: (){
  53. Navigator.pop(context,true);
  54. },
  55. child: Text("Add Asset"),
  56. )
  57. ],
  58. )
  59. );
  60. if(redirect??false){
  61. await Navigator.push(context, MaterialPageRoute(builder: (context) => new AssetDetails(initTag:idxAsset.tag_number)));
  62. // await fetchData();
  63. // scaleCon.text = scale.toStringAsFixed(2);
  64. }
  65. },
  66. child: Row(
  67. children: [
  68. Container(padding: EdgeInsets.only(left: 5.0),width: widthtb*0.035,child: Text('${index+1}')),
  69. Container(width: widthtb*0.09,child: Text(idxAsset.tag_number)),
  70. Container(width: widthtb*0.24,child: Text(idxAsset.asset_desc)),
  71. Container(width: widthtb*0.24,child: Text(idxAsset.pic)),
  72. Container(width: widthtb*0.13,child: Text(idxAsset.gedung)),
  73. Container(width: widthtb*0.125,child: Text(idxAsset.lantai)),
  74. Container(width: widthtb*0.13,child: Text(idxAsset.ruangan)),
  75. ],
  76. ),
  77. );
  78. }
  79. @override
  80. void initState() {
  81. fetchData();
  82. scaleCon.text = scale.toStringAsFixed(2);
  83. super.initState();
  84. }
  85. @override
  86. Widget build(BuildContext context) {
  87. return Scaffold(
  88. resizeToAvoidBottomInset: false,
  89. body: Container(
  90. padding: EdgeInsets.only(top: 10),
  91. color: Colors.grey.withOpacity(0.3),
  92. child: Column(
  93. children: [
  94. Expanded(
  95. flex: 2,
  96. child: Container(
  97. alignment: Alignment.bottomCenter,
  98. padding: const EdgeInsets.all(8.0),
  99. child: Container(
  100. decoration: BoxDecoration(
  101. color: Colors.white,
  102. borderRadius: BorderRadius.circular(20),
  103. ),
  104. // padding: EdgeInsets.all(8),
  105. child: TextField(
  106. controller: searchCon,
  107. onSubmitted: (value)async{
  108. setState(() {
  109. search = value;
  110. // searchCon.text = value;
  111. });
  112. // await loadAsset(loading: true);
  113. },
  114. decoration: InputDecoration(
  115. border: InputBorder.none,
  116. focusedBorder: InputBorder.none,
  117. enabledBorder: InputBorder.none,
  118. errorBorder: InputBorder.none,
  119. disabledBorder: InputBorder.none,
  120. suffixIcon: InkWell(
  121. onTap: ()async{
  122. var result = await util.scan();
  123. if(result['STATUS']==1){
  124. searchCon.text = result['DATA'];
  125. search = searchCon.text;
  126. // await loadAsset();
  127. setState(() {
  128. });
  129. }
  130. },
  131. child: Icon(Icons.center_focus_strong,color: Colors.blueGrey,)),
  132. contentPadding: EdgeInsets.only(left: 10,right: 10,top: 15,bottom: 15),
  133. hintText: "Search Tag Number"
  134. ),
  135. ),
  136. ),
  137. ),
  138. ),
  139. Expanded(
  140. flex:1,
  141. child: Padding(
  142. padding: EdgeInsets.all(5),
  143. child: Row(
  144. children: [
  145. Expanded(
  146. flex:7,
  147. child: Container(
  148. alignment: Alignment.centerLeft,
  149. child: Text('Non-Audited Asset : ${nonAuditedAsset.length} asset(s)'),
  150. ),
  151. ),
  152. Expanded(
  153. flex: 1,
  154. child: Container(
  155. child: Text('Scale : ')
  156. ),
  157. ),
  158. Expanded(
  159. flex: 1,
  160. child: Container(padding: EdgeInsets.only(bottom: 5.0),child: TextField(
  161. controller: scaleCon,
  162. keyboardType: TextInputType.number,
  163. onSubmitted: (value){
  164. try{
  165. scale = double.parse(value);
  166. if(scale>=1.00&&scale<=3.00){
  167. setState(() {
  168. widthtb = 900 *scale;
  169. });
  170. }
  171. else{
  172. util.showToast('ERROR', 'Scale must be between 1.00 - 3.00');
  173. }
  174. }
  175. catch(e){
  176. util.showToast('ERROR', 'Scale must be between 1.00 - 3.00');
  177. }
  178. },
  179. ))),
  180. ],
  181. ),
  182. ),
  183. ),
  184. Expanded(
  185. flex:18,
  186. child: Container(
  187. color: Colors.white,
  188. child: ListView(
  189. scrollDirection: Axis.horizontal,
  190. children: [
  191. Container(
  192. child: Column(
  193. children: [
  194. Container(
  195. decoration: BoxDecoration(
  196. border: Border.all(width: 1.0)
  197. ),
  198. width: widthtb,
  199. child: Row(
  200. children: [
  201. Container(padding: EdgeInsets.only(left: 5.0),width: widthtb*0.035,child: Text('No',style: TextStyle(fontWeight: FontWeight.bold),)),
  202. Container(width: widthtb*0.09,child: Text('Tag Number',style: TextStyle(fontWeight: FontWeight.bold))),
  203. Container(width: widthtb*0.24,child: Text('Asset Desc',style: TextStyle(fontWeight: FontWeight.bold))),
  204. Container(width: widthtb*0.24,child: Text('PIC',style: TextStyle(fontWeight: FontWeight.bold))),
  205. Container(width: widthtb*0.13,child: Text('Gedung',style: TextStyle(fontWeight: FontWeight.bold))),
  206. Container(width: widthtb*0.125,child: Text('Lantai',style: TextStyle(fontWeight: FontWeight.bold))),
  207. Container(width: widthtb*0.13,child: Text('Ruang',style: TextStyle(fontWeight: FontWeight.bold))),
  208. ],
  209. ),
  210. ),
  211. Expanded(
  212. child: MatrixGestureDetector(
  213. onMatrixUpdate: (m,t,s,r){
  214. scale = MatrixGestureDetector.decomposeToValues(m).scale+1;
  215. if(scale>3)scale=3;
  216. setState(() {
  217. scaleCon.text = scale.toStringAsFixed(2);
  218. widthtb = 900 *scale;
  219. // scaleheighttb = 0.04*scale;
  220. });
  221. },
  222. child: Container(
  223. decoration: BoxDecoration(
  224. border: Border.all(width: 1.0)
  225. ),
  226. width: widthtb,
  227. child: ListView.builder(
  228. padding: EdgeInsets.all(0.0),
  229. itemCount: nonAuditedAsset.length,
  230. itemBuilder: (context,index){
  231. Asset idxAsset = nonAuditedAsset[index];
  232. if(search!=''){
  233. if(idxAsset.tag_number.toUpperCase().contains(search.toUpperCase())) return Container(
  234. decoration: BoxDecoration(
  235. border: Border(bottom: BorderSide(width: 0.8))
  236. ),
  237. child: tableRow(idxAsset,index),
  238. );
  239. else return Container();
  240. }
  241. else{
  242. return Container(
  243. decoration: BoxDecoration(
  244. border: Border(bottom: BorderSide(width: 0.8))
  245. ),
  246. child: tableRow(idxAsset,index),
  247. );
  248. }
  249. }),
  250. ),
  251. ),
  252. ),
  253. ],
  254. ),
  255. ),
  256. ],
  257. ),
  258. )
  259. ),
  260. ],
  261. ),
  262. ),
  263. // floatingActionButton: FloatingActionButton.extended(
  264. // onPressed: (){
  265. //
  266. // },
  267. // icon: Icon(Icons.sync),
  268. // label: Text("Sync Approval"),
  269. // ),
  270. );
  271. }
  272. }