Flutter OneSignal Deeplink Implementation

Flutter Onesignal Deeplinks :

Flutter onesignal deeplink concept is explained in this blog with OneSignal. Deep linking enables you to improve the user in flow to your apps, websites by making them know the available services.

You can customise the information with the help of images and one liners such that they attract the user interest.

OneSignal provides you various services using which you can make the user re visit your app / website every time a new content is published or released.

OneSignal uses the firebase as backend and provides you with the functionality you can find firebase and its usages here firebase info.

 

Flutter Onesignal Deeplinks Video Tutorial :

Go through the below playlist for onesignal implementations.

pubspec.yaml:

We need to add onesignal flutter dependency so that we can make use of onesignal services in our flutter app. Make sure you provide the latest updates so that there are no issues.

dependencies:
  flutter:
    sdk: flutter
  onesignal_flutter: ^3.5.0

 

main.dart :

In this class file we are going to implement flutter deeplink onesignal.

import 'package:flutter/material.dart';
import 'package:flutter_onesignal_deeplink/profile.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Onesignal Deeplink"),
        ),
        body: Home()
      ),
    );
  }
}


class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {

  @override
  void initState() {
    super.initState();
    OneSignal.shared.setLogLevel(OSLogLevel.debug, OSLogLevel.none);
    OneSignal.shared.setAppId("82fc054e-08f0-4266-a9f5-d144716fcdae");

    OneSignal.shared.setNotificationOpenedHandler((openedResult) {
     var data =  openedResult.notification.additionalData!["Page"].toString();
     
     if(data == "Profile"){
       Navigator.push(context, MaterialPageRoute(builder: (context) => Profile()));
     }
     
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: TextButton(
        child: Text("Home Screen"),
        onPressed: (){
        },
      ),
    );
  }
}

 

profile.dart :

This is the profile screen to which we are getting redirected once we receive notification. Here we are not providing any additional functionality.

 

import 'package:flutter/material.dart';

class Profile extends StatelessWidget {
  const Profile({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Profile')),
      body: const Center(
        child: Text("Profile Screen",
          style: TextStyle(fontSize: 24.0),
        ),
      ),
    );
  }
}

 

If you have any query’s in this tutorial on flutter deeplink onesignal do let us know in the comment section below.If you like this tutorial do like and share us for more interesting updates.

Show Buttons
Hide Buttons
Read previous post:
flutter video player
Flutter Video Player Widget Integration

Flutter Video Player : In this blog we are going to learn the easiest way to implement video player in...

Close