import 'dart:async'; import 'package:flutter/services.dart'; abstract class Bloc { void dispose(); } class DeepLinkBloc extends Bloc { //Event Channel creation static const stream = const EventChannel('https://demo.endi.coop/login?nextpage=%2F'); //Method channel creation static const platform = const MethodChannel('https://demo.endi.coop'); StreamController _stateController = StreamController(); Stream get state => _stateController.stream; Sink get stateSink => _stateController.sink; //Adding the listener into contructor DeepLinkBloc() { //Checking application start by deep link startUri().then(_onRedirected); //Checking broadcast stream, if deep link was clicked in opened appication stream.receiveBroadcastStream().listen((d) => _onRedirected(d)); } _onRedirected(String uri) { // Throw deep link URI into the BloC's stream stateSink.add(uri); } @override void dispose() { _stateController.close(); } Future startUri() async { try { return platform.invokeMethod('initialLink'); } on PlatformException catch (e) { return "Failed to Invoke: '${e.message}'."; } } }