Advertisement
febu19

Untitled

Dec 3rd, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 48.00 KB | None | 0 0
  1. import 'dart:async';
  2. import 'dart:io';
  3.  
  4. import 'package:add_2_calendar/add_2_calendar.dart';
  5. import 'package:dio/dio.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_calendar_carousel/classes/event.dart';
  8. import 'package:flutter_calendar_carousel/classes/event_list.dart';
  9. import 'package:flutter_local_notifications/flutter_local_notifications.dart';
  10. import 'package:geolocator/geolocator.dart';
  11. import 'package:rflutter_alert/rflutter_alert.dart';
  12. import 'package:rohisapp/endpoint/api.dart';
  13. import 'package:rohisapp/model/event_model.dart';
  14. import 'package:rohisapp/notification/firebase_notification_handler.dart';
  15. import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart';
  16. import 'package:intl/intl.dart' show DateFormat;
  17. import 'package:shared_preferences/shared_preferences.dart';
  18. import 'package:permission_handler/permission_handler.dart';
  19. import 'package:device_info/device_info.dart';
  20. import 'package:html_unescape/html_unescape.dart';
  21. import 'package:wc_flutter_share/wc_flutter_share.dart';
  22.  
  23. class KalenderKegiatan extends StatefulWidget {
  24.   KalenderKegiatan(this.deviceid);
  25.   final String deviceid;
  26.   @override
  27.   _KalenderKegiatanState createState() => _KalenderKegiatanState();
  28. }
  29.  
  30. class _KalenderKegiatanState extends State<KalenderKegiatan>
  31.     with SingleTickerProviderStateMixin {
  32.   FlutterLocalNotificationsPlugin localNotificationsPlugin =
  33.       FlutterLocalNotificationsPlugin();
  34.   initializeNotifications() async {
  35.     var initializeAndroid = AndroidInitializationSettings('ic_launcher');
  36.     var initializeIOS = IOSInitializationSettings();
  37.     var initSettings = InitializationSettings(initializeAndroid, initializeIOS);
  38.     await localNotificationsPlugin.initialize(initSettings);
  39.     var pendingNotificationRequests =
  40.         await localNotificationsPlugin.pendingNotificationRequests();
  41.     print('pendingNotificationRequests ' +
  42.         pendingNotificationRequests.length.toString());
  43.   }
  44.  
  45.   int jumartikel = 0;
  46.   Timer timer;
  47.   String timeText = '';
  48.   String statusText = '';
  49.   int jam = 0;
  50.   int menit = 0;
  51.   int detik = 0;
  52.   Stopwatch stopwatch = Stopwatch();
  53.   static const delay = Duration(microseconds: 1);
  54.   String m = '';
  55.   String y = '';
  56.  
  57.   var begin = 0.0;
  58.   Animation<double> heightSize;
  59.   AnimationController controller;
  60.   void updateClock() {
  61.     final duration = Duration(hours: jam, minutes: menit, seconds: detik);
  62.  
  63.     // if time is up, stop the timer
  64.     if (stopwatch.elapsed.inMilliseconds == duration.inMilliseconds) {
  65.       print('--finished Timer Page--');
  66.       stopwatch.stop();
  67.       stopwatch.reset();
  68.       controller.stop(canceled: false);
  69.       setState(() {
  70.         statusText = 'Finished';
  71.         // buttonText = "Restart";
  72.       });
  73.       return;
  74.     } else {
  75.       statusText = '';
  76.     }
  77.  
  78.     final millisecondsRemaining =
  79.         duration.inMilliseconds - stopwatch.elapsed.inMilliseconds;
  80.     final hoursRemaining =
  81.         ((millisecondsRemaining / (1000 * 60 * 60)) % 24).toInt();
  82.     final minutesRemaining =
  83.         ((millisecondsRemaining / (1000 * 60)) % 60).toInt();
  84.     final secondsRemaining = ((millisecondsRemaining / 1000) % 60).toInt();
  85.  
  86.     setState(() {
  87.       timeText = '${hoursRemaining.toString().padLeft(2, '0')}:'
  88.           '${minutesRemaining.toString().padLeft(2, '0')}:'
  89.           '${secondsRemaining.toString().padLeft(2, '0')}';
  90.     });
  91.  
  92.     if (stopwatch.isRunning) {
  93.       setState(() {});
  94.     } else if (stopwatch.elapsed.inSeconds == 0) {
  95.       setState(() {
  96.         timeText = '${jam.toString().padLeft(2, "0")}:'
  97.             '${menit.toString().padLeft(2, '0')}:'
  98.             '${detik.toString().padLeft(2, '0')}';
  99.       });
  100.     } else {
  101.       setState(() {});
  102.     }
  103.   }
  104.  
  105.   Position positions;
  106.   double lat;
  107.   double long;
  108.   static double _minHeight = 130, _maxHeight = 290;
  109.   Offset _offset = Offset(0, _minHeight);
  110.   DateTime _currentDate = DateTime.now();
  111.   DateTime _currentDate2 = DateTime.now();
  112.   DateTime _targetDateTime = DateTime.now();
  113.   String _currentMonth = '';
  114.   bool content = false;
  115.   SharedPreferences sharedPreferences;
  116.   bool islogin = false;
  117.   var email = "";
  118.   var userid = "";
  119.   var full_name = "";
  120.   var kota = "";
  121.   var lokasiAdzan = "";
  122.   var tglHijriah = "";
  123.   var tglMasehi = "";
  124.   var deviceid = "";
  125.   String timerString = '';
  126.   bool _isVisible = true;
  127.   String firstHalf;
  128.   String secondHalf;
  129.  
  130.   bool flag = true;
  131.   static Widget _eventIcon = new Container(
  132.     decoration: new BoxDecoration(
  133.         color: Colors.white,
  134.         borderRadius: BorderRadius.all(Radius.circular(1000)),
  135.         border: Border.all(color: Colors.blue, width: 2.0)),
  136.     child: new Icon(
  137.       Icons.check_circle,
  138.       color: Colors.blue,
  139.     ),
  140.   );
  141.  
  142.   static Widget _holidayIcon = new Container(
  143.     decoration: new BoxDecoration(
  144.         color: Colors.white,
  145.         borderRadius: BorderRadius.all(Radius.circular(1000)),
  146.         border: Border.all(color: Colors.red, width: 2.0)),
  147.     child: new Icon(
  148.       Icons.home,
  149.       color: Colors.red,
  150.     ),
  151.   );
  152.  
  153.   EventList<Event> _markedDateMap = EventList<Event>();
  154.  
  155.   CalendarCarousel _calendarCarouselNoHeader;
  156.  
  157.   void handleNewDate(date) {
  158.     print("handleNewDate ${date}");
  159.   }
  160.  
  161.   getDeviceDetails() async {
  162.     String deviceName;
  163.     String deviceVersion;
  164.     String identifier;
  165.     final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
  166.     try {
  167.       if (Platform.isAndroid) {
  168.         var build = await deviceInfoPlugin.androidInfo;
  169.         deviceName = build.model;
  170.         deviceVersion = build.version.toString();
  171.         identifier = build.androidId; //UUID for Android
  172.         print('identifier ' + identifier);
  173.       } else if (Platform.isIOS) {
  174.         var data = await deviceInfoPlugin.iosInfo;
  175.         deviceName = data.name;
  176.         deviceVersion = data.systemVersion;
  177.         identifier = data.identifierForVendor; //UUID for iOS
  178.       }
  179.       setState(() {
  180.         deviceid = identifier;
  181.       });
  182.       _checkJadwalSholat(deviceid);
  183.       String url = new Api().url;
  184.       var dio = new Dio();
  185.       await dio.post(
  186.         url + "index.php/api/Device_info",
  187.         data: {
  188.           "device_id": identifier,
  189.           "deviceName": deviceName,
  190.         },
  191.         options:
  192.             new Options(contentType: ContentType.parse("application/json")),
  193.       );
  194.     } catch (e) {
  195.       print('Failed to get platform version');
  196.     }
  197.  
  198.     return [deviceName, deviceVersion, identifier];
  199.   }
  200.  
  201.   _checkJadwalSholat(identifier) async {
  202.     var now = new DateTime.now();
  203.     var formatter = new DateFormat('MM');
  204.     var dates = formatter.format(now);
  205.  
  206.     String url = new Api().url;
  207.     Response response;
  208.     var dio = new Dio();
  209.     try {
  210.       // for (int i = 1; i <= 7; i++) {
  211.       response = await dio
  212.           .get(url + "index.php/api/CheckJadwalSholat?device_id=" + identifier);
  213.       final json = response.data;
  214.       if (response.statusCode == 200) {
  215.         // print(json.toString());
  216.         lokasiAdzan = json.toString();
  217.       } else {
  218.         throw Exception('Failed to load');
  219.       }
  220.     } on DioError catch (e) {
  221.       print("GAGAL");
  222.  
  223.       if (e.response != null) {
  224.         print(e.response.data);
  225.         print(e.response.headers);
  226.         print(e.response.request);
  227.       } else {
  228.         print(e.request);
  229.         print(e.message);
  230.       }
  231.     }
  232.   }
  233.  
  234.   Widget _boxDate(kategori, dates) {
  235.     print('kategori ' + kategori);
  236.     if (kategori == '0') {
  237.       return new Container(
  238.           width: 50.0,
  239.           height: 50.0,
  240.           padding: EdgeInsets.all(15.0),
  241.           decoration: BoxDecoration(
  242.             color: Colors.green,
  243.             borderRadius: BorderRadius.all(Radius.circular(10.0)),
  244.             boxShadow: <BoxShadow>[
  245.               new BoxShadow(
  246.                 color: Colors.black12,
  247.                 blurRadius: 10.0,
  248.                 offset: new Offset(0.0, 10.0),
  249.               ),
  250.             ],
  251.           ),
  252.           child: Text(dates.toString(),
  253.               style: TextStyle(
  254.                 fontSize: 14.0,
  255.                 fontWeight: FontWeight.bold,
  256.               )));
  257.     } else if (kategori == '1') {
  258.       return new Container(
  259.           width: 50.0,
  260.           height: 50.0,
  261.           padding: EdgeInsets.all(15.0),
  262.           decoration: BoxDecoration(
  263.             color: Colors.red,
  264.             borderRadius: BorderRadius.all(Radius.circular(10.0)),
  265.             boxShadow: <BoxShadow>[
  266.               new BoxShadow(
  267.                 color: Colors.black12,
  268.                 blurRadius: 10.0,
  269.                 offset: new Offset(0.0, 10.0),
  270.               ),
  271.             ],
  272.           ),
  273.           child: Text(dates.toString(),
  274.               style: TextStyle(
  275.                 fontSize: 14.0,
  276.                 fontWeight: FontWeight.bold,
  277.               )));
  278.     } else {
  279.       return new Container(
  280.           width: 50.0,
  281.           height: 50.0,
  282.           padding: EdgeInsets.all(15.0),
  283.           decoration: BoxDecoration(
  284.             color: Colors.green,
  285.             borderRadius: BorderRadius.all(Radius.circular(10.0)),
  286.             boxShadow: <BoxShadow>[
  287.               new BoxShadow(
  288.                 color: Colors.black12,
  289.                 blurRadius: 10.0,
  290.                 offset: new Offset(0.0, 10.0),
  291.               ),
  292.             ],
  293.           ),
  294.           child: Text(dates.toString(),
  295.               style: TextStyle(
  296.                 fontSize: 14.0,
  297.                 fontWeight: FontWeight.bold,
  298.               )));
  299.     }
  300.   }
  301.  
  302.   Future<void> _scheduleNotifications(id, title, desc, tanggal) async {
  303.     var scheduledNotificationDateTime = tanggal.add(Duration(seconds: 5));
  304.     print('scheduledNotificationDateTime ' +
  305.         scheduledNotificationDateTime.toString());
  306.  
  307.     var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
  308.         'your other channel id',
  309.         'your other channel name',
  310.         'your other channel description');
  311.  
  312.     var iOSPlatformChannelSpecifics = IOSNotificationDetails();
  313.  
  314.     var platformChannelSpecifics = NotificationDetails(
  315.         androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
  316.     await localNotificationsPlugin.schedule(id, title, desc,
  317.         scheduledNotificationDateTime, platformChannelSpecifics);
  318.   }
  319.  
  320.   Widget _shareJadwal(title, date, jam, ustadz, kategori) {
  321.     if (kategori == '0') {
  322.       return Center(
  323.           child: InkWell(
  324.         onTap: () async {
  325.           await WcFlutterShare.share(
  326.               sharePopupTitle: 'Share Jadwal Kajian',
  327.               subject: title,
  328.               text: 'Jadwal Kajian \nTema : ' +
  329.                   title +
  330.                   '\nTanggal : ' +
  331.                   date.toString() +
  332.                   '\nJam : ' +
  333.                   jam.toString() +
  334.                   '\nPengisi :' +
  335.                   ustadz,
  336.               mimeType: 'text/plain');
  337.         },
  338.         child: Icon(
  339.           Icons.share,
  340.           color: Colors.black,
  341.         ),
  342.       ));
  343.     } else if (kategori == '0') {
  344.       return Center(
  345.           child: InkWell(
  346.         onTap: () async {
  347.           await WcFlutterShare.share(
  348.               sharePopupTitle: 'Share Jadwal Kajian',
  349.               subject: title,
  350.               text: 'Hari Libur',
  351.               mimeType: 'text/plain');
  352.         },
  353.         child: Icon(
  354.           Icons.share,
  355.           color: Colors.black,
  356.         ),
  357.       ));
  358.     } else {
  359.       return Center(
  360.           child: InkWell(
  361.         onTap: () async {
  362.           await WcFlutterShare.share(
  363.               sharePopupTitle: 'Share Jadwal Kajian',
  364.               subject: title,
  365.               text: 'Jadwal Kajian \nTema : ' +
  366.                   title +
  367.                   '\nTanggal : ' +
  368.                   date.toString() +
  369.                   '\nJam : ' +
  370.                   jam.toString() +
  371.                   '\nPengisi :' +
  372.                   ustadz,
  373.               mimeType: 'text/plain');
  374.         },
  375.         child: Icon(
  376.           Icons.share,
  377.           color: Colors.black,
  378.         ),
  379.       ));
  380.     }
  381.   }
  382.  
  383.   _listEvents(EventModel event) {
  384.     if (event.description_event.length > 30) {
  385.       firstHalf = event.description_event.substring(0, 30);
  386.       secondHalf =
  387.           event.description_event.substring(30, event.description_event.length);
  388.     } else {
  389.       firstHalf = event.description_event;
  390.       secondHalf = "";
  391.     }
  392.     var now = event.date;
  393.     var formatter = new DateFormat('dd');
  394.     var dates = formatter.format(now);
  395.  
  396.     var end = event.dates;
  397.     var formatterenddate = new DateFormat('yyyy-MM-dd hh:mm:ss');
  398.     var enddate = formatterenddate.format(end);
  399.  
  400.     var formatter2 = new DateFormat('dd-MM-yyyy');
  401.     var dates2 = formatter2.format(now);
  402.     var dates3 = formatter2.format(end);
  403.  
  404.     var formatEvent = new DateFormat('yyyy-MM-dd hh:mm:ss');
  405.     var datesEvent = formatEvent.format(now);
  406.     var formatter3 = new DateFormat('hh:mm');
  407.     var jam = formatter3.format(now);
  408.     var lokasi = event.lokasi;
  409.     Events events = Events(
  410.       title: event.title,
  411.       description: jam.toString() + ' - ' + event.description_event,
  412.       location: 'Masjid' + DateTime.now().toString(),
  413.       startDate: DateTime.parse(datesEvent),
  414.       endDate: DateTime.parse(enddate),
  415.       allDay: false,
  416.     );
  417.     return Padding(
  418.       padding: const EdgeInsets.only(top: 8.0),
  419.       child: Align(
  420.         child: Container(
  421.             padding: EdgeInsets.all(15.0),
  422.             decoration: BoxDecoration(
  423.               color: Colors.white,
  424.               borderRadius: BorderRadius.all(Radius.circular(10.0)),
  425.               boxShadow: <BoxShadow>[
  426.                 new BoxShadow(
  427.                   color: Colors.black12,
  428.                   blurRadius: 10.0,
  429.                   offset: new Offset(0.0, 10.0),
  430.                 ),
  431.               ],
  432.             ),
  433.             child: Column(
  434.               children: <Widget>[
  435.                 Row(
  436.                   children: <Widget>[
  437.                     _boxDate(event.kategori, dates),
  438.                     Padding(
  439.                       padding: EdgeInsets.only(left: 10.0),
  440.                     ),
  441.  
  442.                     Expanded(
  443.                         flex: 6,
  444.                         child: Column(
  445.                           children: <Widget>[
  446.                             Row(
  447.                               children: <Widget>[
  448.                                 Text('Tema :' + event.title,
  449.                                     style: TextStyle(fontSize: 11.0)),
  450.                               ],
  451.                             ),
  452.                             Row(
  453.                               children: <Widget>[
  454.                                 secondHalf.isEmpty
  455.                                     ? new Text(firstHalf,
  456.                                         style: TextStyle(fontSize: 11.0))
  457.                                     : new Column(
  458.                                         children: <Widget>[
  459.                                           new Text(
  460.                                               flag
  461.                                                   ? (firstHalf + "...")
  462.                                                   : (firstHalf + secondHalf),
  463.                                               style: TextStyle(fontSize: 11.0)),
  464.                                           new InkWell(
  465.                                             child: new Row(
  466.                                               mainAxisAlignment:
  467.                                                   MainAxisAlignment.end,
  468.                                               children: <Widget>[
  469.                                                 new Text(
  470.                                                   flag
  471.                                                       ? "View Detail"
  472.                                                       : "show less",
  473.                                                   style: new TextStyle(
  474.                                                       color: Colors.blue),
  475.                                                 ),
  476.                                               ],
  477.                                             ),
  478.                                             onTap: () {
  479.                                               _viewEven(event);
  480.                                               // setState(() {
  481.                                               //   flag = !flag;
  482.                                               // });
  483.                                             },
  484.                                           ),
  485.                                         ],
  486.                                       ),
  487.                                 // Text(
  488.                                 //   event.description_event,
  489.                                 //   style: TextStyle(fontSize: 11.0),
  490.                                 // ),
  491.                               ],
  492.                             ),
  493.                             Row(
  494.                               children: <Widget>[
  495.                                 Text(
  496.                                   'Pengisi : ' + event.ustadz,
  497.                                   style: TextStyle(fontSize: 11.0),
  498.                                 ),
  499.                               ],
  500.                             ),
  501.                             Row(
  502.                               children: <Widget>[
  503.                                 Column(
  504.                                   children: <Widget>[
  505.                                     Text('Tanggal : ' + dates2 + ' - ' + dates3,
  506.                                         style: TextStyle(fontSize: 11.0)),
  507.                                   ],
  508.                                 ),
  509.                               ],
  510.                             ),
  511.                             Row(
  512.                               children: <Widget>[
  513.                                 Text(
  514.                                   'Jam : ' + jam,
  515.                                   style: TextStyle(fontSize: 11.0),
  516.                                 ),
  517.                               ],
  518.                             ),
  519.                             Row(
  520.                               children: <Widget>[
  521.                                 Text(
  522.                                   'Lokasi : ' + lokasi,
  523.                                   style: TextStyle(fontSize: 11.0),
  524.                                 ),
  525.                               ],
  526.                             ),
  527.                           ],
  528.                         )),
  529.                     // Expanded(
  530.                     //   flex: 2,
  531.                     //   child:
  532.                     _shareJadwal(
  533.                         event.title, dates2, jam, event.ustadz, event.kategori),
  534.  
  535.                     Padding(
  536.                       padding: EdgeInsets.only(left: 10.0),
  537.                     ),
  538.  
  539.                     Center(
  540.                         child: InkWell(
  541.                       onTap: () async {
  542.                         print('aaa' + event.dates.toString());
  543.                         await _scheduleNotifications(
  544.                             int.parse(event.id_event),
  545.                             event.title + ' - ' + event.description_event,
  546.                             'tanggal ' + event.date.toString(),
  547.                             event.dates);
  548.                       },
  549.                       child: Icon(
  550.                         Icons.notifications,
  551.                         color: Colors.black,
  552.                       ),
  553.                     )),
  554.                     Padding(
  555.                       padding: EdgeInsets.only(left: 10.0),
  556.                     ),
  557.                     Center(
  558.                         child: InkWell(
  559.                       onTap: () async {
  560.                         Add2Calendar.addEvent2Cal(events).then((success) {
  561.                           print('sukses');
  562.                         });
  563.                       },
  564.                       child: Icon(
  565.                         Icons.calendar_today,
  566.                         color: Colors.black,
  567.                       ),
  568.                     )),
  569.                     // )
  570.                   ],
  571.                 ),
  572.               ],
  573.             )),
  574.       ),
  575.     );
  576.   }
  577.  
  578.   @override
  579.   void initState() {
  580.     new FirebaseNotifications().setUpFirebase();
  581.  
  582.     super.initState();
  583.     (() async {
  584.       await _event();
  585.       await _hariLibur();
  586.       await getDeviceDetails();
  587.       await fetchEvent();
  588.       sharedPreferences = await SharedPreferences.getInstance();
  589.       setState(() {
  590.         if (sharedPreferences.getBool("isLogin") != null) {
  591.           islogin = sharedPreferences.getBool("isLogin");
  592.           email = sharedPreferences.getString("email");
  593.           full_name = sharedPreferences.getString("full_name");
  594.           userid = sharedPreferences.getString("userid");
  595.         } else {
  596.           full_name = "";
  597.         }
  598.       });
  599.     })();
  600.     // _askPermission();
  601.   }
  602.  
  603.   @override
  604.   void dispose() {
  605.     controller.dispose();
  606.     stopwatch.stop();
  607.     timer.cancel();
  608.     super.dispose();
  609.   }
  610.  
  611.   _event() async {
  612.     String url = new Api().url;
  613.     Response res;
  614.     var dio = new Dio();
  615.     try {
  616.       res = await dio.get(url + "index.php/api/Jadwal_kajian");
  617.  
  618.       final dataEvents = res.data;
  619.       if (res.statusCode == 200) {
  620.         for (int i = 0; i < int.parse(dataEvents[0]['total']); i++) {
  621.           var now = DateTime.parse(dataEvents[i]['date']);
  622.           var end = DateTime.parse(dataEvents[i]['dates']);
  623.           var formatter = new DateFormat('dd/MM/yyyy');
  624.           var dates = formatter.format(now);
  625.           var datesend = formatter.format(end);
  626.           var formatterJam = new DateFormat('HH:mm');
  627.           var jam = formatterJam.format(now);
  628.           var unescape = new HtmlUnescape();
  629.           var text = unescape.convert(dataEvents[i]['ustadz']);
  630.           var kat = unescape.convert(dataEvents[i]['kategori']);
  631.           var description_event =
  632.               unescape.convert(dataEvents[i]['description_event']);
  633.           _markedDateMap.add(
  634.             new DateTime(
  635.                 int.parse(dataEvents[i]['eventyear']),
  636.                 int.parse(dataEvents[i]['eventmonth']),
  637.                 int.parse(dataEvents[i]['eventday'])),
  638.             new Event(
  639.               date: new DateTime(
  640.                   int.parse(dataEvents[i]['eventyear']),
  641.                   int.parse(dataEvents[i]['eventmonth']),
  642.                   int.parse(dataEvents[i]['eventday'])),
  643.               title: dataEvents[i]['title'] +
  644.                   '-' +
  645.                   dates +
  646.                   ' s/d ' +
  647.                   datesend +
  648.                   '-' +
  649.                   jam +
  650.                   '-' +
  651.                   text +
  652.                   '*' +
  653.                   kat +
  654.                   '*' +
  655.                   description_event,
  656.               icon: _eventIcon,
  657.             ),
  658.           );
  659.         }
  660.       } else {
  661.         throw Exception('Failed to load');
  662.       }
  663.     } on DioError catch (e) {
  664.       print("GAGAL");
  665.  
  666.       if (e.response != null) {
  667.         print(e.response.data);
  668.         print(e.response.headers);
  669.         print(e.response.request);
  670.       } else {
  671.         print(e.request);
  672.         print(e.message);
  673.       }
  674.     }
  675.   }
  676.  
  677.   _hariLibur() async {
  678.     String url = new Api().url;
  679.     Response res;
  680.     var dio = new Dio();
  681.     try {
  682.       res = await dio.get(url + "index.php/api/Jadwal_kajian/harilibur");
  683.  
  684.       final dataEvents = res.data;
  685.       if (res.statusCode == 200) {
  686.         for (int i = 0; i < int.parse(dataEvents[0]['total']); i++) {
  687.           var now = DateTime.parse(dataEvents[i]['date']);
  688.           var end = DateTime.parse(dataEvents[i]['dates']);
  689.           var formatter = new DateFormat('dd/MM/yyyy');
  690.           var dates = formatter.format(now);
  691.           var datesend = formatter.format(end);
  692.           var formatterJam = new DateFormat('HH:mm');
  693.           var jam = formatterJam.format(now);
  694.           var unescape = new HtmlUnescape();
  695.           var text = unescape.convert(dataEvents[i]['ustadz']);
  696.           var kat = unescape.convert(dataEvents[i]['kategori']);
  697.           var description_event =
  698.               unescape.convert(dataEvents[i]['description_event']);
  699.  
  700.           _markedDateMap.add(
  701.             new DateTime(
  702.                 int.parse(dataEvents[i]['eventyear']),
  703.                 int.parse(dataEvents[i]['eventmonth']),
  704.                 int.parse(dataEvents[i]['eventday'])),
  705.             new Event(
  706.               date: new DateTime(
  707.                   int.parse(dataEvents[i]['eventyear']),
  708.                   int.parse(dataEvents[i]['eventmonth']),
  709.                   int.parse(dataEvents[i]['eventday'])),
  710.               title: dataEvents[i]['title'] +
  711.                   '-' +
  712.                   dates +
  713.                   ' s/d ' +
  714.                   datesend +
  715.                   '-' +
  716.                   jam +
  717.                   '-' +
  718.                   text +
  719.                   '*' +
  720.                   kat +
  721.                   '*' +
  722.                   description_event,
  723.               icon: _holidayIcon,
  724.             ),
  725.           );
  726.         }
  727.       } else {
  728.         throw Exception('Failed to load');
  729.       }
  730.     } on DioError catch (e) {
  731.       print("GAGAL");
  732.  
  733.       if (e.response != null) {
  734.         print(e.response.data);
  735.         print(e.response.headers);
  736.         print(e.response.request);
  737.       } else {
  738.         print(e.request);
  739.         print(e.message);
  740.       }
  741.     }
  742.   }
  743.  
  744.   _viewEven(EventModel ev) async {
  745.     var titles = "";
  746.     var judul = "";
  747.     var newtgl = "";
  748.     var jam = "";
  749.     var ustadz = "";
  750.     var tgl = "";
  751.     var lokasi = "";
  752.     if (ev.kategori == '1') {
  753.       titles = 'Hari Libur';
  754.       judul = '';
  755.       tgl = '';
  756.       newtgl = ev.date.toString();
  757.       jam = '';
  758.       ustadz = '';
  759.       lokasi = '';
  760.     } else {
  761.       judul = 'Tema : ' + ev.title.toString();
  762.       tgl = ev.date.toString();
  763.       newtgl = 'Tanggal : ' + ev.dates.toString();
  764.       jam = 'Jam : ' + ev.date.toString();
  765.       ustadz = 'Pengisi : ' + ev.ustadz.toString();
  766.       lokasi = 'Lokasi : ' + ev.lokasi.toString();
  767.       titles = 'Detail';
  768.     }
  769.     double c_width = MediaQuery.of(context).size.width * 0.8;
  770.     showDialog(
  771.       context: context,
  772.       builder: (BuildContext context) {
  773.         return AlertDialog(
  774.           title: new Text(titles),
  775.           content: Container(
  776.             width: c_width,
  777.             child: SingleChildScrollView(
  778.               child: Column(
  779.                 children: <Widget>[
  780.                   new Container(
  781.                     padding: const EdgeInsets.all(16.0),
  782.                     width: c_width,
  783.                     child: new Column(
  784.                       children: <Widget>[
  785.                         new Text(ev.description_event,
  786.                             textAlign: TextAlign.left,
  787.                             style: TextStyle(fontSize: 12)),
  788.                       ],
  789.                     ),
  790.                   ),
  791.                   new Padding(
  792.                     padding: EdgeInsets.only(top: 15.0),
  793.                   ),
  794.                   DialogButton(
  795.                     child: Text(
  796.                       "OK",
  797.                       style: TextStyle(color: Colors.white, fontSize: 20),
  798.                     ),
  799.                     onPressed: () {
  800.                       Navigator.of(context).pop();
  801.                     },
  802.                     width: 120,
  803.                   )
  804.                 ],
  805.               ),
  806.             ),
  807.           ),
  808.         );
  809.       },
  810.     );
  811.   }
  812.  
  813.   Future<List<EventModel>> fetchEvent() async {
  814.     try {
  815.       String url = new Api().url;
  816.  
  817.       var notes = List<EventModel>();
  818.  
  819.       Response response;
  820.       response = await Dio().get(url + "index.php/api/Event");
  821.       final json = response.data;
  822.       if (response.statusCode == 200) {
  823.         notes = (json)
  824.             .map<EventModel>((item) => EventModel.fromJson(item))
  825.             .toList();
  826.       } else {
  827.         throw Exception('Failed to load');
  828.       }
  829.       // print("json " + json.toString());
  830.       return new Future.delayed(new Duration(seconds: 1), () {
  831.         return notes.where((i) => i.id_event != null).toList();
  832.       });
  833.     } catch (e) {
  834.       print('Failed to get platform version');
  835.     }
  836.   }
  837.  
  838.   // List<EventModelNext> _listFuture = [];
  839.   Future<List<EventModel>> fetchEventNext() async {
  840.     try {
  841.       String url = new Api().url;
  842.  
  843.       var note = List<EventModel>();
  844.  
  845.       Response response;
  846.       response = await Dio().get(url +
  847.           "index.php/api/EventNext?month=" +
  848.           m.toString() +
  849.           "&year=" +
  850.           y.toString());
  851.  
  852.       final json = response.data;
  853.       if (response.statusCode == 200) {
  854.         note = (json)
  855.             .map<EventModel>((item) => EventModel.fromJson(item))
  856.             .toList();
  857.         print('bisa!!!' + note.toString());
  858.       } else {
  859.         throw Exception('Failed to load');
  860.       }
  861.       // print("json " + json.toString());
  862.       return new Future.delayed(new Duration(seconds: 1), () {
  863.         return note.where((i) => i.id_event != null).toList();
  864.       });
  865.     } catch (e) {
  866.       print('Failed to get platform version');
  867.     }
  868.   }
  869.  
  870.   _listEventsNext(EventModel eventNext) {
  871.     print('eventNext.date - ' + eventNext.date.toString());
  872.     var now = eventNext.date;
  873.     var formatter = new DateFormat('dd');
  874.     var dates = formatter.format(now);
  875.  
  876.     var end = eventNext.dates;
  877.     var formatterenddate = new DateFormat('yyyy-MM-dd hh:mm:ss');
  878.     var enddate = formatterenddate.format(end);
  879.  
  880.     var formatter2 = new DateFormat('dd-MM-yyyy');
  881.     var dates2 = formatter2.format(now);
  882.     var dates3 = formatter2.format(end);
  883.  
  884.     var formatEvent = new DateFormat('yyyy-MM-dd hh:mm:ss');
  885.     var datesEvent = formatEvent.format(now);
  886.     var formatter3 = new DateFormat('hh:mm');
  887.     var jam = formatter3.format(now);
  888.     var lokasi = eventNext.lokasi;
  889.  
  890.     Events events = Events(
  891.       title: eventNext.title,
  892.       description: jam.toString() + ' - ' + eventNext.description_event,
  893.       location: 'Masjid' + DateTime.now().toString(),
  894.       startDate: DateTime.parse(datesEvent),
  895.       endDate: DateTime.parse(enddate),
  896.       allDay: false,
  897.     );
  898.     return Padding(
  899.       padding: const EdgeInsets.only(top: 8.0),
  900.       child: Align(
  901.         child: Container(
  902.             padding: EdgeInsets.all(15.0),
  903.             decoration: BoxDecoration(
  904.               color: Colors.white,
  905.               borderRadius: BorderRadius.all(Radius.circular(10.0)),
  906.               boxShadow: <BoxShadow>[
  907.                 new BoxShadow(
  908.                   color: Colors.black12,
  909.                   blurRadius: 10.0,
  910.                   offset: new Offset(0.0, 10.0),
  911.                 ),
  912.               ],
  913.             ),
  914.             child: Column(
  915.               children: <Widget>[
  916.                 Row(
  917.                   children: <Widget>[
  918.                     _boxDate(eventNext.kategori, dates),
  919.  
  920.                     Padding(
  921.                       padding: EdgeInsets.only(left: 10.0),
  922.                     ),
  923.  
  924.                     Expanded(
  925.                         flex: 6,
  926.                         child: Column(
  927.                           children: <Widget>[
  928.                             Row(
  929.                               children: <Widget>[
  930.                                 Text('Tema :' + eventNext.title,
  931.                                     style: TextStyle(fontSize: 11.0)),
  932.                               ],
  933.                             ),
  934.                             Row(
  935.                               children: <Widget>[
  936.                                 secondHalf.isEmpty
  937.                                     ? new Text(firstHalf,
  938.                                         style: TextStyle(fontSize: 11.0))
  939.                                     : new Column(
  940.                                         children: <Widget>[
  941.                                           new Text(
  942.                                               flag
  943.                                                   ? (firstHalf + "...")
  944.                                                   : (firstHalf + secondHalf),
  945.                                               style: TextStyle(fontSize: 11.0)),
  946.                                           new InkWell(
  947.                                             child: new Row(
  948.                                               mainAxisAlignment:
  949.                                                   MainAxisAlignment.end,
  950.                                               children: <Widget>[
  951.                                                 new Text(
  952.                                                   flag
  953.                                                       ? "VIew Detail"
  954.                                                       : "show less",
  955.                                                   style: new TextStyle(
  956.                                                       color: Colors.blue),
  957.                                                 ),
  958.                                               ],
  959.                                             ),
  960.                                             onTap: () {
  961.                                               _viewEven(eventNext);
  962.                                               // setState(() {
  963.                                               //   flag = !flag;
  964.                                               // });
  965.                                             },
  966.                                           ),
  967.                                         ],
  968.                                       ),
  969.                                 // Text(
  970.                                 //   event.description_event,
  971.                                 //   style: TextStyle(fontSize: 11.0),
  972.                                 // ),
  973.                               ],
  974.                             ),
  975.                             Row(
  976.                               children: <Widget>[
  977.                                 Text(
  978.                                   'Pengisi : ' + eventNext.ustadz,
  979.                                   style: TextStyle(fontSize: 11.0),
  980.                                 ),
  981.                               ],
  982.                             ),
  983.                             Row(
  984.                               children: <Widget>[
  985.                                 Column(
  986.                                   children: <Widget>[
  987.                                     Text('Tanggal : ' + dates2 + ' - ' + dates3,
  988.                                         style: TextStyle(fontSize: 11.0)),
  989.                                   ],
  990.                                 ),
  991.                               ],
  992.                             ),
  993.                             Row(
  994.                               children: <Widget>[
  995.                                 Text(
  996.                                   'Jam : ' + jam,
  997.                                   style: TextStyle(fontSize: 11.0),
  998.                                 ),
  999.                               ],
  1000.                             ),
  1001.                             Row(
  1002.                               children: <Widget>[
  1003.                                 Text(
  1004.                                   'Lokasi : ' + lokasi,
  1005.                                   style: TextStyle(fontSize: 11.0),
  1006.                                 ),
  1007.                               ],
  1008.                             ),
  1009.                           ],
  1010.                         )),
  1011.                     // Expanded(
  1012.                     //   flex: 2,
  1013.                     //   child:
  1014.                     Center(
  1015.                         child: InkWell(
  1016.                       onTap: () async {
  1017.                         await WcFlutterShare.share(
  1018.                             sharePopupTitle: 'Share Jadwal Kajian',
  1019.                             subject: eventNext.title,
  1020.                             text: 'Jadwal Kajian \nTema : ' +
  1021.                                 eventNext.title +
  1022.                                 '\nTanggal : ' +
  1023.                                 dates2.toString() +
  1024.                                 '\nJam : ' +
  1025.                                 jam.toString() +
  1026.                                 '\nPengisi :' +
  1027.                                 eventNext.ustadz,
  1028.                             mimeType: 'text/plain');
  1029.                       },
  1030.                       child: Icon(
  1031.                         Icons.share,
  1032.                         color: Colors.black,
  1033.                       ),
  1034.                     )),
  1035.                     Padding(
  1036.                       padding: EdgeInsets.only(left: 10.0),
  1037.                     ),
  1038.  
  1039.                     Center(
  1040.                         child: InkWell(
  1041.                       onTap: () async {
  1042.                         print('aaa' + eventNext.dates.toString());
  1043.                         await _scheduleNotifications(
  1044.                             int.parse(eventNext.id_event),
  1045.                             eventNext.title +
  1046.                                 ' - ' +
  1047.                                 eventNext.description_event,
  1048.                             'tanggal ' + eventNext.date.toString(),
  1049.                             eventNext.dates);
  1050.                       },
  1051.                       child: Icon(
  1052.                         Icons.notifications,
  1053.                         color: Colors.black,
  1054.                       ),
  1055.                     )),
  1056.                     Padding(
  1057.                       padding: EdgeInsets.only(left: 10.0),
  1058.                     ),
  1059.                     Center(
  1060.                         child: InkWell(
  1061.                       onTap: () async {
  1062.                         Add2Calendar.addEvent2Cal(events).then((success) {
  1063.                           print('sukses');
  1064.                         });
  1065.                       },
  1066.                       child: Icon(
  1067.                         Icons.calendar_today,
  1068.                         color: Colors.black,
  1069.                       ),
  1070.                     )),
  1071.                     // )
  1072.                   ],
  1073.                 ),
  1074.               ],
  1075.             )),
  1076.       ),
  1077.     );
  1078.   }
  1079.  
  1080.   Widget _contentKajian() {
  1081.     if (_isVisible == true) {
  1082.       return Container(
  1083.         width: MediaQuery.of(context).size.width,
  1084.         // decoration: BoxDecoration(
  1085.         //     color: Colors.blueGrey[100]),
  1086.         height: MediaQuery.of(context).size.height,
  1087.  
  1088.         child: new FutureBuilder<List>(
  1089.             future: fetchEvent(),
  1090.             builder: (context, snapshot) {
  1091.               if (snapshot.hasData) {
  1092.                 return new ListView.builder(
  1093.                   shrinkWrap: true,
  1094.                   physics: const NeverScrollableScrollPhysics(),
  1095.                   itemCount: snapshot.data.length,
  1096.                   padding: EdgeInsets.only(top: 4.0),
  1097.                   itemBuilder: (context, index) {
  1098.                     return _listEvents(snapshot.data[index]);
  1099.                   },
  1100.                 );
  1101.               }
  1102.               return Center(
  1103.                 child: SizedBox(
  1104.                     width: 40.0,
  1105.                     height: 40.0,
  1106.                     child: const CircularProgressIndicator()),
  1107.               );
  1108.             }),
  1109.       );
  1110.     } else if (_isVisible == false) {
  1111.       return Container(
  1112.         width: MediaQuery.of(context).size.width,
  1113.         // decoration: BoxDecoration(
  1114.         //     color: Colors.blueGrey[100]),
  1115.         height: MediaQuery.of(context).size.height,
  1116.  
  1117.         child: new FutureBuilder<List>(
  1118.             future: fetchEventNext(),
  1119.             builder: (context, snapshot) {
  1120.               if (snapshot.hasData) {
  1121.                 return new ListView.builder(
  1122.                   shrinkWrap: true,
  1123.                   physics: const NeverScrollableScrollPhysics(),
  1124.                   itemCount: snapshot.data.length,
  1125.                   padding: EdgeInsets.only(top: 4.0),
  1126.                   itemBuilder: (context, index) {
  1127.                     return _listEventsNext(snapshot.data[index]);
  1128.                   },
  1129.                 );
  1130.               }
  1131.               return Center(
  1132.                 child: SizedBox(
  1133.                     width: 40.0,
  1134.                     height: 40.0,
  1135.                     child: const CircularProgressIndicator()),
  1136.               );
  1137.             }),
  1138.       );
  1139.     } else {
  1140.       Container();
  1141.     }
  1142.   }
  1143.  
  1144.   @override
  1145.   Widget build(BuildContext context) {
  1146.     _calendarCarouselNoHeader = CalendarCarousel<Event>(
  1147.       todayBorderColor: Colors.green,
  1148.       onDayPressed: (DateTime date, List<Event> events) {
  1149.         this.setState(() => _currentDate2 = date);
  1150.         // events.forEach((event) => _checkExternal(event.title));
  1151.         print(events[0].title);
  1152.       },
  1153.       weekendTextStyle: TextStyle(
  1154.         color: Colors.red,
  1155.       ),
  1156.       thisMonthDayBorderColor: Colors.grey,
  1157.       weekFormat: false,
  1158.       markedDatesMap: _markedDateMap,
  1159.       height: 310.0,
  1160.       selectedDateTime: _currentDate2,
  1161.         targetDateTime: _targetDateTime,
  1162.       customGridViewPhysics: NeverScrollableScrollPhysics(),
  1163.       markedDateShowIcon: true,
  1164.       markedDateIconMaxShown: 2,
  1165.       markedDateMoreShowTotal:
  1166.           false, // null for not showing hidden events indicator
  1167.       showHeader: false,
  1168.       markedDateIconBuilder: (event) {
  1169.         return event.icon;
  1170.       },
  1171.       todayTextStyle: TextStyle(
  1172.         color: Colors.blue,
  1173.       ),
  1174.       todayButtonColor: Colors.yellow,
  1175.       selectedDayTextStyle: TextStyle(
  1176.         color: Colors.yellow,
  1177.       ),
  1178.       minSelectedDate: _currentDate.subtract(Duration(days: 360)),
  1179.       maxSelectedDate: _currentDate.add(Duration(days: 360)),
  1180.       prevDaysTextStyle: TextStyle(
  1181.         fontSize: 16,
  1182.         color: Colors.pinkAccent,
  1183.       ),
  1184.       inactiveDaysTextStyle: TextStyle(
  1185.         color: Colors.tealAccent,
  1186.         fontSize: 16,
  1187.       ),
  1188.       onCalendarChanged: (DateTime date) {
  1189.         this.setState(() {
  1190.           _targetDateTime = date;
  1191.           _currentMonth = DateFormat.yMMM().format(_targetDateTime);
  1192.         });
  1193.       },
  1194.     );
  1195.     return Scaffold(
  1196.         appBar: AppBar(
  1197.           backgroundColor: Color.fromRGBO(0, 185, 92, 1),
  1198.           title: Center(child: Text("Assalamu'alaikum " + full_name)),
  1199.           elevation: 0,
  1200.         ),
  1201.         body: Stack(
  1202.           alignment: Alignment.bottomCenter,
  1203.           children: <Widget>[
  1204.             new SingleChildScrollView(
  1205.               physics: ScrollPhysics(),
  1206.               child: Container(
  1207.                 decoration: BoxDecoration(color: Colors.blueGrey[100]),
  1208.                 padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 10.0),
  1209.                 child: Column(
  1210.                   children: <Widget>[
  1211.                     Padding(
  1212.                       padding: EdgeInsets.only(bottom: 20.0),
  1213.                     ),
  1214.                     Align(
  1215.                       child: Padding(
  1216.                         padding: EdgeInsets.only(left: 10.0, right: 10.0),
  1217.                         child: Container(
  1218.                             height: 440.0,
  1219.                             decoration: BoxDecoration(
  1220.                               color: Colors.white,
  1221.                               borderRadius:
  1222.                                   BorderRadius.all(Radius.circular(10.0)),
  1223.                               boxShadow: <BoxShadow>[
  1224.                                 new BoxShadow(
  1225.                                   color: Colors.black12,
  1226.                                   blurRadius: 10.0,
  1227.                                   offset: new Offset(0.0, 10.0),
  1228.                                 ),
  1229.                               ],
  1230.                             ),
  1231.                             child: Column(
  1232.                               children: <Widget>[
  1233.                                 Container(
  1234.                                   margin: EdgeInsets.only(
  1235.                                     top: 30.0,
  1236.                                     bottom: 16.0,
  1237.                                     left: 16.0,
  1238.                                     right: 16.0,
  1239.                                   ),
  1240.                                   child: new Row(
  1241.                                     children: <Widget>[
  1242.                                       Expanded(
  1243.                                           child: Text(
  1244.                                         _currentMonth,
  1245.                                         style: TextStyle(
  1246.                                           fontWeight: FontWeight.bold,
  1247.                                           fontSize: 24.0,
  1248.                                         ),
  1249.                                       )),
  1250.                                       FlatButton(
  1251.                                         child: Text('PREV'),
  1252.                                         onPressed: () {
  1253.                                           setState(() {
  1254.                                             _targetDateTime = DateTime(_targetDateTime.year, _targetDateTime.month -1);
  1255.                                             _currentMonth = DateFormat.yMMM().format(_targetDateTime);
  1256.                                             m = DateFormat.M()
  1257.                                                 .format(_currentDate2);
  1258.                                             y = DateFormat.y()
  1259.                                                 .format(_currentDate2);
  1260.                                             _isVisible = false;
  1261.                                             fetchEventNext();
  1262.                                           });
  1263.                                         },
  1264.                                       ),
  1265.                                       FlatButton(
  1266.                                         child: Text('NEXT'),
  1267.                                         onPressed: () {
  1268.                                           setState(() {
  1269.                                             _targetDateTime = DateTime(_targetDateTime.year, _targetDateTime.month +1);
  1270.                                             _currentMonth = DateFormat.yMMM().format(_targetDateTime);
  1271.                                             m = DateFormat.M()
  1272.                                                 .format(_currentDate2);
  1273.                                             y = DateFormat.y()
  1274.                                                 .format(_currentDate2);
  1275.                                             _isVisible = false;
  1276.                                             fetchEventNext();
  1277.                                           });
  1278.                                         },
  1279.                                       )
  1280.                                     ],
  1281.                                   ),
  1282.                                 ),
  1283.                                 Container(
  1284.                                   margin:
  1285.                                       EdgeInsets.symmetric(horizontal: 16.0),
  1286.                                   child: _calendarCarouselNoHeader,
  1287.                                 ), //
  1288.                               ],
  1289.                             )),
  1290.                       ),
  1291.                     ),
  1292.                     Padding(
  1293.                       padding: EdgeInsets.only(bottom: 10.0),
  1294.                     ),
  1295.                     Padding(
  1296.                       padding: EdgeInsets.only(bottom: 10.0),
  1297.                     ),
  1298.                     Align(
  1299.                       child: Container(
  1300.                           padding: EdgeInsets.all(15.0),
  1301.                           child: Column(
  1302.                             children: <Widget>[
  1303.                               Row(
  1304.                                 children: <Widget>[
  1305.                                   Text(
  1306.                                     "Agenda & Kegiatan Bulan Ini",
  1307.                                     textAlign: TextAlign.center,
  1308.                                     style: TextStyle(
  1309.                                         fontSize: 16.0,
  1310.                                         fontWeight: FontWeight.bold,
  1311.                                         color: Colors.black),
  1312.                                   ),
  1313.                                 ],
  1314.                               ),
  1315.                             ],
  1316.                           )),
  1317.                     ),
  1318.                     _contentKajian(),
  1319.                     Padding(
  1320.                       padding: EdgeInsets.only(bottom: 150.0),
  1321.                     ),
  1322.                   ],
  1323.                 ),
  1324.               ),
  1325.             ),
  1326.           ],
  1327.         ));
  1328.   }
  1329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement