Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidUrlVError on Android Deep Link #218

Open
sergioprot opened this issue Nov 9, 2023 · 1 comment
Open

InvalidUrlVError on Android Deep Link #218

sergioprot opened this issue Nov 9, 2023 · 1 comment

Comments

@sergioprot
Copy link

If Android deep link only contains host (no path parameters), VRouter will throw InvalidUrlVError exception.

Steps to reproduce

I'm using flutter 3.13.9 and vrouter 1.2.1. I tested on Android 11 emulator just so that I wouldn't have to configure host.
Here's the minimal reproducible code sample:
main.dart:

import 'package:flutter/material.dart';
import 'package:vrouter/vrouter.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return VRouter(
      routes: [
        VWidget(
          path: '/',
          widget: const Home(),
        )
      ],
    );
  }
}

class Home extends StatelessWidget {
  const Home({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('VRouter'),
      ),
    );
  }
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application
        android:label="vrouter_test"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="example.com" />
                <data android:scheme="https" />
            </intent-filter>

        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Then tap this deep link on Android device/emulator: https://example.com

Expected result

App opens on initialUrl, which is '/' by default.

Actual result

Screenshot 2023-11-09 at 12 54 33

Logs:

======== Exception caught by widgets library =======================================================
The following InvalidUrlVError was thrown building Builder(dirty, dependencies: [VRouterScopeData]):
The current url is null but you are trying to access the path "" which does not start with '/'.
This is likely because you set a initialUrl which does not start with '/'.

The relevant error-causing widget was: 
  Builder Builder:file:///Users/sergey/.pub-cache/hosted/pub.dev/vrouter-1.2.1/lib/src/core/vrouter_delegate.dart:1864:18
When the exception was thrown, this was the stack: 
#0      VRouterDelegate.to (package:vrouter/src/core/vrouter_delegate.dart:1302:9)
#1      VRouterDelegate._initialize (package:vrouter/src/core/vrouter_delegate.dart:1609:9)
#2      VRouterDelegate.build.<anonymous closure> (package:vrouter/src/core/vrouter_delegate.dart:1869:36)
#3      Builder.build (package:flutter/src/widgets/basic.dart:7619:48)
#4      StatelessElement.build (package:flutter/src/widgets/framework.dart:5367:49)
#5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5297:15)
#6      Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#7      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5279:5)
#8      ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
...     Normal element mounting (446 frames)
#454    Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
#455    Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
#456    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1253:16)
#457    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1222:5)
#458    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1169:18)
#459    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2719:19)
#460    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1168:13)
#461    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:1001:7)
#462    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:981:7)
#466    _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 3 frames from class _Timer and dart:async-patch)
====================================================================================================

======== Exception caught by widgets library =======================================================
The following InvalidUrlVError was thrown building Builder(dependencies: [VRouterScopeData]):
The current url is null but you are trying to access the path "" which does not start with '/'.
This is likely because you set a initialUrl which does not start with '/'.

The relevant error-causing widget was: 
  Builder Builder:file:///Users/sergey/.pub-cache/hosted/pub.dev/vrouter-1.2.1/lib/src/core/vrouter_delegate.dart:1864:18
When the exception was thrown, this was the stack: 
#0      VRouterDelegate.to (package:vrouter/src/core/vrouter_delegate.dart:1302:9)
#1      VRouterDelegate._initialize (package:vrouter/src/core/vrouter_delegate.dart:1609:9)
#2      VRouterDelegate.build.<anonymous closure> (package:vrouter/src/core/vrouter_delegate.dart:1869:36)
#3      Builder.build (package:flutter/src/widgets/basic.dart:7619:48)
#4      StatelessElement.build (package:flutter/src/widgets/framework.dart:5367:49)
#5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5297:15)
#6      Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#7      StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
#8      Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#10     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#11     ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#14     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#15     ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
#16     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#17     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#18     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#19     ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
#20     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#21     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#22     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#23     StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
#24     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#25     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#26     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#27     ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
#28     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#29     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#30     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#31     ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
#32     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#33     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#34     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
#35     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#36     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2779:19)
#37     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:916:21)
#38     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
#39     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#40     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#41     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:952:7)
#45     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 3 frames from class _Timer and dart:async-patch)
====================================================================================================
sergioprot pushed a commit to sergioprot/vrouter that referenced this issue Nov 9, 2023
@sergioprot
Copy link
Author

This fix works for me: sergioprot@53c9a2e
@lulupointu Should I open a PR for this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant