Advertisement
Guest User

Notif

a guest
Sep 7th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 5.74 KB | None | 0 0
  1. import 'package:ayo_sholat/const/date.dart';
  2. import 'package:ayo_sholat/services/notif.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_local_notifications/flutter_local_notifications.dart';
  5. import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
  6.  
  7. void main(){
  8.   runApp(MyApp());
  9. }
  10.  
  11.  
  12. class MyApp extends StatelessWidget {
  13.   // This widget is the root of your application.
  14.   @override
  15.   Widget build(BuildContext context) {
  16.     return MaterialApp(
  17.       home: MyHomePage(),
  18.     );
  19.   }
  20. }
  21.  
  22. class MyHomePage extends StatefulWidget {
  23.  
  24.   @override
  25.   _MyHomePageState createState() => _MyHomePageState();
  26. }
  27.  
  28. class _MyHomePageState extends State<MyHomePage> {
  29.  
  30.   Date date = Date();
  31.   Notif notif = Notif();
  32.   FlutterLocalNotificationsPlugin localNotificationsPlugin;
  33.   var now = new DateTime.now();
  34.   var date1 = DateTime.parse("2019-09-07 22:36:00");
  35.  
  36.   @override
  37.   void initState() {
  38.     super.initState();
  39.     var initAndroid = new AndroidInitializationSettings('app_icon');
  40.     var initIos = new IOSInitializationSettings();
  41.     var initSettings = new InitializationSettings(initAndroid, initIos);
  42.     localNotificationsPlugin = new FlutterLocalNotificationsPlugin();
  43.     localNotificationsPlugin.initialize(initSettings);
  44.   }
  45.  
  46.   showNotification(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async{
  47.    var time = new Time(8, 38, 0);
  48.    var androidPlatformChannelSpecifics =
  49.       new AndroidNotificationDetails('12',
  50.           'Ayo Sholat', 'Ayo Sholat');
  51.   var iOSPlatformChannelSpecifics =
  52.       new IOSNotificationDetails();
  53.   var platformChannelSpecifics = new NotificationDetails(
  54.       androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
  55.   await flutterLocalNotificationsPlugin.showDailyAtTime(
  56.       0,
  57.       'show daily title',
  58.       'Daily notification shown at approximately ',
  59.       time,
  60.       platformChannelSpecifics);
  61.   }
  62.  
  63.   @override
  64.   Widget build(BuildContext context) {
  65.     return Scaffold(
  66.       backgroundColor: Colors.white,
  67.       body: SingleChildScrollView(
  68.         child: Column(
  69.           children: <Widget>[
  70.             Stack(
  71.               children: <Widget>[
  72.                 Container(
  73.                   width: double.infinity,
  74.                   height: MediaQuery.of(context).size.height / 2,
  75.                   decoration: BoxDecoration(
  76.                     color: Colors.grey[300],
  77.                     image: DecorationImage(
  78.                       image: NetworkImage("https://cdn.dribbble.com/users/1866105/screenshots/3766355/1.jpg"),
  79.                       fit: BoxFit.cover
  80.                     )
  81.                   ),
  82.                 ),
  83.                 Padding(
  84.                   padding: const EdgeInsets.only(
  85.                     top: 48.0
  86.                   ),
  87.                   child: Row(
  88.                       mainAxisAlignment: MainAxisAlignment.center,
  89.                       crossAxisAlignment: CrossAxisAlignment.center,
  90.                       children: <Widget>[
  91.                         Column(
  92.                           children: <Widget>[
  93.                             Text("Dhuhur 12:13", style: TextStyle(fontSize: 32.0, fontWeight: FontWeight.w600, color: Colors.white),),
  94.                             SizedBox(height: 8.0,),
  95.                             Text("3 Jam 45 Menit Lagi", style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w500, color: Colors.white),),
  96.                           ],
  97.                         )
  98.                       ],
  99.                   ),
  100.                 ),
  101.                 Positioned(
  102.                   left: 0,
  103.                   bottom: 0,
  104.                   child: Padding(
  105.                     padding: EdgeInsets.only(
  106.                       left: 24.0,
  107.                       bottom: 24.0
  108.                     ),
  109.                     child: Column(
  110.                       mainAxisAlignment: MainAxisAlignment.start,
  111.                       crossAxisAlignment: CrossAxisAlignment.start,
  112.                       children: <Widget>[
  113.                         Text("Hari Ini", style: TextStyle(color: Colors.white, fontSize: 28.0),),
  114.                         SizedBox(height: 4.0,),
  115.                         Text("${date.hari[now.weekday - 1]}, ${now.day} ${date.bulan[now.month - 1]} ${now.year}", style: TextStyle(color: Colors.white, fontSize: 18.0),),
  116.                       ],
  117.                     ),
  118.                   ),
  119.                 )
  120.               ],
  121.             ),
  122.             Padding(
  123.               padding: const EdgeInsets.symmetric(
  124.                 horizontal: 24.0
  125.               ),
  126.               child: Container(
  127.                     width: double.infinity,
  128.                     height: MediaQuery.of(context).size.height / 2,
  129.                     child: ListView.builder(
  130.                     itemCount: date.sholat.length,
  131.                     itemBuilder: (context, index){
  132.                       return Row(
  133.                         children: <Widget>[
  134.                           Expanded(flex: 1,child: Text("${date.sholat[index]}", style: TextStyle(fontSize: 20.0),)),
  135.                           Expanded(flex: 2, child: Center(child: Text("12:13", style: TextStyle(fontSize: 20.0),))),
  136.                           Expanded(
  137.                             flex: 1,
  138.                               child: IconButton(
  139.                               onPressed: ()  {
  140.                                 showNotification(localNotificationsPlugin);
  141.                               },
  142.                               icon: Icon(MdiIcons.alarm, size: 28.0,),
  143.                             ),
  144.                           )
  145.                         ],
  146.                       );
  147.                     },
  148.                 ),
  149.               ),
  150.             )
  151.           ],
  152.         ),
  153.       ),
  154.     );
  155.   }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement