Advertisement
Jcrox

testing.dart

May 4th, 2025 (edited)
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.06 KB | Source Code | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:projectname/my_functions.dart';
  3. import 'package:onesignal_flutter/onesignal_flutter.dart';
  4.  
  5. void main() {
  6.   runApp(const MyApp());
  7.  
  8.   OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
  9.   OneSignal.initialize("app-id-nimo");
  10.   OneSignal.Notifications.requestPermission(true);
  11. }
  12.  
  13. class MyApp extends StatelessWidget {
  14.   const MyApp({super.key});
  15.  
  16.   @override
  17.   Widget build(BuildContext context) {
  18.     return MaterialApp(
  19.       title: 'OneSignal Example',
  20.       theme: ThemeData(
  21.         primarySwatch: Colors.blue,
  22.       ),
  23.       home: const LoginPage(),
  24.     );
  25.   }
  26. }
  27.  
  28. class LoginPage extends StatelessWidget {
  29.   const LoginPage({super.key});
  30.  
  31.   @override
  32.   Widget build(BuildContext context) {
  33.     return Scaffold(
  34.       appBar: AppBar(
  35.         title: const Text('Login'),
  36.       ),
  37.       body: Center(
  38.         children: <Widget>[
  39.             ElevatedButton(
  40.               onPressed: () {
  41.                 //Gamit ni kung by group imo gusto eh notify, example Staff
  42.                 OneSignal.User.addTagWithKey("userType", "Staff");
  43.                
  44.                 //Kuhaon ning player_id, iya kuhaon ang id sa imo device. Gamit ni para individual notification
  45.                 //Ako ge butang ang player_id sa osUID nako sa firestore document
  46.                 //Depende ni ug unsay hitsura sa imo document, ilisi lng, basta kanang player_id ang ibutang
  47.                  String? player_id = OneSignal.User.pushSubscription.id;
  48.         await FirebaseFirestore.instance
  49.             .collection('users')
  50.             .doc(userId)
  51.             .update({'osUID': player_id});
  52.            
  53.            
  54.            
  55.               },
  56.               child: const Text('Add OneSignal Data'),
  57.             ),
  58.             const SizedBox(height: 20),
  59.             ElevatedButton(
  60.               onPressed: () {
  61.                  
  62.                  
  63.                  
  64.                 await NotifServices.sendGroupNotification(
  65.           userType:"Staff",
  66.           heading: "Message for Staffs",
  67.           content:
  68.               "This is a message for statffs!",
  69.           // Optionally include an image URL:
  70.           // bigPicture: "https://example.com/image.png",
  71.         );
  72.                  
  73.                  
  74.                  
  75.               },
  76.               child: const Text('Test Group Notification'),
  77.             ),
  78.             const SizedBox(height: 20),
  79.             ElevatedButton(
  80.               onPressed: () {
  81.                  
  82.                  
  83.                 await NotifServices.sendIndividualNotification(
  84.                       playerId: "ag_player_id_na_ge_butang_nimo_sa_field_sa_imo_document", //pwede sad eh variable pagbutang
  85.                       heading: "Individual Message",
  86.                       content:
  87.                           "Individual Notification",
  88.                     );
  89.                  
  90.                  
  91.                  
  92.               },
  93.               child: const Text('Test individual notification'),
  94.             ),
  95.           ],
  96.       ),
  97.     );
  98.   }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement