Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

canvasing_screen.dart 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:ffi';
  4. import 'package:employee_selfservice_mobile/Screens/Menu/Canvasing/canvasingDetail_screen.dart';
  5. import 'package:employee_selfservice_mobile/Screens/Menu/Canvasing/getAll_post.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:fluttertoast/fluttertoast.dart';
  8. import 'package:google_fonts/google_fonts.dart';
  9. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  10. import 'package:shared_preferences/shared_preferences.dart';
  11. import 'dart:developer' as logDev;
  12. import '../../background.dart';
  13. class CanvasingScreen extends StatefulWidget {
  14. const CanvasingScreen({Key? key}) : super(key: key);
  15. @override
  16. State<CanvasingScreen> createState() => _CanvasingScreen();
  17. }
  18. class _CanvasingScreen extends State<CanvasingScreen> {
  19. late List <String> id_List;
  20. late List <String> name_List;
  21. late List <String> customer_List;
  22. late List <String> telp_List;
  23. late List <String> alamat_List;
  24. late List <Color> statusColor;
  25. late List <bool> visible;
  26. int AllDataLength = 0;
  27. @override
  28. initState() {
  29. super.initState();
  30. id_List = [""];
  31. name_List = [""];
  32. customer_List = [""];
  33. telp_List = [""];
  34. alamat_List = [""];
  35. visible = [false];
  36. WidgetsBinding.instance.addPostFrameCallback((_) async {
  37. getAllData();
  38. //initTimer();
  39. });
  40. }
  41. Timer? timer;
  42. void initTimer() {
  43. if (timer != null && timer!.isActive) return;
  44. timer = Timer.periodic(const Duration(seconds: 60), (timer) {
  45. //job
  46. setState(() {
  47. getAllData();
  48. });
  49. });
  50. }
  51. @override
  52. void dispose() {
  53. //timer?.cancel();
  54. super.dispose();
  55. }
  56. getAllData() async {
  57. ProgressDialog loading = ProgressDialog(context);
  58. loading = ProgressDialog(context,
  59. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  60. loading.style(
  61. message: 'Please Wait .....',
  62. borderRadius: 3,
  63. backgroundColor: Colors.white,
  64. progressWidget: CircularProgressIndicator(),
  65. elevation: 10.0,
  66. padding: EdgeInsets.all(10),
  67. insetAnimCurve: Curves.easeInOut,
  68. progress: 0.0,
  69. maxProgress: 100.0,
  70. progressTextStyle: TextStyle(
  71. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  72. messageTextStyle: TextStyle(
  73. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  74. final SharedPreferences prefs = await SharedPreferences.getInstance();
  75. int? user_id = prefs.getInt('user_id');
  76. logDev.log(user_id!.toString(), name: "ID NYA BERAPA???!!!");
  77. await loading.show();
  78. GetAll_Post.connectToAPI(user_id).then((valueResult) async {
  79. Map<String, dynamic> object = jsonDecode(valueResult);
  80. if (object.containsKey("result").toString() == "true") {
  81. String status = object['result']['status'].toString();
  82. if (status.contains("failed")) {
  83. await loading.hide();
  84. alertDialogFailedRetrievedData(context);
  85. } else if (status.contains("success")){
  86. logDev.log(status, name: "SUCCeSS?");
  87. List <dynamic> allData = object['result']['data'];
  88. await loading.hide();
  89. setState(() {
  90. for (int i = 0; i < allData.length; i++){
  91. String id = allData[i]['id'].toString();
  92. String name = allData[i]['name'].toString();
  93. String customer = allData[i]['customer'].toString();
  94. String telp = allData[i]['telp'].toString();
  95. String alamat = allData[i]['alamat'].toString();
  96. if (customer == "false"){
  97. customer ="-";
  98. }
  99. if (telp == "false"){
  100. telp = "-";
  101. }
  102. if (alamat == "false"){
  103. alamat = "-";
  104. }
  105. id_List.add(id);
  106. name_List.add(name);
  107. customer_List.add(customer);
  108. telp_List.add(telp);
  109. alamat_List.add(alamat);
  110. visible.add(false);
  111. }
  112. id_List.removeAt(0);
  113. name_List.removeAt(0);
  114. customer_List.removeAt(0);
  115. telp_List.removeAt(0);
  116. alamat_List.removeAt(0);
  117. visible.removeAt(0);
  118. AllDataLength = allData.length;
  119. });
  120. }
  121. } else {
  122. Fluttertoast.showToast(
  123. msg: "Server Response Error",
  124. toastLength: Toast.LENGTH_SHORT,
  125. gravity: ToastGravity.CENTER,
  126. timeInSecForIosWeb: 1,
  127. textColor: Colors.white,
  128. fontSize: 16.0);
  129. }
  130. });
  131. await loading.hide();
  132. }
  133. @override
  134. Widget build(BuildContext context) {
  135. var size = MediaQuery.of(context).size;
  136. return Scaffold(
  137. body: Stack(
  138. children: [
  139. Column(
  140. children: <Widget>[
  141. Stack(
  142. children: [
  143. WavyHeader(),
  144. Container(
  145. margin: EdgeInsets.only(
  146. top: (size.height / 6) - 20),
  147. padding: EdgeInsets.fromLTRB(0, 5, 25, 5),
  148. child: Row(
  149. mainAxisAlignment: MainAxisAlignment.end,
  150. crossAxisAlignment: CrossAxisAlignment.end,
  151. children: [
  152. Text(
  153. 'CANVASING\t\t',
  154. maxLines: 1,
  155. style: GoogleFonts.luckiestGuy(
  156. fontSize: 28,
  157. color: Color(0xFF4858A7),
  158. fontStyle: FontStyle.italic,
  159. ),
  160. ),
  161. Image.asset(
  162. 'assets/icons/menu/ic_canvasing_4.png',
  163. width: 40,
  164. height: 40,
  165. ),
  166. ],
  167. )
  168. ),
  169. ],
  170. ),
  171. ],
  172. ),
  173. Container(
  174. margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40,
  175. left: 5, right: 5, bottom: 10),
  176. child: ListView.builder(
  177. scrollDirection: Axis.vertical,
  178. shrinkWrap: true,
  179. itemCount: AllDataLength,
  180. itemBuilder: (context, int i) {
  181. return Container(
  182. child: InkWell(
  183. child: Card(
  184. elevation: 10,
  185. child: Column(
  186. children: [
  187. Row(
  188. children: [
  189. Expanded(
  190. flex: 10,
  191. child: Padding(
  192. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  193. child: Column(
  194. mainAxisAlignment: MainAxisAlignment.center,
  195. crossAxisAlignment: CrossAxisAlignment.start,
  196. children: [
  197. //Text(id_List[i], style: GoogleFonts.rubikBubbles(fontSize: 15)),
  198. Text(name_List[i], style: GoogleFonts.rubikBubbles(fontSize: 15)),
  199. Text(customer_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  200. Text(telp_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  201. Text(alamat_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  202. ],
  203. ),
  204. )
  205. ),
  206. /*Expanded(
  207. flex: 2,
  208. child: Padding(
  209. padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
  210. child: Text(status_List[i], textAlign: TextAlign.center, style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17),
  211. ),
  212. )
  213. ),*/
  214. ],
  215. ),
  216. /*Align(
  217. alignment: Alignment.centerLeft,
  218. child: Visibility(
  219. visible: visible[i],
  220. child: Padding(
  221. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  222. child: Column(
  223. mainAxisAlignment: MainAxisAlignment.start,
  224. crossAxisAlignment: CrossAxisAlignment.start,
  225. children: [
  226. Text(telp_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  227. Text(alamat_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  228. ],
  229. ),
  230. )
  231. ),
  232. )*/
  233. ],
  234. ),
  235. ),
  236. onTap: (){
  237. setState(() async {
  238. //visible[i] = !visible[i];
  239. var prefs = await SharedPreferences.getInstance();
  240. await prefs.setString('idDetail', id_List[i]);
  241. Navigator.push(context, MaterialPageRoute(builder: (context) => CanvasingDetail()));
  242. });
  243. },
  244. ),
  245. );
  246. },
  247. ),
  248. )
  249. ]),
  250. );
  251. }
  252. }
  253. alertDialogFailedRetrievedData(BuildContext context) {
  254. Widget okButton = TextButton(
  255. child: Text("Refresh"),
  256. onPressed: () {
  257. Navigator.of(context, rootNavigator: true).pop();
  258. Navigator.pushReplacement(
  259. context, MaterialPageRoute(builder: (context) => CanvasingScreen()));
  260. },
  261. );
  262. Widget noButton = TextButton(
  263. child: Text("Back"),
  264. onPressed: () {
  265. Navigator.of(context, rootNavigator: true).pop();
  266. Navigator.pop(context);
  267. },
  268. );
  269. // set up the AlertDialog
  270. AlertDialog alert = AlertDialog(
  271. title: Text("Canvasing"),
  272. content: Text("Failed to Retrieve Data"),
  273. actions: [
  274. noButton,
  275. okButton,
  276. ],
  277. );
  278. // show the dialog
  279. showDialog(
  280. context: context,
  281. barrierDismissible: false,
  282. builder: (BuildContext context) {
  283. return alert;
  284. },
  285. );
  286. }