· 6 years ago · Jan 12, 2020, 04:58 PM
1import 'dart:async';
2import 'dart:convert';
3import 'dart:typed_data';
4import 'package:flutter/services.dart';
5import 'package:flutter_bloc/flutter_bloc.dart';
6import 'package:http/http.dart' as http;
7import 'package:firebase_messaging/firebase_messaging.dart';
8import 'package:flutter/material.dart';
9import 'package:flutter/widgets.dart';
10import 'package:flutter_local_notifications/flutter_local_notifications.dart';
11import 'package:intl/intl.dart';
12import 'package:intl/date_symbol_data_local.dart';
13import 'package:sistesi/View/MenuList.dart';
14import 'package:sistesi/View/detailPengumumanView.dart';
15import 'package:shared_preferences/shared_preferences.dart';
16import 'package:sistesi/View/daftarEkskulView.dart';
17import 'package:sistesi/bloc/chat_bloc.dart';
18import 'package:sistesi/bloc/subscribe_bloc.dart';
19import 'package:sistesi/model/Berita.dart';
20import 'package:sistesi/model/DashboardAbsen.dart';
21import 'package:sistesi/model/DataNotif.dart';
22import 'package:sistesi/model/DataUser.dart';
23import 'package:sistesi/model/Ekskul.dart';
24import 'package:sistesi/model/Iuran.dart';
25import 'package:sistesi/model/Kalender.dart';
26import 'package:carousel_slider/carousel_slider.dart';
27import 'package:sistesi/model/MenuModel.dart';
28import 'package:flutter/cupertino.dart';
29import 'package:sistesi/View/profileView.dart';
30import 'package:sistesi/model/Pengumuman.dart';
31import 'package:sistesi/model/RunningText.dart';
32import 'package:sistesi/model/TahunAjaran.dart';
33import 'package:sistesi/model/TglLocal.dart';
34import 'package:sistesi/providers/ApiServices.dart';
35import 'package:modal_progress_hud/modal_progress_hud.dart';
36import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
37import 'package:sistesi/widget/Base.dart';
38import 'package:sistesi/widget/StringSistesi.dart';
39import 'package:sistesi/widget/Style.dart';
40import 'dart:io' show Platform;
41import 'package:sistesi/View/Absensi/absensiView.dart';
42import 'package:sistesi/View/chatDetail.dart';
43import 'package:sistesi/View/kalender.dart';
44import 'package:sistesi/View/obrolanList.dart';
45
46class Dashboard extends StatefulWidget {
47 final String logoSekolah;
48 Dashboard({this.logoSekolah});
49 @override
50 State<StatefulWidget> createState() {
51 return _DashboardState();
52 }
53}
54
55class _DashboardState extends State<Dashboard> with Base {
56 String tahunBulan =
57 "${DateTime.now().year.toString()}${DateTime.now().month.toString()}";
58 StreamSubscription _purchaseUpdatedSubscription;
59 List<IAPItem> _iaps = []; // billing
60 final rp = new NumberFormat("#,##0", "en_US");
61 TglLocal tglLocal = TglLocal();
62 Future<List<Pengumuman>> _peng;
63 Future<List<Iuran>> _iur;
64 Future<List<Berita>> _ber;
65 Future<List<Ekskul>> _eks;
66
67 bool _saving = true;
68 int _selectedPage = 0;
69 final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
70 DateFormat dateFormat;
71 List<MenuModel> items = List<MenuModel>();
72 SharedPreferences sharedPreferences;
73 List<DataNotif> listChat = List<DataNotif>();
74 List<RunningText> listRT = List();
75 List<String> rt = List();
76 DataUser listUser;
77 Future<List<Kalender>> _kalender;
78 DashboardAbsen dashboardAbsen;
79 Future<DashboardAbsen> _dashboardAbsen;
80 JamAbsen jamAbsen;
81 var totalChat = 0;
82 var totalNotif = 0;
83 FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
84 final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
85 ApiServices _apiServices = ApiServices();
86 String urlFile = "";
87 String jenisLogin = "";
88 String jenisRaport = "";
89 String idLogin = "";
90 String idKelas = "";
91 String namaUser = "";
92 String ddAktif;
93 List<TahunAjaran> tahunAjaran;
94 List dataTahunAjaran = List();
95 StreamController<String> streamController = new StreamController();
96 List<String> spChat = [];
97 String namaKelas = "";
98 String idSekolah = "";
99 String modelBisnis = "";
100 String beranda = "";
101 SubscribeBloc _subscribeBloc;
102 SubscribeLoaded _subscribeLoaded = SubscribeLoaded();
103 String logoSekolah = "";
104 DateTime currentBackPressTime;
105
106 Future onSelectNotification(String payload) {
107 debugPrint("payload : $payload");
108 var splitPayload = payload.split(",");
109 Navigator.push(
110 context,
111 MaterialPageRoute(
112 builder: (context) {
113 return ChatDetail(
114 dariId: idLogin,
115 dariJenis: jenisLogin,
116 untukId: splitPayload[4],
117 untukJenis: "g",
118 namaGuru: "Cristine"); //kurang ambil nama guru notif
119 },
120 ),
121 );
122 }
123
124 showNotification(String title, String desc, String payload) async {
125 var android = new AndroidNotificationDetails(
126 'sistesi', 'sistesi2', 'sistesi3',
127 priority: Priority.High, importance: Importance.Max);
128 var iOS = new IOSNotificationDetails();
129 var platform = new NotificationDetails(android, iOS);
130 await flutterLocalNotificationsPlugin.show(0, title, desc, platform,
131 payload: payload);
132 }
133
134 localNotificationSetup() {
135 flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
136 var android = new AndroidInitializationSettings('@mipmap/ic_launcher');
137 var iOS = new IOSInitializationSettings();
138 var initSettings = new InitializationSettings(android, iOS);
139 flutterLocalNotificationsPlugin.initialize(initSettings,
140 onSelectNotification: onSelectNotification);
141 }
142
143 Future clearChat() async {
144 final prefs = await SharedPreferences.getInstance();
145 final key = "chat";
146 prefs.remove(key);
147 }
148
149 Future initSharedPreferences() async {
150 sharedPreferences = await SharedPreferences.getInstance();
151 urlFile = sharedPreferences.getString(Strings.urlFile);
152 jenisLogin = sharedPreferences.getString(Strings.jenisLogin);
153 jenisRaport = sharedPreferences.getString("jenisRaport");
154 idLogin = sharedPreferences.getString(Strings.idJenis);
155 idKelas = sharedPreferences.getString(Strings.idKelas);
156 namaUser = sharedPreferences.getString(Strings.namaUser);
157 modelBisnis = sharedPreferences.getString(Strings.modelBisnis);
158 print("Model Bisnis " + modelBisnis);
159 _apiServices.getDataProfile().then((val) {
160 setState(() {
161 namaKelas = val.namaKelas;
162 idSekolah = val.idSekolah;
163 _saving = false;
164 });
165 });
166
167 loadNotifChat();
168 }
169
170 void removeNotifChat(DataNotif item) {
171 listChat.remove(item);
172 if (listChat.isEmpty) setState(() {});
173 saveNotifChat();
174 }
175
176 void addNotifChat(DataNotif item) {
177 listChat.insert(0, item);
178 saveNotifChat();
179 }
180
181 void loadNotifChat() {
182 spChat = sharedPreferences.getStringList('chat');
183 if (spChat != null) {
184 listChat =
185 spChat.map((item) => DataNotif.fromMap(json.decode(item))).toList();
186 setState(() {
187 totalChat = listChat.length;
188 });
189 }
190 }
191
192 void saveNotifChat() {
193 List<String> stringList =
194 listChat.map((item) => json.encode(item.toMap())).toList();
195 print("dibawah data saveNotifChat");
196 print(stringList);
197 sharedPreferences.setStringList('chat', stringList);
198 }
199
200 void loadRunningText() async {
201 final headers = {"Content-Type": "application/json"};
202 final value = {"a": "a"};
203 final body = json.encode(value);
204 final prefs = await SharedPreferences.getInstance();
205 final urlWs = prefs.getString("urlWs");
206 final subUrl = "runningText";
207
208 final response =
209 await http.post("$urlWs$subUrl", headers: headers, body: body);
210 final responseResult = json.decode(response.body);
211 assert(response.toString() != null);
212 if (response.statusCode == 200) {
213 listRT = (responseResult['data'] as List)
214 .map((data) => new RunningText.fromJson(data))
215 .toList();
216 for (var i = 0; i < listRT.length; i++) {
217 rt.add(listRT[i].isi);
218 }
219 }
220 }
221
222 Future<DashboardAbsen> _loadAbsenInfo() async {
223 final prefs = await SharedPreferences.getInstance();
224 final idJenis = prefs.getString("idJenis");
225 final jenisLogin = prefs.getString("jenisLogin");
226 var data = {"jenis_login": jenisLogin, "id_jenis": idJenis};
227 final headers = {"Content-Type": "application/json"};
228 final body = json.encode(data);
229 final urlWs = prefs.getString("urlWs");
230 final subUrl = "dashboardAbsen";
231 final res = await http.post("$urlWs$subUrl", headers: headers, body: body);
232 final resResult = json.decode(res.body);
233 setState(() {
234 logoSekolah = prefs.getString("logoSekolah");
235 });
236
237 if (res.statusCode == 200) {
238 jamAbsen = JamAbsen.fromJson(resResult['data']['jam_absen']);
239 dashboardAbsen =
240 DashboardAbsen.fromJson(resResult['data']['rekap_absen']);
241 return dashboardAbsen;
242 } else {
243 return null;
244 }
245 }
246
247 List<T> map<T>(List list, Function handler) {
248 List<T> result = [];
249 for (var i = 0; i < list.length; i++) {
250 result.add(handler(i, list[i]));
251 }
252 return result;
253 }
254
255 Future<String> _loadTahunAjaran() async {
256 setState(() {
257 _saving = true;
258 });
259 final prefs = await SharedPreferences.getInstance();
260 final urlWs = prefs.getString("urlWs");
261 final subUrl = "tahunAjaran";
262 final headers = {"Content-Type": "application/json"};
263 final res = await http.post("$urlWs$subUrl", headers: headers);
264 final resResult = json.decode(res.body);
265 for (var i = 0; i < resResult['data'].length; i++) {
266 if (resResult['data'][i]['aktif'] == "1") {
267 ddAktif = resResult['data'][i]['idtanggalan'].toString();
268 }
269 }
270 setState(() {
271 tahunAjaran = (resResult['data'] as List)
272 .map((data) => TahunAjaran.fromJson(data))
273 .toList();
274 dataTahunAjaran = resResult['data'];
275 _saving = false;
276 });
277 return ddAktif;
278 }
279
280 void purchase(int paket) async {
281 // billing
282 print('paket' + _iaps[paket].productId);
283 FlutterInappPurchase.instance.requestPurchase(_iaps[paket].productId,
284 accountIdAndroid: Strings.accountIdAndroid);
285 }
286
287 /// jika pembayaran subscribe produk sudah selesai
288 /// masuk ke method ini untuk mencatat semua data produk google dan data client
289 void confirmPurchase(PurchasedItem purchasedItem) async {
290 // ambil data refresh_token dan google_token di API kita
291 Map<String, dynamic> getGoogleToken = await _apiServices.getGoogleToken();
292
293 // method ini berfungsi untuk mengambil accessTokenGoogle
294 // untuk kebutuhan method berikutnya
295 Map<String, dynamic> getAccessTokenGoogle =
296 await _apiServices.getAccessTokenGoogle(
297 getGoogleToken["refresh_token"], getGoogleToken["google_token"]);
298
299 // validasi pembayaran produk subscribe google
300 final validateReceipt = await _apiServices.validateReceiptAndroid(
301 packageName: Strings.packageName,
302 productId: purchasedItem.productId,
303 productToken: purchasedItem.purchaseToken,
304 accessToken: getAccessTokenGoogle["access_token"],
305 isSubscription: true);
306
307 // tampung data respon validateReceipt
308 final resResult = json.decode(validateReceipt.body);
309
310 // seleksi sku produk mana yg di beli
311 // dan ambil index produk nya
312 String indexProduct = "";
313 Strings.productName.forEach((k, v) {
314 if (v == purchasedItem.productId) {
315 indexProduct = k;
316 }
317 });
318
319 // catat semua data subscribe google termasuk sku produk
320 // dan kirim ke server kita
321 await _apiServices
322 .postUpdateBayar(
323 indexProduct,
324 purchasedItem.productId,
325 purchasedItem.purchaseToken,
326 resResult["startTimeMillis"],
327 resResult["expiryTimeMillis"],
328 resResult["autoRenewing"],
329 resResult["orderId"])
330 .then((val) {
331 // reload data untuk membuka menu apa saja yg dibeli
332 _subscribeBloc..add(CheckSubscribe());
333
334 // tampilkan toast untuk konfirmasi
335 showToast(val != null
336 ? "Pembelian ${purchasedItem.productId} Berhasil"
337 : "Pembelian gagal");
338 });
339 }
340
341 // get product sku by platform
342 getProduct() {
343 if (Platform.isAndroid) {
344 print("======================Platform Android======================");
345 return ["paket_1", "paket_2", "paket_3", "etest", "elearning"];
346 } else if (Platform.isIOS) {
347 print("======================Platform IOS======================");
348 return [
349 "id.sistesi.paket_1",
350 "id.sistesi.paket_2",
351 "id.sistesi.paket_3",
352 "id.sistesi.etest",
353 "id.sistesi.elearning"
354 ];
355 }
356 }
357
358 _initIAPs() async {
359 // billing
360 var result = await FlutterInappPurchase.instance.initConnection;
361 print("Established IAP Connection..." + result);
362 _iaps = await FlutterInappPurchase.instance.getSubscriptions(getProduct());
363
364 for (var i = 0; i < _iaps.length; ++i) {
365 print(_iaps[i].title + " " + _iaps[i].price);
366 var xxx = _iaps[i].description.split("\n");
367 for (int i = 0; i < xxx.length; i++) {
368 print('${xxx[i].replaceAll("- ", "")}');
369 }
370 }
371
372 FlutterInappPurchase.purchaseUpdated.listen((productItem) {
373 // ketika client sudah selesai pembayaran subscribe
374 // jalankan methode dibawah ini
375 confirmPurchase(productItem);
376 });
377 }
378
379 List<Widget> getDescProduct(int indexSKU) {
380 final f = NumberFormat.currency(
381 locale: "id", name: "IDR", decimalDigits: 0, symbol: "Rp. ");
382 final rupiahFormat =
383 f.format(double.parse(Strings.productPrice[indexSKU]).toInt());
384 Text txtKet = Text(
385 "Untuk menggunakan fitur diatas, anda harus berlanggangan $rupiahFormat per bulan. Silahkan klik lanjutkan menuju ke pembayaran",
386 style: TextStyle(
387 color: Colors.grey,
388 ),
389 textAlign: TextAlign.justify,
390 );
391 List<Widget> data = List();
392 if (indexSKU == 0) {
393 data.add(SizedBox(
394 height: 10.0,
395 ));
396 data.add(Text("- E-Learning"));
397 data.add(SizedBox(
398 height: 10.0,
399 ));
400 data.add(txtKet);
401 } else if (indexSKU == 1) {
402 data.add(SizedBox(
403 height: 10.0,
404 ));
405 data.add(Text("- E-Test"));
406 data.add(SizedBox(
407 height: 10.0,
408 ));
409 data.add(txtKet);
410 } else if (indexSKU == 2) {
411 data.add(SizedBox(
412 height: 10.0,
413 ));
414 data.add(Text("- Kalender"));
415 data.add(Text("- Jadwal"));
416 data.add(Text("- Pesan/Chat"));
417 data.add(Text("- Nilai"));
418 data.add(Text("- Ekskul"));
419 data.add(SizedBox(
420 height: 10.0,
421 ));
422 data.add(txtKet);
423 } else if (indexSKU == 3) {
424 data.add(SizedBox(
425 height: 10.0,
426 ));
427 data.add(Text("- Iuran"));
428 data.add(Text("- Pengumuman"));
429 data.add(Text("- Berita"));
430 data.add(Text("- Catatan BK"));
431 data.add(Text("- Raport"));
432 data.add(Text("- Kalender"));
433 data.add(SizedBox(
434 height: 10.0,
435 ));
436 data.add(txtKet);
437 } else if (indexSKU == 4) {
438 data.add(SizedBox(
439 height: 10.0,
440 ));
441 data.add(Text("- Kalender"));
442 data.add(Text("- Jadwal"));
443 data.add(Text("- Pesan/Chat"));
444 data.add(Text("- Nilai"));
445 data.add(Text("- Ekskul"));
446 data.add(Text("- Iuran"));
447 data.add(Text("- Pengumuman"));
448 data.add(Text("- Berita"));
449 data.add(Text("- Catatan BK"));
450 data.add(Text("- Raport"));
451 data.add(Text("- Kalender"));
452 data.add(SizedBox(
453 height: 10.0,
454 ));
455 data.add(txtKet);
456 }
457
458 return data;
459 }
460
461 _showDialog(int indexSKU) {
462 showDialog(
463 context: context,
464 builder: (BuildContext context) => new CupertinoAlertDialog(
465 title: Text(Strings.productTitile[indexSKU]),
466 content: Container(
467 child: Column(
468 crossAxisAlignment: CrossAxisAlignment.start,
469 children: getDescProduct(indexSKU)),
470 ),
471 actions: [
472 FlatButton(
473 onPressed: () => Navigator.of(context).pop(),
474 child: Text(
475 'Keluar',
476 style: TextStyle(color: CupertinoColors.activeBlue),
477 )),
478 FlatButton(
479 onPressed: () {
480 setState(() {
481 _saving = true;
482 });
483 Navigator.of(context).pop();
484 Future.delayed(Duration(seconds: 3), () {
485 _saving = false;
486 _subscribeBloc.add(ByPass(indexSKU: indexSKU));
487 });
488 print("Kuyyyyyyyyyyyyyyyyyyyy");
489 showToast(
490 "Pembelian ${Strings.productTitile[indexSKU]} Berhasil");
491 },
492 child: Text('Lanjutkan',
493 style: TextStyle(color: CupertinoColors.activeBlue)),
494 )
495 ],
496 ),
497 );
498 }
499
500 @override
501 initState() {
502 super.initState();
503 _initIAPs(); // billing
504 // basicSubscribe();
505 _dashboardAbsen = _loadAbsenInfo();
506 _iur = _apiServices.loadIuran();
507 _eks = _apiServices.loadEkskul("today");
508 _ber = _apiServices.getBerita();
509 _peng = _apiServices.getPengumuman();
510 _kalender = _apiServices.getKalender("today");
511 _loadTahunAjaran();
512 loadRunningText();
513 initSharedPreferences();
514 initializeDateFormatting();
515 localNotificationSetup();
516 dateFormat = new DateFormat("EEEE\nd MMMM\nyyyy", "id");
517 _firebaseMessaging.configure(
518 onMessage: (Map<String, dynamic> message) async {
519 final notification = LocalNotificationChat(
520 "notification", message['notification'] as Map);
521 ChatBloc.instance.newNotification(notification);
522
523 print(message["data"]);
524 final idnotif = message["data"]["idnotif"];
525 final idPenerima = message["data"]["id_penerima"];
526 final jenisPenerima = message["data"]["jenis_penerima"];
527 final jenisPengirim = message["data"]["jenis"];
528 final idPengirim = message["data"]["id"];
529 var payload = "";
530 payload = idnotif +
531 "," +
532 jenisPenerima +
533 "," +
534 jenisPengirim +
535 "," +
536 idPenerima +
537 "," +
538 idPengirim;
539 addNotifChat(DataNotif(
540 idNotif: idnotif,
541 idPenerima: idPenerima,
542 jenisPenerima: jenisPenerima,
543 jenisPengirim: jenisPengirim,
544 idPengirim: idPengirim));
545 initSharedPreferences();
546 showNotification(
547 message["data"]["title"], message["data"]["body"], payload);
548 },
549 onLaunch: (Map<String, dynamic> message) async {
550 print("message onLaunch {$message}");
551 },
552 onResume: (Map<String, dynamic> message) async {
553 print("message onResume {$message}");
554 },
555 );
556 _firebaseMessaging.requestNotificationPermissions(
557 const IosNotificationSettings(sound: true, badge: true, alert: true));
558 _firebaseMessaging.onIosSettingsRegistered
559 .listen((IosNotificationSettings settings) {
560 print("Settings registered: $settings");
561 });
562 _firebaseMessaging.getToken().then((String token) {
563 assert(token != null);
564 // setState(() {});
565 });
566 }
567
568 @override
569 dispose() {
570 _purchaseUpdatedSubscription.cancel();
571 streamController.close();
572 _subscribeBloc.close();
573 SystemChrome.setPreferredOrientations([
574 DeviceOrientation.landscapeRight,
575 DeviceOrientation.landscapeLeft,
576 DeviceOrientation.portraitUp,
577 DeviceOrientation.portraitDown,
578 ]);
579 super.dispose();
580 }
581
582 @override
583 Widget build(BuildContext context) {
584 Uint8List bytes = base64Decode(widget.logoSekolah);
585
586 var now = new DateTime.now();
587 var waktu = dateFormat.format(now);
588
589 final CarouselSlider runningTexta = CarouselSlider(
590 viewportFraction: 1.0,
591 autoPlayInterval: Duration(seconds: 3),
592 aspectRatio: 2,
593 autoPlay: true,
594 enlargeCenterPage: true,
595 items: map<Widget>(
596 rt,
597 (index, i) {
598 return Container(
599 alignment: Alignment.centerLeft,
600 child: Text(
601 listRT[index].isi,
602 style: TextStyle(
603 fontSize: 11.0,
604 ),
605 ),
606 );
607 },
608 ),
609 );
610
611 final runningText = Container(
612 color: Colors.grey[300],
613 width: MediaQuery.of(context).size.width,
614 height: 60,
615 child: ListTile(
616 leading: Icon(
617 Icons.info,
618 size: 40.0,
619 ),
620 title:
621 rt.isNotEmpty && listRT.isNotEmpty ? runningTexta : Container(),
622 ));
623
624 final eventInfo =
625 BlocBuilder<SubscribeBloc, SubscribeState>(builder: (context, state) {
626 _subscribeBloc = BlocProvider.of<SubscribeBloc>(context);
627 if (state is Loading) {
628 return Container(
629 height: 200.0,
630 width: MediaQuery.of(context).size.width,
631 color: Colors.white,
632 alignment: Alignment.bottomCenter,
633 child: Center(child: CircularProgressIndicator()));
634 } else {
635 _subscribeLoaded = state as SubscribeLoaded;
636 return FutureBuilder(
637 future: _kalender,
638 // ignore: missing_return
639 builder: (BuildContext context, AsyncSnapshot snapshot) {
640 switch (snapshot.connectionState) {
641 case ConnectionState.none:
642 return Text('Tidak ada Event');
643 case ConnectionState.active:
644 return Text('');
645 case ConnectionState.waiting:
646 return Container(
647 height: 200.0,
648 width: MediaQuery.of(context).size.width,
649 color: Colors.white,
650 alignment: Alignment.bottomCenter,
651 child: Center(child: CircularProgressIndicator()));
652 case ConnectionState.done:
653 var count = 0;
654 Widget ketHeader = Container();
655 Widget ket = Container();
656 Widget badgeKet = Container();
657 Widget ketSekolah = Container();
658
659 if (snapshot.data != null) {
660 if (snapshot.data[0].ket != "") {
661 badgeKet = Container(
662 width: 100.0,
663 height: 30.0,
664 decoration: BoxDecoration(
665 color: CupertinoColors.destructiveRed,
666 borderRadius: BorderRadius.circular(20.0),
667 ),
668 child: Center(
669 child: Text(
670 "KBM Libur",
671 style: TextStyle(
672 fontSize: 12.0,
673 color: CupertinoColors
674 .white), // default text style
675 ),
676 ),
677 );
678 ketHeader = Container(
679 padding: const EdgeInsets.only(top: 5.0),
680 child: Text(
681 "KBM Libur",
682 style: new TextStyle(
683 fontWeight: FontWeight.w800,
684 fontSize: 18.0,
685 ),
686 ));
687 ket = Container(
688 padding: const EdgeInsets.only(
689 top: 10.0, bottom: 40.0, right: 25.0),
690 child: Text(
691 snapshot.data[0].ket,
692 style: new TextStyle(
693 fontSize: 14.0, color: Colors.grey[500]),
694 ));
695 }
696 }
697
698 if (snapshot.data != null) {
699 if (snapshot.data[0].ketSekolah != "") {
700 count = 1;
701 ketSekolah = Container(
702 padding: const EdgeInsets.only(
703 top: 10.0, bottom: 40.0, right: 25.0),
704 child: Text(
705 snapshot.data[0].ketSekolah,
706 style: TextStyle(
707 fontSize: 14.0, color: Colors.grey[500]),
708 ));
709 }
710 }
711
712 final _eventInfo = Container(
713 width: MediaQuery.of(context).size.width,
714 child: Stack(
715 children: <Widget>[
716 Card(
717 elevation: 5,
718 shape: RoundedRectangleBorder(
719 borderRadius: BorderRadius.circular(8.0),
720 ),
721 child: InkWell(
722 onTap: () {
723 Navigator.push(context,
724 MaterialPageRoute(builder: (context) {
725 return KalenderView();
726 }));
727 },
728 child: Container(
729 child: IntrinsicHeight(
730 child: Row(
731 mainAxisAlignment: MainAxisAlignment.center,
732 children: <Widget>[
733 Expanded(
734 child: Column(
735 mainAxisAlignment:
736 MainAxisAlignment.start,
737 crossAxisAlignment:
738 CrossAxisAlignment.center,
739 children: <Widget>[
740 Container(
741 padding: EdgeInsets.all(10),
742 child: Text(
743 waktu,
744 style:
745 TextStyle(fontSize: 16.0),
746 textAlign: TextAlign.center,
747 )),
748 badgeKet,
749 SizedBox(
750 height: 10.0,
751 ),
752 Container(
753 width: 120.0,
754 height: 30.0,
755 decoration: BoxDecoration(
756 gradient: Styles.colorButton,
757 borderRadius:
758 BorderRadius.circular(20.0),
759 ),
760 child: Center(
761 child: Text(
762 count == 0
763 ? "Tidak ada Kegiatan"
764 : "$count Kegiatan",
765 style: TextStyle(
766 fontSize: 12.0,
767 color: CupertinoColors
768 .white), // default text style
769 ),
770 ),
771 ),
772 SizedBox(
773 height: 10.0,
774 ),
775 ],
776 ),
777 ),
778 VerticalDivider(
779 color: Colors.grey,
780 ),
781 Expanded(
782 child: Column(
783 mainAxisAlignment:
784 MainAxisAlignment.start,
785 crossAxisAlignment:
786 CrossAxisAlignment.start,
787 children: <Widget>[
788 ketHeader,
789 ket,
790 Container(
791 padding: EdgeInsets.all(10.0),
792 child: Text(
793 "Daftar Kegiatan",
794 style: TextStyle(
795 fontSize: 16.0,
796 ),
797 )),
798 ketSekolah,
799 ],
800 ),
801 )
802 ],
803 )))),
804 ),
805 _subscribeLoaded.paket1 == false
806 ? InkWell(
807 onTap: () {
808 int indexSKU;
809 if (modelBisnis == "Basic Subscribe") {
810 indexSKU = 4;
811 } else {
812 indexSKU = 2;
813 }
814 _showDialog(indexSKU);
815 },
816 child: Container(
817 height: 200.0,
818 width: MediaQuery.of(context).size.width,
819 color: Color(0xFFFFFFFF).withOpacity(0.9),
820 alignment: Alignment.bottomCenter,
821 child: Center(
822 child:
823 Icon(Icons.lock_outline, size: 100.0),
824 ),
825 ))
826 : Container()
827 ],
828 ));
829 return _eventInfo;
830 }
831 });
832 }
833 });
834
835 final absenInfo = FutureBuilder(
836 future: _dashboardAbsen,
837 // ignore: missing_return
838 builder: (BuildContext context, AsyncSnapshot snapshot) {
839 switch (snapshot.connectionState) {
840 case ConnectionState.none:
841 return Text('Tidak ada Absen');
842 case ConnectionState.active:
843 return Text('');
844 case ConnectionState.waiting:
845 return Container(
846 height: 200.0,
847 width: MediaQuery.of(context).size.width,
848 color: Colors.white,
849 alignment: Alignment.bottomCenter,
850 child: Center(child: CircularProgressIndicator()));
851 case ConnectionState.done:
852 if (snapshot.hasError) {
853 return Text('${snapshot.error}',
854 style: TextStyle(color: Colors.red));
855 } else {
856 final _absenInfo = Container(
857 width: MediaQuery.of(context).size.width,
858 child: Stack(
859 children: <Widget>[
860 Container(
861 height: 220.0,
862 width: 400.0,
863 child: Card(
864 elevation: 5,
865 shape: RoundedRectangleBorder(
866 borderRadius: BorderRadius.circular(8.0),
867 ),
868 child: InkWell(
869 onTap: () {
870 Navigator.push(context,
871 MaterialPageRoute(builder: (context) {
872 return Absensi(tahunBulan, idLogin,
873 jenisLogin, namaUser);
874 }));
875 },
876 child: Row(
877 mainAxisAlignment: MainAxisAlignment.center,
878 children: <Widget>[
879 Expanded(
880 child: Column(
881 crossAxisAlignment:
882 CrossAxisAlignment.center,
883 children: <Widget>[
884 Container(
885 padding: const EdgeInsets.only(
886 top: 15.0),
887 width: 140,
888 alignment: Alignment.center,
889 child: Text(
890 "Hari Ini",
891 style: new TextStyle(
892 fontSize: 16.0,
893 color: Colors.lightBlue),
894 )),
895 Divider(
896 height: 30,
897 color: Colors.grey,
898 ),
899 Container(
900 height: 50.0,
901 width: 80.0,
902 child: Column(
903 mainAxisAlignment:
904 MainAxisAlignment.spaceEvenly,
905 crossAxisAlignment:
906 CrossAxisAlignment.center,
907 children: <Widget>[
908 Text(
909 "Masuk",
910 style: new TextStyle(
911 fontSize: 14.0),
912 ),
913 Text(
914 jamAbsen.jamMasuk != "-"
915 ? jamAbsen.jamMasuk
916 : "-",
917 style: new TextStyle(
918 fontSize: 18.0),
919 ),
920 ],
921 ),
922 ),
923 Divider(
924 height: 30,
925 color: Colors.grey,
926 ),
927 Container(
928 height: 50.0,
929 width: 70.0,
930 child: Column(
931 mainAxisAlignment:
932 MainAxisAlignment.spaceBetween,
933 crossAxisAlignment:
934 CrossAxisAlignment.center,
935 children: <Widget>[
936 Text(
937 "Pulang",
938 style: new TextStyle(
939 fontSize: 14.0),
940 ),
941 Text(
942 jamAbsen.jamPulang != "-"
943 ? jamAbsen.jamPulang
944 : "-",
945 style: new TextStyle(
946 fontSize: 18.0),
947 ),
948 ],
949 ),
950 ),
951 ],
952 ),
953 ),
954 VerticalDivider(
955 color: Colors.grey,
956 ),
957 Expanded(
958 child: Column(
959 crossAxisAlignment:
960 CrossAxisAlignment.start,
961 mainAxisAlignment:
962 MainAxisAlignment.start,
963 children: <Widget>[
964 Container(
965 padding: const EdgeInsets.only(
966 top: 15.0),
967 alignment: Alignment.center,
968 child: Text(
969 "Bulan Ini",
970 style: new TextStyle(
971 fontSize: 16.0,
972 color: Colors.lightBlue),
973 )),
974 Divider(
975 height: 30,
976 color: Colors.grey,
977 ),
978 Container(
979 height: 130,
980 width: 140.0,
981 padding: EdgeInsets.all(5.0),
982 child: Column(
983 crossAxisAlignment:
984 CrossAxisAlignment.start,
985 mainAxisAlignment:
986 MainAxisAlignment
987 .spaceBetween,
988 children: <Widget>[
989 ketAbsen(
990 color: Colors.greenAccent,
991 jmlAbsen:
992 snapshot.data.masuk,
993 ket: 'Masuk'),
994 ketAbsen(
995 color: Colors.blueAccent,
996 jmlAbsen:
997 snapshot.data.izin,
998 ket: 'Izin'),
999 ketAbsen(
1000 color: Colors.purple[900],
1001 jmlAbsen:
1002 snapshot.data.alpha,
1003 ket: 'Sakit'),
1004 ketAbsen(
1005 color: Colors.red[900],
1006 jmlAbsen:
1007 snapshot.data.masuk,
1008 ket: 'Alpha'),
1009 ]),
1010 )
1011 ],
1012 ),
1013 )
1014 ],
1015 )),
1016 ),
1017 ),
1018 ],
1019 ),
1020 );
1021 return _absenInfo;
1022 }
1023 }
1024 });
1025
1026 final iuran =
1027 BlocBuilder<SubscribeBloc, SubscribeState>(builder: (context, state) {
1028 _subscribeBloc = BlocProvider.of<SubscribeBloc>(context);
1029 if (state is Loading) {
1030 return Container(
1031 height: 200.0,
1032 width: MediaQuery.of(context).size.width,
1033 color: Colors.white,
1034 alignment: Alignment.bottomCenter,
1035 child: Center(child: CircularProgressIndicator()));
1036 } else {
1037 _subscribeLoaded = state as SubscribeLoaded;
1038 }
1039 return FutureBuilder(
1040 future: _iur,
1041 // ignore: missing_return
1042 builder: (BuildContext context, AsyncSnapshot snapshot) {
1043 switch (snapshot.connectionState) {
1044 case ConnectionState.none:
1045 return Text('Tidak ada Iuran');
1046 case ConnectionState.active:
1047 return Text('');
1048 case ConnectionState.waiting:
1049 return Container(
1050 height: 200.0,
1051 width: MediaQuery.of(context).size.width,
1052 color: Colors.white,
1053 alignment: Alignment.bottomCenter,
1054 child: Center(child: CircularProgressIndicator()));
1055 case ConnectionState.done:
1056 if (snapshot.hasError) {
1057 final refresh = Column(
1058 children: <Widget>[
1059 IconButton(
1060 icon: Icon(CupertinoIcons.refresh),
1061 onPressed: () {
1062 setState(() {
1063 _iur = _apiServices.loadIuran();
1064 });
1065 },
1066 ),
1067 Text("Terjadi Kesalahan"),
1068 // Text('${snapshot.error}',
1069 // style: TextStyle(color: Colors.red))
1070 ],
1071 );
1072 return refresh;
1073 } else if (!snapshot.hasData) {
1074 return Card(
1075 elevation: 4.0,
1076 child: Padding(
1077 padding: EdgeInsets.all(8.0),
1078 child: Text("Tidak ada iuran yang belum dibayar")),
1079 );
1080 } else {
1081 final _iuran = Container(
1082 child: Column(
1083 mainAxisAlignment: MainAxisAlignment.spaceBetween,
1084 crossAxisAlignment: CrossAxisAlignment.start,
1085 children: <Widget>[
1086 Container(
1087 padding: EdgeInsets.all(8.0),
1088 child: Align(
1089 alignment: Alignment.topLeft,
1090 child: Text(
1091 jenisLogin == "s" ? "Iuran" : "",
1092 style: TextStyle(
1093 fontWeight: FontWeight.bold, fontSize: 20.0),
1094 )),
1095 ),
1096 _subscribeLoaded.paket2 == false
1097 ? InkWell(
1098 onTap: () {
1099 int indexSKU;
1100 if (modelBisnis == "Basic Subscribe") {
1101 indexSKU = 4;
1102 } else {
1103 indexSKU = 3;
1104 }
1105 _showDialog(indexSKU);
1106 },
1107 child: Card(
1108 elevation: 5.0,
1109 child: Container(
1110 height: 200.0,
1111 width: MediaQuery.of(context).size.width,
1112 color: Colors.white,
1113 alignment: Alignment.bottomCenter,
1114 child: Center(
1115 child:
1116 Icon(Icons.lock_outline, size: 100.0),
1117 ),
1118 )))
1119 : Container(
1120 padding: EdgeInsets.only(bottom: 20.0),
1121 height: 170.0,
1122 width: MediaQuery.of(context).size.width,
1123 child: ListView.builder(
1124 scrollDirection: Axis.horizontal,
1125 // padding: EdgeInsets.all(2),
1126 itemCount: snapshot.data.length,
1127 itemBuilder: (BuildContext context, int index) {
1128 Widget statusBayar;
1129 final rp = new NumberFormat("#,##0", "en_US");
1130 if (snapshot.data[index].statusBayar == "1") {
1131 statusBayar = Container(
1132 padding: const EdgeInsets.all(5.0),
1133 // color: Colors.lightBlue[400],
1134 decoration: BoxDecoration(
1135 color: Colors.blue,
1136 borderRadius:
1137 new BorderRadius.circular(20.0),
1138 ),
1139 child: Text(
1140 "Lunas",
1141 style: new TextStyle(
1142 fontSize: 15.0,
1143 color: CupertinoColors.white),
1144 ));
1145 } else {
1146 statusBayar = Container(
1147 padding: const EdgeInsets.all(5.0),
1148 decoration: BoxDecoration(
1149 color: CupertinoColors.destructiveRed,
1150 borderRadius:
1151 new BorderRadius.circular(20.0),
1152 ),
1153 child: Text(
1154 "Belum Bayar",
1155 style: new TextStyle(
1156 fontSize: 15.0,
1157 color: Colors.white),
1158 ),
1159 );
1160 }
1161 return Container(
1162 padding:
1163 EdgeInsets.only(left: 5.0, right: 7.0),
1164 width: 280.0,
1165 height: 250.0,
1166 child: Card(
1167 elevation: 5.0,
1168 shape: RoundedRectangleBorder(
1169 borderRadius:
1170 BorderRadius.circular(15.0)),
1171 child: Container(
1172 padding: EdgeInsets.all(15.0),
1173 child: Column(
1174 mainAxisAlignment:
1175 MainAxisAlignment.spaceBetween,
1176 crossAxisAlignment:
1177 CrossAxisAlignment.start,
1178 children: <Widget>[
1179 Text(snapshot.data[index].namaIuran,
1180 style: TextStyle(
1181 fontSize: 18.0,
1182 fontWeight:
1183 FontWeight.bold)),
1184 Text(
1185 tglLocal.getTgl(snapshot
1186 .data[index].bulanTahun),
1187 style: TextStyle(
1188 color: CupertinoColors
1189 .inactiveGray,
1190 )),
1191 Text(
1192 "Rp. " +
1193 rp.format(int.parse(snapshot
1194 .data[index].jml)),
1195 style: TextStyle(
1196 color: CupertinoColors
1197 .activeBlue,
1198 fontWeight:
1199 FontWeight.bold)),
1200 statusBayar,
1201 ],
1202 ),
1203 ),
1204 ),
1205 );
1206 },
1207 ),
1208 )
1209 ]));
1210 return _iuran;
1211 }
1212 }
1213 },
1214 );
1215 });
1216
1217 final pengumuman = BlocBuilder<SubscribeBloc, SubscribeState>(
1218 builder: (context, state) {
1219 _subscribeBloc = BlocProvider.of<SubscribeBloc>(context);
1220 if (state is Loading) {
1221 return Container(
1222 height: 200.0,
1223 width: MediaQuery.of(context).size.width,
1224 color: Colors.white,
1225 alignment: Alignment.bottomCenter,
1226 child: Center(child: CircularProgressIndicator()));
1227 } else {
1228 _subscribeLoaded = state as SubscribeLoaded;
1229 return FutureBuilder(
1230 future: _peng,
1231 // ignore: missing_return
1232 builder: (BuildContext context, AsyncSnapshot snapshot) {
1233 // ignore: missing_return
1234 switch (snapshot.connectionState) {
1235 case ConnectionState.none:
1236 return Text('Tidak ada Pengumuman');
1237 case ConnectionState.active:
1238 return Text('');
1239 case ConnectionState.waiting:
1240 return Container(
1241 height: 200.0,
1242 width: MediaQuery.of(context).size.width,
1243 color: Colors.white,
1244 alignment: Alignment.bottomCenter,
1245 child: Center(child: CircularProgressIndicator()));
1246 case ConnectionState.done:
1247 if (snapshot.hasError) {
1248 final refresh = Column(
1249 children: <Widget>[
1250 IconButton(
1251 icon: Icon(CupertinoIcons.refresh),
1252 onPressed: () {
1253 setState(() {
1254 _peng = _apiServices.getPengumuman();
1255 });
1256 },
1257 ),
1258 Text("Terjadi Kesalahan"),
1259 // Text('${snapshot.error}',
1260 // style: TextStyle(color: Colors.red))
1261 ],
1262 );
1263 return refresh;
1264 } else if (!snapshot.hasData) {
1265 return Container(child: Text("Tidak ada pengumuman"));
1266 } else {
1267 int total = snapshot.data.length >= 5
1268 ? 6
1269 : snapshot.data.length + 1;
1270 final _pengumuman = Container(
1271 width: MediaQuery.of(context).size.width,
1272 child: Column(
1273 mainAxisAlignment: MainAxisAlignment.start,
1274 crossAxisAlignment: CrossAxisAlignment.start,
1275 children: <Widget>[
1276 Container(
1277 padding:
1278 EdgeInsets.fromLTRB(7.0, 5.0, 10.0, 10.0),
1279 child: Align(
1280 alignment: Alignment.topLeft,
1281 child: Text(
1282 'Pengumuman',
1283 style: TextStyle(
1284 fontWeight: FontWeight.bold,
1285 fontSize: 20.0),
1286 ),
1287 ),
1288 ),
1289 _subscribeLoaded.paket2 == false
1290 ? InkWell(
1291 onTap: () {
1292 int indexSKU;
1293 if (modelBisnis ==
1294 "Basic Subscribe") {
1295 indexSKU = 4;
1296 } else {
1297 indexSKU = 3;
1298 }
1299 _showDialog(indexSKU);
1300 },
1301 child: Card(
1302 elevation: 5.0,
1303 child: Container(
1304 height: 200.0,
1305 width: MediaQuery.of(context)
1306 .size
1307 .width,
1308 color: Colors.white,
1309 alignment: Alignment.bottomCenter,
1310 child: Center(
1311 child: Icon(Icons.lock_outline,
1312 size: 100.0),
1313 ),
1314 )))
1315 : Container(
1316 height: 260.0,
1317 width:
1318 MediaQuery.of(context).size.width,
1319 child: ListView.builder(
1320 scrollDirection: Axis.horizontal,
1321 padding: EdgeInsets.all(2),
1322 itemCount: total,
1323 itemBuilder: (BuildContext context,
1324 int index) {
1325 String urlImage = "";
1326 if (!(index == total - 1)) {
1327 if (snapshot.data[index]
1328 .thumbnail ==
1329 null ||
1330 snapshot.data[index].tipe ==
1331 "Pdf") {
1332 urlImage =
1333 "https://dev.sistesi.id/basic/public/img/nodata.jpg";
1334 } else if (snapshot
1335 .data[index].thumbnail
1336 .toString()
1337 .contains("https")) {
1338 urlImage = snapshot
1339 .data[index].thumbnail;
1340 } else {
1341 urlImage = urlFile.toString() +
1342 snapshot
1343 .data[index].thumbnail
1344 .toString();
1345 }
1346 }
1347 return index == total - 1
1348 ? GestureDetector(
1349 onTap: () {
1350 Navigator.pushNamed(
1351 context,
1352 '/daftarPengumuman');
1353 },
1354 child: Container(
1355 child: Column(
1356 mainAxisAlignment:
1357 MainAxisAlignment
1358 .center,
1359 children: <Widget>[
1360 Container(
1361 height: 70.0,
1362 width: 70.0,
1363 child: Card(
1364 shape:
1365 RoundedRectangleBorder(
1366 borderRadius:
1367 BorderRadius
1368 .circular(
1369 60.0),
1370 ),
1371 child: Icon(
1372 CupertinoIcons
1373 .right_chevron,
1374 size: 50.0),
1375 )),
1376 Text(
1377 "Lihat Semua",
1378 style: TextStyle(
1379 color:
1380 Colors.blue,
1381 fontWeight:
1382 FontWeight
1383 .bold),
1384 )
1385 ],
1386 )))
1387 : Container(
1388 padding: EdgeInsets.only(
1389 left: 5.0, right: 7.0),
1390 width: 230.0,
1391 height: 150.0,
1392 child: GestureDetector(
1393 onTap: () {
1394 Navigator.push(
1395 context,
1396 MaterialPageRoute(
1397 builder:
1398 (context) {
1399 return PengumumanBeritaView(
1400 id: snapshot
1401 .data[index]
1402 .id,
1403 tipe: "p",
1404 );
1405 }));
1406 },
1407 child: Card(
1408 elevation: 3,
1409 shape: RoundedRectangleBorder(
1410 borderRadius:
1411 BorderRadius
1412 .circular(
1413 20.0)),
1414 child: Column(
1415 crossAxisAlignment:
1416 CrossAxisAlignment
1417 .start,
1418 mainAxisAlignment:
1419 MainAxisAlignment
1420 .start,
1421 children: <
1422 Widget>[
1423 Container(
1424 width:
1425 230.0,
1426 height:
1427 150.0,
1428 child: ClipRRect(
1429 borderRadius: BorderRadius.only(topLeft: const Radius.circular(20.0), topRight: const Radius.circular(20.0)),
1430 child: FadeInImage.assetNetwork(
1431 fit:
1432 BoxFit.cover,
1433 image:
1434 "$urlImage",
1435 placeholder:
1436 "assets/images/nodata.jpg",
1437 ))),
1438 Divider(
1439 height:
1440 20.0,
1441 color: Colors
1442 .grey,
1443 ),
1444 Container(
1445 child:
1446 ListTile(
1447 title: Text(
1448 snapshot
1449 .data[
1450 index]
1451 .judul,
1452 style: TextStyle(
1453 fontSize:
1454 14.0)),
1455 subtitle:
1456 Column(
1457 mainAxisAlignment:
1458 MainAxisAlignment
1459 .start,
1460 crossAxisAlignment:
1461 CrossAxisAlignment
1462 .start,
1463 children: <
1464 Widget>[
1465 Text("Kepada : " +
1466 snapshot.data[index].ditujukanUntuk),
1467 Text(
1468 tglLocal.getTgl(snapshot.data[index].tanggal),
1469 style: TextStyle(color: Colors.grey, fontSize: 12.0)),
1470 ],
1471 ),
1472 ))
1473 ]))),
1474 );
1475 },
1476 ),
1477 )
1478 ]));
1479 return _pengumuman;
1480 }
1481 }
1482 });
1483 }
1484 },
1485 );
1486
1487 //Sementara Begini
1488 String beranda = sharedPreferences == null
1489 ? "Kompleks"
1490 : sharedPreferences.getString("beranda");
1491 final berita =
1492 BlocBuilder<SubscribeBloc, SubscribeState>(builder: (context, state) {
1493 _subscribeBloc = BlocProvider.of<SubscribeBloc>(context);
1494 if (state is Loading) {
1495 return Container(
1496 height: 200.0,
1497 width: MediaQuery.of(context).size.width,
1498 color: Colors.white,
1499 alignment: Alignment.bottomCenter,
1500 child: Center(child: CircularProgressIndicator()));
1501 } else {
1502 _subscribeLoaded = state as SubscribeLoaded;
1503 return FutureBuilder(
1504 future: _ber,
1505 // ignore: missing_return
1506 builder: (BuildContext context, AsyncSnapshot snapshot) {
1507 switch (snapshot.connectionState) {
1508 case ConnectionState.none:
1509 return Text('Tidak ada Berita');
1510 break;
1511 case ConnectionState.waiting:
1512 return Container(
1513 height: 200.0,
1514 width: MediaQuery.of(context).size.width,
1515 color: Colors.white,
1516 alignment: Alignment.bottomCenter,
1517 child: Center(child: CircularProgressIndicator()));
1518 break;
1519 case ConnectionState.active:
1520 return Text('');
1521 break;
1522 case ConnectionState.done:
1523 if (snapshot.hasError) {
1524 final refresh = Column(
1525 children: <Widget>[
1526 IconButton(
1527 icon: Icon(CupertinoIcons.refresh),
1528 onPressed: () {
1529 setState(() {
1530 _ber = _apiServices.getBerita();
1531 });
1532 },
1533 ),
1534 Text("Terjadi Kesalahan"),
1535 // Text('${snapshot.error}',
1536 // style: TextStyle(color: Colors.red))
1537 ],
1538 );
1539 return refresh;
1540 } else if (!snapshot.hasData) {
1541 return Container(child: Text("Tidak ada Berita"));
1542 } else {
1543 int total = snapshot.data.length >= 5
1544 ? 6
1545 : snapshot.data.length + 1;
1546 final _berita = Container(
1547 padding: EdgeInsets.only(top: 50.0),
1548 width: MediaQuery.of(context).size.width,
1549 child: Column(
1550 mainAxisAlignment: MainAxisAlignment.start,
1551 crossAxisAlignment: CrossAxisAlignment.start,
1552 children: <Widget>[
1553 Container(
1554 padding:
1555 EdgeInsets.fromLTRB(7.0, 5.0, 10.0, 10.0),
1556 child: Align(
1557 alignment: Alignment.topLeft,
1558 child: Text(
1559 'Berita',
1560 style: TextStyle(
1561 fontWeight: FontWeight.bold,
1562 fontSize: 20.0),
1563 ),
1564 ),
1565 ),
1566 _subscribeLoaded.paket2 == false
1567 ? InkWell(
1568 onTap: () {
1569 int indexSKU;
1570 if (modelBisnis == "Basic Subscribe") {
1571 indexSKU = 4;
1572 } else {
1573 indexSKU = 3;
1574 }
1575 _showDialog(indexSKU);
1576 },
1577 child: Card(
1578 elevation: 5.0,
1579 child: Container(
1580 height: 200.0,
1581 width: MediaQuery.of(context)
1582 .size
1583 .width,
1584 color: Colors.white,
1585 alignment: Alignment.bottomCenter,
1586 child: Center(
1587 child: Icon(Icons.lock_outline,
1588 size: 100.0),
1589 ),
1590 )))
1591 : Container(
1592 padding: EdgeInsets.only(right: 7.0),
1593 height: 260.0,
1594 width: MediaQuery.of(context).size.width,
1595 child: ListView.builder(
1596 scrollDirection: Axis.horizontal,
1597 padding: EdgeInsets.all(2),
1598 itemCount: total,
1599 itemBuilder:
1600 (BuildContext context, int index) {
1601 String urlImage = "";
1602 if (!(index == total - 1)) {
1603 if (snapshot.data[index]
1604 .thumbnail ==
1605 null ||
1606 snapshot.data[index].tipe ==
1607 "Pdf") {
1608 urlImage =
1609 "https://dev.sistesi.id/basic/public/img/nodata.jpg";
1610 } else if (snapshot
1611 .data[index].thumbnail
1612 .toString()
1613 .contains("https")) {
1614 urlImage = snapshot
1615 .data[index].thumbnail;
1616 } else {
1617 urlImage = urlFile.toString() +
1618 snapshot.data[index].thumbnail
1619 .toString();
1620 }
1621 }
1622 return index == total - 1
1623 ? GestureDetector(
1624 onTap: () {
1625 Navigator.pushNamed(context,
1626 '/daftarBerita');
1627 },
1628 child: Container(
1629 child: Column(
1630 mainAxisAlignment:
1631 MainAxisAlignment
1632 .center,
1633 children: <Widget>[
1634 Container(
1635 height: 70.0,
1636 width: 70.0,
1637 child: Card(
1638 shape:
1639 RoundedRectangleBorder(
1640 borderRadius:
1641 BorderRadius
1642 .circular(
1643 60.0),
1644 ),
1645 child: Icon(
1646 CupertinoIcons
1647 .right_chevron,
1648 size: 50.0))),
1649 Text(
1650 "Lihat Semua",
1651 style: TextStyle(
1652 color: Colors.blue,
1653 fontWeight:
1654 FontWeight
1655 .bold),
1656 )
1657 ],
1658 )))
1659 : Container(
1660 padding: EdgeInsets.only(
1661 left: 5.0, right: 7.0),
1662 width: MediaQuery.of(context)
1663 .size
1664 .width *
1665 0.86,
1666 height: 150.0,
1667 child: Card(
1668 shape:
1669 RoundedRectangleBorder(
1670 borderRadius:
1671 BorderRadius
1672 .circular(
1673 20.0)),
1674 child: GestureDetector(
1675 onTap: () {
1676 Navigator.push(
1677 context,
1678 MaterialPageRoute(
1679 builder:
1680 (context) {
1681 return PengumumanBeritaView(
1682 id: snapshot
1683 .data[index]
1684 .id,
1685 tipe: "b",
1686 );
1687 }));
1688 },
1689 child: Column(
1690 crossAxisAlignment:
1691 CrossAxisAlignment
1692 .start,
1693 children: <Widget>[
1694 Container(
1695 width: MediaQuery.of(
1696 context)
1697 .size
1698 .width *
1699 0.86,
1700 height: 150.0,
1701 child:
1702 ClipRRect(
1703 borderRadius: BorderRadius.only(
1704 topLeft: Radius
1705 .circular(
1706 20.0),
1707 topRight:
1708 Radius.circular(
1709 20.0)),
1710 child: FadeInImage
1711 .assetNetwork(
1712 fit: BoxFit
1713 .cover,
1714 image:
1715 "$urlImage",
1716 placeholder:
1717 "assets/images/nodata.jpg",
1718 ),
1719 ),
1720 ),
1721 Divider(
1722 color:
1723 Colors.grey,
1724 ),
1725 Container(
1726 //padding: EdgeInsets.all(5.0),
1727 height: 60.0,
1728 child:
1729 ListTile(
1730 title: Text(snapshot
1731 .data[
1732 index]
1733 .judul),
1734 subtitle: Text(
1735 tglLocal.getTgl(snapshot
1736 .data[
1737 index]
1738 .tanggal),
1739 style: TextStyle(
1740 color:
1741 Colors.grey,
1742 fontSize: 12.0)),
1743 )),
1744 ]),
1745 )),
1746 );
1747 },
1748 ),
1749 )
1750 ]));
1751 return _berita;
1752 }
1753 break;
1754 }
1755 });
1756 }
1757 });
1758
1759 final ekskul =
1760 BlocBuilder<SubscribeBloc, SubscribeState>(builder: (context, state) {
1761 _subscribeBloc = BlocProvider.of<SubscribeBloc>(context);
1762 if (state is Loading) {
1763 return Container(
1764 height: 200.0,
1765 width: MediaQuery.of(context).size.width,
1766 color: Colors.white,
1767 alignment: Alignment.bottomCenter,
1768 child: Center(child: CircularProgressIndicator()));
1769 } else {
1770 _subscribeLoaded = state as SubscribeLoaded;
1771 return FutureBuilder(
1772 future: _eks,
1773 // ignore: missing_return
1774 builder: (BuildContext context, AsyncSnapshot snapshot) {
1775 switch (snapshot.connectionState) {
1776 case ConnectionState.none:
1777 return Text('Tidak ada Ekskul');
1778 break;
1779 case ConnectionState.waiting:
1780 return Container(
1781 height: 200.0,
1782 width: MediaQuery.of(context).size.width,
1783 color: Colors.white,
1784 alignment: Alignment.bottomCenter,
1785 child: Center(child: CircularProgressIndicator()));
1786 break;
1787 case ConnectionState.active:
1788 return Text('');
1789 break;
1790 case ConnectionState.done:
1791 if (snapshot.hasError) {
1792 return Container(
1793 child: Text("Terjadi kesalahan"),
1794 );
1795 } else if (!snapshot.hasData) {
1796 return Card(
1797 elevation: 4.0,
1798 child: Padding(
1799 padding: EdgeInsets.all(8.0),
1800 child: Text(
1801 "Tidak ada kegiatan Ekstrakulikuler pada hari ini maupun yang anda ikuti"),
1802 ),
1803 );
1804 } else {
1805 final _ekskul = Container(
1806 width: MediaQuery.of(context).size.width,
1807 child: Column(
1808 mainAxisAlignment: MainAxisAlignment.start,
1809 crossAxisAlignment: CrossAxisAlignment.start,
1810 children: <Widget>[
1811 Container(
1812 padding:
1813 EdgeInsets.fromLTRB(7.0, 5.0, 10.0, 10.0),
1814 child: Align(
1815 alignment: Alignment.topLeft,
1816 child: Text(
1817 'Ekstrakulikuler',
1818 style: TextStyle(
1819 fontWeight: FontWeight.bold,
1820 fontSize: 20.0),
1821 ),
1822 ),
1823 ),
1824 Container(
1825 child: _subscribeLoaded.paket1 == false
1826 ? InkWell(
1827 onTap: () {
1828 int indexSKU;
1829 if (modelBisnis ==
1830 "Basic Subscribe") {
1831 indexSKU = 4;
1832 } else {
1833 indexSKU = 2;
1834 }
1835 _showDialog(indexSKU);
1836 },
1837 child: Card(
1838 elevation: 5.0,
1839 child: Container(
1840 width: MediaQuery.of(context)
1841 .size
1842 .width,
1843 color: Colors.white,
1844 alignment: Alignment.bottomCenter,
1845 child: Center(
1846 child: Icon(Icons.lock_outline,
1847 size: 100.0),
1848 ),
1849 )))
1850 : Container(
1851 width:
1852 MediaQuery.of(context).size.width,
1853 child: GestureDetector(
1854 onTap: () {
1855 Navigator.push(context,
1856 MaterialPageRoute(
1857 builder: (context) {
1858 return DaftarEkskul();
1859 }));
1860 },
1861 child: Card(
1862 child: ListView.separated(
1863 shrinkWrap: true,
1864 separatorBuilder:
1865 (context, index) {
1866 return Divider(
1867 color: Colors.grey,
1868 );
1869 },
1870 physics:
1871 NeverScrollableScrollPhysics(),
1872 itemCount: snapshot.data.length,
1873 itemBuilder:
1874 (BuildContext context,
1875 int index) {
1876 return IntrinsicHeight(
1877 child: Row(
1878 mainAxisAlignment:
1879 MainAxisAlignment
1880 .center,
1881 children: <Widget>[
1882 Expanded(
1883 child: ListTile(
1884 title: Text(
1885 snapshot
1886 .data[index]
1887 .namaEkskul,
1888 style: new TextStyle(
1889 fontSize:
1890 18.0),
1891 textAlign:
1892 TextAlign
1893 .center,
1894 ),
1895 subtitle: Text(
1896 snapshot.data[index].ekskulSaya ==
1897 "ya"
1898 ? jenisLogin ==
1899 's'
1900 ? "Mengikuti"
1901 : "Mengajar"
1902 : "",
1903 style: new TextStyle(
1904 fontSize:
1905 12.0,
1906 color: Colors
1907 .blue),
1908 textAlign:
1909 TextAlign
1910 .center,
1911 )),
1912 ),
1913 VerticalDivider(
1914 color: Colors.grey,
1915 ),
1916 Expanded(
1917 child: Column(
1918 mainAxisAlignment:
1919 MainAxisAlignment
1920 .center,
1921 children: <Widget>[
1922 Text(
1923 snapshot
1924 .data[
1925 index]
1926 .hari +
1927 " " +
1928 snapshot
1929 .data[
1930 index]
1931 .jam,
1932 style: TextStyle(
1933 fontSize:
1934 12.0)),
1935 Text(
1936 snapshot
1937 .data[index]
1938 .namaGuru,
1939 style: TextStyle(
1940 fontSize:
1941 12.0,
1942 color: Colors
1943 .grey))
1944 ],
1945 ))
1946 ],
1947 ),
1948 );
1949 },
1950 ),
1951 )),
1952 ),
1953 )
1954 ]));
1955
1956 return _ekskul;
1957 }
1958 break;
1959 }
1960 });
1961 }
1962 });
1963
1964 final _dashboard =
1965 BlocBuilder<SubscribeBloc, SubscribeState>(builder: (context, state) {
1966 if (state is Loading) {
1967 return Container(
1968 height: 200.0,
1969 width: MediaQuery.of(context).size.width,
1970 color: Colors.white,
1971 alignment: Alignment.bottomCenter,
1972 child: Center(child: CircularProgressIndicator()));
1973 } else {
1974 _subscribeLoaded = state as SubscribeLoaded;
1975 return Container(
1976 padding: EdgeInsets.all(8.0),
1977 child: ListView(
1978 children: <Widget>[
1979 runningText,
1980 eventInfo,
1981 SizedBox(
1982 height: 20.0,
1983 ),
1984 absenInfo,
1985 SizedBox(
1986 height: 20.0,
1987 ),
1988 jenisLogin == 's' ? iuran : Container(),
1989 SizedBox(
1990 height: 20.0,
1991 ),
1992 pengumuman,
1993 SizedBox(
1994 height: 20.0,
1995 ),
1996 MenuList(
1997 onPurchase: (int paket) {
1998 _showDialog(paket);
1999 },
2000 subscribeLoaded: _subscribeLoaded,
2001 modelBisnis: sharedPreferences.getString(Strings.modelBisnis),
2002 eTest: sharedPreferences.getString(Strings.eTest),
2003 eLearning: sharedPreferences.getString(Strings.eLearning),
2004 beranda: beranda,
2005 ddAktif: ddAktif,
2006 dataTahunAjaran: dataTahunAjaran,
2007 ),
2008 berita,
2009 SizedBox(
2010 height: 20.0,
2011 ),
2012 ekskul,
2013 ],
2014 ),
2015 );
2016 }
2017 });
2018
2019 Future<bool> onWillPop() {
2020 DateTime now = DateTime.now();
2021 if (currentBackPressTime == null ||
2022 now.difference(currentBackPressTime) > Duration(seconds: 2)) {
2023 currentBackPressTime = now;
2024 showToast("Tekan Sekali Lagi untuk Keluar");
2025 return Future.value(false);
2026 }
2027 return Future.value(true);
2028 }
2029
2030 final _appBar = CupertinoNavigationBar(
2031 leading: GestureDetector(
2032 onTap: () {
2033 Navigator.pushNamed(context, '/tentang');
2034 },
2035 child:
2036 Container(width: 35.0, height: 35.0, child: Image.memory(bytes))),
2037 middle: Container(
2038 height: 30.0,
2039 child: Image.asset("assets/images/sistesi_font_small.png")),
2040 trailing: beranda == 'Sederhana'
2041 ? null
2042 : Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
2043 Stack(children: <Widget>[
2044 IconButton(
2045 icon: Icon(Icons.chat_bubble_outline),
2046 color: Colors.lightBlue,
2047 onPressed: () {
2048 Navigator.push(
2049 context,
2050 MaterialPageRoute(
2051 builder: (context) =>
2052 Obrolan(jenisLogin: jenisLogin)));
2053 },
2054 ),
2055 spChat != null && spChat.length != 0
2056 ? new Positioned(
2057 right: 11,
2058 top: 11,
2059 child: new Container(
2060 padding: EdgeInsets.all(2),
2061 decoration: new BoxDecoration(
2062 color: Colors.red,
2063 borderRadius: BorderRadius.circular(6),
2064 ),
2065 constraints: BoxConstraints(
2066 minWidth: 14,
2067 minHeight: 14,
2068 ),
2069 child: Text(
2070 "${spChat.length}",
2071 style: TextStyle(
2072 color: Colors.white,
2073 fontSize: 8,
2074 ),
2075 textAlign: TextAlign.center,
2076 ),
2077 ),
2078 )
2079 : new Container(),
2080 ]),
2081 Stack(children: <Widget>[
2082 IconButton(
2083 icon: Icon(Icons.notifications_none),
2084 color: Colors.lightBlue,
2085 onPressed: () {
2086 Navigator.pushNamed(context, '/notifikasi');
2087 },
2088 ),
2089 totalNotif != 0
2090 ? new Positioned(
2091 right: 11,
2092 top: 11,
2093 child: new Container(
2094 padding: EdgeInsets.all(2),
2095 decoration: new BoxDecoration(
2096 color: Colors.red,
2097 borderRadius: BorderRadius.circular(6),
2098 ),
2099 constraints: BoxConstraints(
2100 minWidth: 14,
2101 minHeight: 14,
2102 ),
2103 child: Text(
2104 '$totalNotif',
2105 style: TextStyle(
2106 color: Colors.white,
2107 fontSize: 8,
2108 ),
2109 textAlign: TextAlign.center,
2110 ),
2111 ),
2112 )
2113 : new Container(),
2114 ]),
2115 ]),
2116 );
2117
2118 return Scaffold(
2119 key: scaffoldKey,
2120 appBar: _appBar,
2121 body: BlocProvider<SubscribeBloc>(
2122 builder: (context) => SubscribeBloc()..add(CheckSubscribe()),
2123 child: WillPopScope(
2124 child: BlocBuilder<SubscribeBloc, SubscribeState>(
2125 builder: (context, state) {
2126 if (state is Loading) {
2127 return Container(
2128 height: 200.0,
2129 width: MediaQuery.of(context).size.width,
2130 color: Colors.white,
2131 alignment: Alignment.bottomCenter,
2132 child: Center(child: CircularProgressIndicator()));
2133 } else {
2134 _subscribeLoaded = state as SubscribeLoaded;
2135 return ModalProgressHUD(
2136 child: _selectedPage == 0
2137 ? (beranda == 'Sederhana'
2138 ? MenuList(
2139 subscribeLoaded: _subscribeLoaded,
2140 eTest: sharedPreferences.getString(Strings.eTest),
2141 eLearning: sharedPreferences
2142 .getString(Strings.eLearning),
2143 modelBisnis: sharedPreferences
2144 .getString(Strings.modelBisnis),
2145 beranda: beranda,
2146 ddAktif: ddAktif,
2147 dataTahunAjaran: dataTahunAjaran,
2148 )
2149 : _dashboard)
2150 : Profile(),
2151 inAsyncCall: _saving,
2152 );
2153 }
2154 }),
2155 onWillPop: onWillPop),
2156 ),
2157 bottomNavigationBar: BottomNavigationBar(
2158 currentIndex: _selectedPage,
2159 onTap: (int index) {
2160 setState(() {
2161 print("ini beranda");
2162 print(beranda);
2163 _selectedPage = index;
2164 });
2165 },
2166 items: [
2167 BottomNavigationBarItem(
2168 icon: Icon(CupertinoIcons.home),
2169 title: Text("Beranda"),
2170 ),
2171 BottomNavigationBarItem(
2172 icon: Icon(CupertinoIcons.profile_circled), title: Text("Akun"))
2173 ],
2174 ),
2175 );
2176 }
2177}