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.

surveylist_screen.dart 12KB

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