Flutter app for Asset Management
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

107 Zeilen
3.0 KiB

  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:io';
  4. import 'package:flutter/material.dart';
  5. import 'package:http/http.dart' as http;
  6. import 'package:barcode_scan/barcode_scan.dart';
  7. import 'package:fluttertoast/fluttertoast.dart';
  8. class Util{
  9. scan()async{
  10. String BarcodeText ='';
  11. try{
  12. ScanResult result = await BarcodeScanner.scan();
  13. BarcodeText = result.rawContent;
  14. return {'STATUS':1,'DATA':BarcodeText};
  15. }
  16. catch(e){
  17. return {'STATUS':0,'DATA':e};
  18. }
  19. }
  20. showLoadingFuture(context,future,{dismiss=false,onWillPop})async {
  21. var dialogContext;
  22. showDialog(
  23. context: context,
  24. builder: (BuildContext context) {
  25. dialogContext = context;
  26. return WillPopScope(
  27. onWillPop: onWillPop??()async{return true;},
  28. child: new Center(
  29. child: new CircularProgressIndicator(),
  30. ),
  31. );
  32. },
  33. barrierDismissible: dismiss,
  34. );
  35. var res = await future;
  36. Navigator.pop(dialogContext);
  37. return res;
  38. }
  39. JsonDataPostRaw(Map jsonData, String url,{timeout:false,duration:10}) async{
  40. const JsonDecoder decoder = const JsonDecoder();
  41. try {
  42. var headers = {'device':'mobile','Content-type': 'application/json'};
  43. var response;
  44. if (timeout)
  45. response = await http.post(
  46. '$url', headers: headers,
  47. body: json.encode(jsonData)).timeout(
  48. Duration(seconds: duration));
  49. else
  50. response = await http.post(
  51. '$url', headers: headers,
  52. body: json.encode(jsonData));
  53. final Map data = decoder.convert(response.body);
  54. return data;
  55. } on TimeoutException catch(e){
  56. return {"STATUS":"ERROR","ERROR":"Request Timeout"};
  57. }
  58. on Exception catch(exception){
  59. print(url);
  60. // Toast("Not Connected to Server", Colors.red);
  61. return {"STATUS":"ERROR","ERROR":"Not Connected to Server. $exception"};
  62. }
  63. }
  64. showToast(type,text)async{
  65. await Fluttertoast.cancel();
  66. Fluttertoast.showToast(
  67. msg: "$text",
  68. toastLength: Toast.LENGTH_SHORT,
  69. gravity: ToastGravity.BOTTOM,
  70. timeInSecForIosWeb: 1,
  71. backgroundColor: (type=='ERROR')?Colors.red:(type=='SUCCESS')?Colors.green:Colors.black38,
  72. textColor: Colors.white,
  73. fontSize: 16.0
  74. );
  75. }
  76. showLoading(context,{dissmissable=false,onwillpop}){
  77. showDialog(
  78. context: context,
  79. builder: (BuildContext context) {
  80. return WillPopScope(
  81. onWillPop: onwillpop??()async{return true;},
  82. child: new Center(
  83. child: new CircularProgressIndicator(),
  84. ),
  85. );
  86. },
  87. barrierDismissible: dissmissable,
  88. );
  89. }
  90. checkinternet()async{
  91. try {
  92. var result = await InternetAddress.lookup('google.com').timeout(Duration(seconds: 3),onTimeout: (){return null;});
  93. if (result!=null && result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
  94. return true;
  95. }
  96. else return false;
  97. } on SocketException catch (_) {
  98. return false;
  99. }
  100. }
  101. }