Flutter app for Asset Management
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

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