Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:projectname/my_functions.dart';
- import 'package:onesignal_flutter/onesignal_flutter.dart';
- void main() {
- runApp(const MyApp());
- OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
- OneSignal.initialize("app-id-nimo");
- OneSignal.Notifications.requestPermission(true);
- }
- class MyApp extends StatelessWidget {
- const MyApp({super.key});
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'OneSignal Example',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: const LoginPage(),
- );
- }
- }
- class LoginPage extends StatelessWidget {
- const LoginPage({super.key});
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('Login'),
- ),
- body: Center(
- children: <Widget>[
- ElevatedButton(
- onPressed: () {
- //Gamit ni kung by group imo gusto eh notify, example Staff
- OneSignal.User.addTagWithKey("userType", "Staff");
- //Kuhaon ning player_id, iya kuhaon ang id sa imo device. Gamit ni para individual notification
- //Ako ge butang ang player_id sa osUID nako sa firestore document
- //Depende ni ug unsay hitsura sa imo document, ilisi lng, basta kanang player_id ang ibutang
- String? player_id = OneSignal.User.pushSubscription.id;
- await FirebaseFirestore.instance
- .collection('users')
- .doc(userId)
- .update({'osUID': player_id});
- },
- child: const Text('Add OneSignal Data'),
- ),
- const SizedBox(height: 20),
- ElevatedButton(
- onPressed: () {
- await NotifServices.sendGroupNotification(
- userType:"Staff",
- heading: "Message for Staffs",
- content:
- "This is a message for statffs!",
- // Optionally include an image URL:
- // bigPicture: "https://example.com/image.png",
- );
- },
- child: const Text('Test Group Notification'),
- ),
- const SizedBox(height: 20),
- ElevatedButton(
- onPressed: () {
- await NotifServices.sendIndividualNotification(
- playerId: "ag_player_id_na_ge_butang_nimo_sa_field_sa_imo_document", //pwede sad eh variable pagbutang
- heading: "Individual Message",
- content:
- "Individual Notification",
- );
- },
- child: const Text('Test individual notification'),
- ),
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement