No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

history_screen.dart 11KB

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