| @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; | |||||
| import 'package:image_picker/image_picker.dart'; | import 'package:image_picker/image_picker.dart'; | ||||
| import 'main.dart'; | import 'main.dart'; | ||||
| import 'util/Models.dart'; | import 'util/Models.dart'; | ||||
| import 'package:http/http.dart' as http; | |||||
| import 'util/prefsKey.dart'; | |||||
| class AssetDetails extends StatefulWidget { | class AssetDetails extends StatefulWidget { | ||||
| // AssetDetails({Key key}) : super(key: key); | // AssetDetails({Key key}) : super(key: key); | ||||
| @@ -217,12 +219,24 @@ class _AssetDetailsState extends State<AssetDetails> with TickerProviderStateMix | |||||
| alignment: Alignment.centerRight, | alignment: Alignment.centerRight, | ||||
| child: InkWell( | child: InkWell( | ||||
| onTap: ()async { | onTap: ()async { | ||||
| var result = await DBHelper.database.getRefBlob(_asset.tag_number); | |||||
| if(result!=null){ | |||||
| if(result.blob!=null) Navigator.push(context, MaterialPageRoute(builder: (context) => PhotoViewer(result.blob,))); | |||||
| try{ | |||||
| var dbName = await DBHelper.database.getDbName(); | |||||
| var bUnit = await DBHelper.database.getBUnit(); | |||||
| util.showLoading(context); | |||||
| http.Response result = await http.get( | |||||
| '${prefs.getString(keyClass.hostAddress)??"https://asset.thamringroup.web.id"}/api/images?q=${_asset.tag_number}&s=${dbName}&b=${bUnit}', | |||||
| ).timeout(Duration(seconds: 3)); | |||||
| Navigator.pop(context); | |||||
| if(result!=null){ | |||||
| Navigator.push(context, MaterialPageRoute(builder: (context) => PhotoViewer(result.bodyBytes))); | |||||
| } | |||||
| else util.showToast('ALERT', "No Archived Images yet"); | else util.showToast('ALERT', "No Archived Images yet"); | ||||
| } | } | ||||
| else util.showToast('ALERT', "No Archived Images yet"); | |||||
| catch(e){ | |||||
| Navigator.pop(context); | |||||
| print(e); | |||||
| util.showToast('ALERT', "No Archived Images yet"); | |||||
| } | |||||
| //showPhoto | //showPhoto | ||||
| }, | }, | ||||
| child: Padding( | child: Padding( | ||||
| @@ -250,6 +250,13 @@ class _AssetLogsState extends State<AssetLogs> { | |||||
| ], | ], | ||||
| ), | ), | ||||
| ), | ), | ||||
| floatingActionButton: FloatingActionButton.extended( | |||||
| onPressed: (){ | |||||
| }, | |||||
| icon: Icon(Icons.sync), | |||||
| label: Text("Sync Approval"), | |||||
| ), | |||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||
| @@ -323,6 +323,7 @@ class _HomeState extends State<Home> { | |||||
| // var allUnits = await DBHelper.database.getAllAsset(); | // var allUnits = await DBHelper.database.getAllAsset(); | ||||
| // print('${allUnits.length} Units'); | // print('${allUnits.length} Units'); | ||||
| util.showToast('ALERT','Data Downloaded'); | util.showToast('ALERT','Data Downloaded'); | ||||
| await DBHelper.database.setOpenState(); | |||||
| } | } | ||||
| if(value==-1.0){ | if(value==-1.0){ | ||||
| util.showToast('ALERT','Data Error ${trans.error}'); | util.showToast('ALERT','Data Error ${trans.error}'); | ||||
| @@ -5,6 +5,7 @@ import 'prefsKey.dart'; | |||||
| import 'dart:io'; | import 'dart:io'; | ||||
| import 'dart:async'; | import 'dart:async'; | ||||
| import 'package:path/path.dart'; | import 'package:path/path.dart'; | ||||
| import 'package:intl/intl.dart'; | |||||
| class DBHelper{ | class DBHelper{ | ||||
| DBHelper._(); | DBHelper._(); | ||||
| @@ -78,19 +79,19 @@ class DBHelper{ | |||||
| return null; | return null; | ||||
| } | } | ||||
| } | } | ||||
| getRefBlob(tagNumber)async{ | |||||
| try{ | |||||
| final database = await db; | |||||
| var res = await database.query(tableName.ref,where: "${columnName.tag_number} = ?",whereArgs: [tagNumber]); | |||||
| // var a = await database.rawQuery("select length(${columnName.blob}) / 1024 from ${tableName.insert} where ${columnName.no} = $no"); | |||||
| // print(a); | |||||
| return res.isNotEmpty ? Asset.fromJson(res.first): null; | |||||
| } | |||||
| catch(e){ | |||||
| print(e); | |||||
| return null; | |||||
| } | |||||
| } | |||||
| // getRefBlob(tagNumber)async{ | |||||
| // try{ | |||||
| // final database = await db; | |||||
| // var res = await database.query(tableName.insert,where: "${columnName.tag_number} = ?",whereArgs: [tagNumber]); | |||||
| // // var a = await database.rawQuery("select count(*) from ${tableName.insert}"); | |||||
| // // print(a); | |||||
| // return res.isNotEmpty ? Asset.fromJson(res.first): null; | |||||
| // } | |||||
| // catch(e){ | |||||
| // print(e); | |||||
| // return null; | |||||
| // } | |||||
| // } | |||||
| searchbyTagNumber(tagNumber) async{ | searchbyTagNumber(tagNumber) async{ | ||||
| try{ | try{ | ||||
| final database = await db; | final database = await db; | ||||
| @@ -256,5 +257,22 @@ class DBHelper{ | |||||
| return null; | return null; | ||||
| } | } | ||||
| } | } | ||||
| setOpenState()async{ | |||||
| try{ | |||||
| final database = await db; | |||||
| var check_KEY = await database.rawQuery("SELECT 1 FROM ${tableName.key} where ${columnName.key} = 'STATE'"); | |||||
| if (check_KEY.length<=0){ | |||||
| await database.insert(tableName.key, {columnName.key:"STATE",columnName.value:"OPEN"}); | |||||
| } | |||||
| else{ | |||||
| await database.update(tableName.key, {columnName.value:"OPEN"},where: "${columnName.key} = ?",whereArgs: ['STATE']); | |||||
| } | |||||
| await database.update(tableName.key, {columnName.value:DateFormat("YYYY-MM-DD HH:mm:ss").format(DateTime.now())},where: "${columnName.key} = ?",whereArgs: ['START_DATE']); | |||||
| } | |||||
| catch(e){ | |||||
| print(e); | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; | |||||
| import 'package:http/http.dart' as http; | import 'package:http/http.dart' as http; | ||||
| import 'package:barcode_scan/barcode_scan.dart'; | import 'package:barcode_scan/barcode_scan.dart'; | ||||
| import 'package:fluttertoast/fluttertoast.dart'; | import 'package:fluttertoast/fluttertoast.dart'; | ||||
| import '../main.dart'; | |||||
| class Util{ | class Util{ | ||||
| scan()async{ | scan()async{ | ||||
| String BarcodeText =''; | String BarcodeText =''; | ||||
| @@ -18,6 +18,27 @@ class Util{ | |||||
| return {'STATUS':0,'DATA':e}; | return {'STATUS':0,'DATA':e}; | ||||
| } | } | ||||
| } | } | ||||
| showLoadingFuture(context,future,{dismiss=false,onWillPop})async { | |||||
| var dialogContext; | |||||
| showDialog( | |||||
| context: context, | |||||
| builder: (BuildContext context) { | |||||
| dialogContext = context; | |||||
| return WillPopScope( | |||||
| onWillPop: onWillPop??()async{return true;}, | |||||
| child: new Center( | |||||
| child: new CircularProgressIndicator(), | |||||
| ), | |||||
| ); | |||||
| }, | |||||
| barrierDismissible: dismiss, | |||||
| ); | |||||
| var res = await future; | |||||
| Navigator.pop(dialogContext); | |||||
| return res; | |||||
| } | |||||
| JsonDataPostRaw(Map jsonData, String url,{timeout:false,duration:10}) async{ | JsonDataPostRaw(Map jsonData, String url,{timeout:false,duration:10}) async{ | ||||
| const JsonDecoder decoder = const JsonDecoder(); | const JsonDecoder decoder = const JsonDecoder(); | ||||
| try { | try { | ||||
| @@ -43,6 +64,7 @@ class Util{ | |||||
| return {"STATUS":"ERROR","ERROR":"Not Connected to Server. $exception"}; | return {"STATUS":"ERROR","ERROR":"Not Connected to Server. $exception"}; | ||||
| } | } | ||||
| } | } | ||||
| showToast(type,text)async{ | showToast(type,text)async{ | ||||
| await Fluttertoast.cancel(); | await Fluttertoast.cancel(); | ||||
| Fluttertoast.showToast( | Fluttertoast.showToast( | ||||
| @@ -178,7 +178,7 @@ packages: | |||||
| source: hosted | source: hosted | ||||
| version: "1.1.0" | version: "1.1.0" | ||||
| intl: | intl: | ||||
| dependency: transitive | |||||
| dependency: "direct main" | |||||
| description: | description: | ||||
| name: intl | name: intl | ||||
| url: "https://pub.dartlang.org" | url: "https://pub.dartlang.org" | ||||
| @@ -29,6 +29,7 @@ dependencies: | |||||
| photo_view: | photo_view: | ||||
| sqflite: | sqflite: | ||||
| matrix_gesture_detector: | matrix_gesture_detector: | ||||
| intl: | |||||
| # The following adds the Cupertino Icons font to your application. | # The following adds the Cupertino Icons font to your application. | ||||
| # Use with the CupertinoIcons class for iOS style icons. | # Use with the CupertinoIcons class for iOS style icons. | ||||
| cupertino_icons: ^0.1.3 | cupertino_icons: ^0.1.3 | ||||