Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.01 KB | None | 0 0
  1. import 'package:btn_survey/src/core/constants/app_constants.dart';
  2. import 'package:btn_survey/src/core/models/service_monitoring_log.dart';
  3. import 'package:btn_survey/src/core/utils/debouncer.dart';
  4. import 'package:btn_survey/src/core/utils/format_date_time.dart';
  5. import 'package:btn_survey/src/core/utils/size_config.dart';
  6. import 'package:btn_survey/src/core/viewmodels/service_monitoring/service_monitoring_log_model.dart';
  7. import 'package:btn_survey/src/ui/shared/app_colors.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:provider/provider.dart';
  10.  
  11. import '../base_widget.dart';
  12.  
  13. class LogPenilaianSeeAll extends StatefulWidget {
  14. @override
  15. _LogPenilaianSeeAllState createState() => _LogPenilaianSeeAllState();
  16. }
  17.  
  18. class _LogPenilaianSeeAllState extends State<LogPenilaianSeeAll> {
  19. final _debouncer = Debouncer(milliseconds: 500);
  20. List<ServiceMonitoringLogData> logList = List();
  21. List<ServiceMonitoringLogData> filteredLogList = List();
  22. int first = 0;
  23. // String selectStatus = "";
  24. // List<DropdownMenuItem<String>> _dropdownFilterStatus;
  25.  
  26. // @override
  27. // void initState() {
  28. // _dropdownFilterStatus = buildDropdownFilterYear();
  29. // selectStatus = _dropdownFilterStatus[0].value;
  30. // super.initState();
  31. // }
  32.  
  33. // List<DropdownMenuItem<String>> buildDropdownFilterYear() {
  34. // var statusList = [
  35. // 'Pending',
  36. // 'Rejected',
  37. // 'Approved'
  38. // ];
  39.  
  40. // List<DropdownMenuItem<String>> statuss = List();
  41. // for (String status in statusList) {
  42. // statuss.add(DropdownMenuItem(
  43. // value: status,
  44. // child: Text(status),
  45. // ));
  46. // }
  47.  
  48. // return statuss;
  49. // }
  50.  
  51. // void onChangeFilterStatus(String selectStatus) {
  52. // setState(() {
  53. // this.selectStatus = selectStatus;
  54. // print('naon ie $selectStatus');
  55. // });
  56. // }
  57.  
  58. StatusFilter selectedFilter;
  59. List<StatusFilter> statuss = <StatusFilter>[
  60. StatusFilter("Pending"," 1"),
  61. StatusFilter("Approved", "2"),
  62. StatusFilter("Rejected", "3")
  63. ];
  64.  
  65. @override
  66. void iniState() {
  67. selectedFilter = statuss[index];
  68. super.initState();
  69. }
  70.  
  71. @override
  72. Widget build(BuildContext context) {
  73. print('Build Apa Engga $statuss');
  74. return Scaffold(
  75. appBar: AppBar(
  76. title: Text(
  77. 'Log Penilaian',
  78. style: TextStyle(
  79. fontSize: 18,
  80. fontWeight: FontWeight.w600,
  81. color: Color(0xff5F5F5F),
  82. ),
  83. ),
  84. iconTheme: IconThemeData(
  85. color: Color(0xff5F5F5F),
  86. ),
  87. backgroundColor: Colors.white,
  88. brightness: Brightness.light,
  89. centerTitle: true,
  90. ),
  91. body: BaseWidget<ServiceMonitoringLogFilterModel>(
  92. model: ServiceMonitoringLogFilterModel(api: Provider.of(context)),
  93. onModelReady: (model) =>
  94. model.getServiceMonitoringLog(selectedFilter.num),
  95. builder: (context, model, child) {
  96. if (model.busy) {
  97. return Container(
  98. margin: EdgeInsets.symmetric(vertical: 20),
  99. child: Center(
  100. child: CircularProgressIndicator(),
  101. ),
  102. );
  103. } else {
  104. if (first == 0) filteredLogList = model.serviceMonitoringLog.data;
  105. first++;
  106.  
  107. return SingleChildScrollView(
  108. physics: BouncingScrollPhysics(),
  109. child: Column(
  110. children: <Widget>[
  111. Row(
  112. children: <Widget>[
  113. Expanded(
  114. child: Padding(
  115. padding: EdgeInsets.only(
  116. top: 20,
  117. bottom: 10,
  118. left: 20,
  119. right: 20,
  120. ),
  121. child: searchField(model.serviceMonitoringLog.data),
  122. ),
  123. ),
  124. DropdownButton(
  125. value: selectedFilter,
  126. items: statuss.map((StatusFilter status) {
  127. return DropdownMenuItem(
  128. value: status,
  129. child: Text(status.name),
  130. );
  131. }).toList(),
  132. onChanged: (StatusFilter value) async {
  133. selectedFilter = value;
  134. await model
  135. .getServiceMonitoringLog(selectedFilter.num);
  136. },
  137. // value: selectStatus,
  138. // items: _dropdownFilterStatus,
  139. // onChanged: (s) async {
  140. // this.selectStatus = s;
  141. // await model.getServiceMonitoringLog();
  142. // },
  143. )
  144. ],
  145. ),
  146. Container(
  147. margin: EdgeInsets.only(left: 16, right: 16, bottom: 16),
  148. child: ListView.builder(
  149. shrinkWrap: true,
  150. physics: NeverScrollableScrollPhysics(),
  151. itemCount: filteredLogList.length,
  152. itemBuilder: (BuildContext context, int index) {
  153. // New code:
  154. return Container(
  155. margin: EdgeInsets.only(top: 4, bottom: 4),
  156. child: listItemLogPenilaian(filteredLogList[index]),
  157. );
  158. },
  159. ),
  160. ),
  161. ],
  162. ),
  163. );
  164. }
  165. },
  166. ),
  167. );
  168. }
  169.  
  170. Widget searchField(List<ServiceMonitoringLogData> list) {
  171. return new TextField(
  172. keyboardType: TextInputType.text,
  173. autofocus: false,
  174. cursorColor: primaryColor,
  175. style: TextStyle(color: Colors.black),
  176. decoration: InputDecoration(
  177. suffixIcon: Icon(Icons.search),
  178. hintText: 'Cari Log Penilaian',
  179. hintStyle: TextStyle(color: Colors.black.withOpacity(0.3)),
  180. filled: true,
  181. fillColor: Color(0xFFF2F2F2),
  182. contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
  183. border: OutlineInputBorder(
  184. borderRadius: BorderRadius.circular(8),
  185. borderSide: BorderSide(style: BorderStyle.none)),
  186. enabledBorder: OutlineInputBorder(
  187. borderSide: BorderSide(
  188. style: BorderStyle.none,
  189. ),
  190. ),
  191. focusedBorder: OutlineInputBorder(
  192. borderSide: BorderSide(
  193. style: BorderStyle.none,
  194. ),
  195. ),
  196. ),
  197. onChanged: (String value) {
  198. _debouncer.run(() {
  199. setState(() {
  200. filteredLogList = list
  201. .where(
  202. (f) => (f.name.toLowerCase().contains(value.toLowerCase())))
  203. .toList();
  204. });
  205. print("SEARCH KEYWORD ${value.toLowerCase()}");
  206. });
  207. },
  208. );
  209. }
  210.  
  211. Widget listItemLogPenilaian(ServiceMonitoringLogData logPenilaian) {
  212. return Card(
  213. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
  214. elevation: 2,
  215. child: InkWell(
  216. onTap: () {
  217. if (logPenilaian.status == 1) {
  218. Navigator.of(context).pushNamed(RoutePaths.InputFormsOpOne,
  219. arguments:
  220. "${logPenilaian.id.toString()},${logPenilaian.status}");
  221. print(logPenilaian.status);
  222. } else if (logPenilaian.status == 0) {
  223. Navigator.of(context).pushNamed(RoutePaths.InputFormsOpOne,
  224. arguments:
  225. "${logPenilaian.id.toString()},${logPenilaian.status}");
  226. } else if (logPenilaian.status == 2) {
  227. Navigator.of(context).pushNamed(RoutePaths.InputFormsOpOne,
  228. arguments:
  229. "${logPenilaian.id.toString()},${logPenilaian.status}");
  230. }
  231. },
  232. child: Padding(
  233. padding: const EdgeInsets.all(12),
  234. child: Row(
  235. children: <Widget>[
  236. Expanded(
  237. child: Column(
  238. crossAxisAlignment: CrossAxisAlignment.start,
  239. children: <Widget>[
  240. Text(
  241. logPenilaian.name,
  242. style: TextStyle(
  243. fontWeight: FontWeight.w500,
  244. fontSize: 16,
  245. ),
  246. ),
  247. SizedBox(
  248. height: 6,
  249. ),
  250. Row(
  251. children: <Widget>[
  252. Padding(
  253. padding: const EdgeInsets.only(right: 4),
  254. child: Icon(
  255. Icons.date_range,
  256. color: Color(0xFFDADADA),
  257. ),
  258. ),
  259. Text(
  260. getFormattedDateFromIsoTypeB(logPenilaian.updatedAt),
  261. style: TextStyle(
  262. fontSize: 12,
  263. color: Colors.black.withOpacity(0.3),
  264. ),
  265. ),
  266. ],
  267. ),
  268. ],
  269. ),
  270. ),
  271. SizedBox(
  272. width: 16,
  273. ),
  274. getLogResult(logPenilaian),
  275. SizedBox(
  276. width: 16,
  277. ),
  278. getLogIcon(logPenilaian.status),
  279. ],
  280. ),
  281. ),
  282. ),
  283. );
  284. }
  285.  
  286. Widget getLogIcon(int status) {
  287. switch (status) {
  288. case 0:
  289. {
  290. return Image.asset(
  291. 'res/images/ic_wait_orange.png',
  292. width: SizeConfig.blockSizeHorizontal * 8,
  293. );
  294. }
  295. break;
  296. case 1:
  297. {
  298. return Image.asset(
  299. 'res/images/ic_cross_red.png',
  300. width: SizeConfig.blockSizeHorizontal * 8,
  301. );
  302. }
  303. break;
  304. case 2:
  305. {
  306. return Image.asset(
  307. 'res/images/ic_check_green.png',
  308. width: SizeConfig.blockSizeHorizontal * 8,
  309. );
  310. }
  311. }
  312. return Container();
  313. }
  314.  
  315. Widget getLogResult(ServiceMonitoringLogData log) {
  316. switch (log.status) {
  317. case 0:
  318. {
  319. return Column(
  320. crossAxisAlignment: CrossAxisAlignment.start,
  321. children: <Widget>[
  322. Text(
  323. 'Pending',
  324. style: TextStyle(
  325. fontSize: 12,
  326. fontWeight: FontWeight.w600,
  327. color: orange,
  328. ),
  329. ),
  330. SizedBox(
  331. height: 6,
  332. ),
  333. Row(
  334. children: <Widget>[
  335. Padding(
  336. padding: const EdgeInsets.only(right: 4),
  337. child: Icon(
  338. Icons.date_range,
  339. color: Color(0xFFDADADA),
  340. ),
  341. ),
  342. Text(
  343. getFormattedDateFromIsoTypeB(log.updatedAt),
  344. style: TextStyle(
  345. fontSize: 12,
  346. color: Colors.black.withOpacity(0.3),
  347. ),
  348. ),
  349. ],
  350. ),
  351. ],
  352. );
  353. }
  354. break;
  355. case 2:
  356. {
  357. return Column(
  358. crossAxisAlignment: CrossAxisAlignment.start,
  359. children: <Widget>[
  360. Text(
  361. 'Approved',
  362. style: TextStyle(
  363. fontSize: 12,
  364. fontWeight: FontWeight.w600,
  365. color: Color(0xFF42B20D),
  366. ),
  367. ),
  368. SizedBox(
  369. height: 6,
  370. ),
  371. Row(
  372. children: <Widget>[
  373. Padding(
  374. padding: const EdgeInsets.only(right: 4),
  375. child: Icon(
  376. Icons.date_range,
  377. color: Color(0xFFDADADA),
  378. ),
  379. ),
  380. Text(
  381. getFormattedDateFromIsoTypeB(log.updatedAt),
  382. style: TextStyle(
  383. fontSize: 12,
  384. color: Colors.black.withOpacity(0.3),
  385. ),
  386. ),
  387. ],
  388. ),
  389. ],
  390. );
  391. }
  392. break;
  393. case 1:
  394. {
  395. return Column(
  396. crossAxisAlignment: CrossAxisAlignment.start,
  397. children: <Widget>[
  398. Text(
  399. 'Rejected',
  400. style: TextStyle(
  401. fontSize: 12,
  402. fontWeight: FontWeight.w600,
  403. color: Color(0xFFE03238),
  404. ),
  405. ),
  406. SizedBox(
  407. height: 6,
  408. ),
  409. Row(
  410. children: <Widget>[
  411. Padding(
  412. padding: const EdgeInsets.only(right: 4),
  413. child: Icon(
  414. Icons.date_range,
  415. color: Color(0xFFDADADA),
  416. ),
  417. ),
  418. Text(
  419. getFormattedDateFromIsoTypeB(log.updatedAt),
  420. style: TextStyle(
  421. fontSize: 12,
  422. color: Colors.black.withOpacity(0.3),
  423. ),
  424. ),
  425. ],
  426. ),
  427. ],
  428. );
  429. }
  430. break;
  431. }
  432. return Container();
  433. }
  434. }
  435.  
  436. class StatusFilter {
  437. final String name;
  438. final String num;
  439.  
  440. StatusFilter(this.name, this.num);
  441. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement