Flutter.io - Is it possible to deep link to Android and iOS in Flutter? -
if it's possible, easy implementation or tough one?
i had difficulty getting clear idea in flutter.io's documentation.
you can use platform channel this. shouldn't tough. need add handlers in native code , redirect urls via channels flutter code. example ios:
@implementation appdelegate - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { [generatedpluginregistrant registerwithregistry:self]; flutterviewcontroller *controller = (flutterviewcontroller*)self.window.rootviewcontroller; self.urlchannel = [fluttermethodchannel methodchannelwithname:@"com.myproject/url" binarymessenger:controller]; return [super application:application didfinishlaunchingwithoptions:launchoptions]; } - (bool)application:(uiapplication *)app openurl:(nsurl *)url options:(nsdictionary<uiapplicationopenurloptionskey,id> *)options{ [self.urlchannel invokemethod:@"openurl" arguments:@{@"url" : url.absolutestring}]; return true; } @end
and basic flutter code:
class _myhomepagestate extends state<myhomepage> { final methodchannel channel = const methodchannel("com.myproject/url"); string _url; @override initstate() { super.initstate(); channel.setmethodcallhandler((methodcall call) async { debugprint("setmethodcallhandler call = $call"); if (call.method == "openurl") { setstate(() => _url = call.arguments["url"]); } }); } @override widget build(buildcontext context) { return new scaffold( appbar: new appbar( title: new text(_url ?? "no url"), ), ); } }
Comments
Post a Comment