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

[go_router]: Bad state: Origin is only applicable to schemes http and https #148389

Open
lokalathlet opened this issue May 15, 2024 · 6 comments
Open
Labels
found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package package flutter/packages repository. See also p: labels. team-go_router Owned by Go Router team

Comments

@lokalathlet
Copy link

lokalathlet commented May 15, 2024

What package does this bug report belong to?

go_router

What target platforms are you seeing this bug on?

Android, iOS

Steps to reproduce

Change go_router dependency from version 13.2.2 to 13.2.5 (or 14.1.1)
The router(.dart) call 'GoRouteInformationParser.parseRouteInformationWithDependencies' before redirect.
The method processes the routeInformation:
String newUri = '${routeInformation.uri.origin}/';
This ends in an exception
StateError (Bad state: Origin is only applicable to schemes http and https: anyapp://redirect

The following StateError was thrown while dispatching
I/flutter (31737): │ notifications for GoRouteInformationProvider:
I/flutter (31737): │ Bad state: Origin is only applicable to schemes http and https:
I/flutter (31737): │ anyapp://redirect

Expected results

  1. Custom scheme doesn't result in bad state
  2. GoRouterWidgetBuilder should be invoked

Actual results

  1. Custom scheme do result in bad state
  2. GoRouterWidgetBuilder is not invoked

Code snippet

parseRouteInformationWithDependencies from version 13.2.5 failing
late final RouteMatchList initialMatches;
    if (routeInformation.uri.hasEmptyPath) {
      String newUri = '${routeInformation.uri.origin}/';
      if (routeInformation.uri.hasQuery) {
        newUri += '?${routeInformation.uri.query}';
      }
      if (routeInformation.uri.hasFragment) {
        newUri += '#${routeInformation.uri.fragment}';
      }
      initialMatches = configuration.findMatch(
        newUri,
        extra: state.extra,
      );
    } else {
      initialMatches = configuration.findMatch(
        routeInformation.uri.toString(),
        extra: state.extra,
      );
    }
    if (initialMatches.isError) {
      log('No initial matches: ${routeInformation.uri.path}');
    }
parseRouteInformationWithDependencies from version 13.2.2 working
 late final RouteMatchList initialMatches;
    initialMatches = configuration.findMatch(
        routeInformation.uri.path.isEmpty
            ? '${routeInformation.uri}/'
            : routeInformation.uri.toString(),
        extra: state.extra);
    if (initialMatches.isError) {
      log('No initial matches: ${routeInformation.uri.path}');
    }

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
The GoRouteInformationProvider sending notification was: Instance of 'GoRouteInformationProvider'
════════════════════════════════════════════════════════════════════════════════
I/flutter (31737): ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (31737): │ [error] | 10:06:00 295ms | ══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞═════════════════════
I/flutter (31737): │ The following StateError was thrown while dispatching
I/flutter (31737): │ notifications for GoRouteInformationProvider:
I/flutter (31737): │ Bad state: Origin is only applicable to schemes http and https:
I/flutter (31737): │ elbaapp://redirect?code=dd2b4087-8649-407d-80d2-a2e55b7e75af&state=E-fPQdg0elXTnmRSrL345e1HXJjsSFIT
I/flutter (31737): │ 
I/flutter (31737): │ When the exception was thrown, this was the stack:
I/flutter (31737): │ #0      _SimpleUri.origin (dart:core/uri.dart:4502:7)
I/flutter (31737): │ #1      GoRouteInformationParser.parseRouteInformationWithDependencies (package:go_router/src/parser.dart:83:47)
I/flutter (31737): │ #2      _RouterState._processRouteInformation (package:flutter/src/widgets/router.dart:749:8)
I/flutter (31737): │ #3      _RouterState._handleRouteInformationProviderNotification (package:flutter/src/widgets/router.dart:767:5)
I/flutter (31737): │ #4      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:433:24)
I/flutter (31737): │ #5      GoRouteInformationProvider.notifyListeners (package:go_router/src/information_provider.dart:134:11)
I/flutter (31737): │ #6      GoRouteInformationProvider._platformReportsNewRouteInformation (package:go_router/src/information_provider.dart:235:5)
I/flutter (31737): │ #7      GoRouteInformationProvider.didPushRouteInformation (package:go_router/src/information_provider.dart:279:5)
I/flutter (31737): │ #8      WidgetsBinding._handlePushRouteInformation (package:flutter/src/widgets/binding.dart:777:26)
I/flutter (31737): │ <asynchronous suspension>
I/flutter (31737): │ #9      MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:571:42)
I/flutter (31737): │ <asynchronous suspension>
I/flutter (31737): │ #10     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:603:22)
I/flutter (31737): │ <asynchronous suspension>
I/flutter (31737): │ 
I/flutter (31737): │ The GoRouteInformationProvider sending notification was:
I/flutter (31737): │   Instance of 'GoRouteInformationProvider'
I/flutter (31737): │ ═════════════════════════════════════════════════════════════════
I/flutter (31737): │ 
I/flutter (31737): │ Bad state: Origin is only applicable to schemes http and https: elbaapp://redirect?code=dd2b4087-8649-407d-80d2-a2e55b7e75af&state=E-fPQdg0elXTnmRSrL345e1HXJjsSFIT
I/flutter (31737): │ StackTrace: #0      _SimpleUri.origin (dart:core/uri.dart:4502:7)
I/flutter (31737): │ #1      GoRouteInformationParser.parseRouteInformationWithDependencies (package:go_router/src/parser.dart:83:47)
I/flutter (31737): │ #2      _RouterState._processRouteInformation (package:flutter/src/widgets/router.dart:749:8)
I/flutter (31737): │ #3      _RouterState._handleRouteInformationProviderNotification (package:flutter/src/widgets/router.dart:767:5)
I/flutter (31737): │ #4      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:433:24)
I/flutter (31737): │ #5      GoRouteInformationProvider.notifyListeners (package:go_router/src/information_provider.dart:134:11)
I/flutter (31737): │ #6      GoRouteInformationProvider._platformReportsNewRouteInformation (package:go_router/src/information_provider.dart:235:5)
I/flutter (31737): │ #7      GoRouteInformationProvider.didPushRouteInformation (package:go_router/src/information_provider.dart:279:5)
I/flutter (31737): │ #8      WidgetsBinding._handlePushRouteInformation (package:flutter/src/widgets/binding.dart:777:26)
I/flutter (31737): │ <asynchronous suspension>
I/flutter (31737): │ #9      MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:571:42)
I/flutter (31737): │ <asynchronous suspension>
I/flutter (31737): │ #10     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:603:22)
I/flutter (31737): │ <asynchronous suspension>
I/flutter (31737): │ }
I/flutter (31737): └──────────────────────────────────────────────────────────────────────────────────────────────────────────────

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-arm64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.1)
[✓] VS Code (version 1.89.1)
[✓] Connected device (4 available)
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 15, 2024
@darshankawar
Copy link
Member

@lokalathlet
Can you provide runnable reproducible code sample (ex: main.dart) that we can directly use that shows the reported error ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 15, 2024
@lokalathlet lokalathlet changed the title Bad state: Origin is only applicable to schemes http and https [go_router] Bad state: Origin is only applicable to schemes http and https May 17, 2024
@lokalathlet lokalathlet changed the title [go_router] Bad state: Origin is only applicable to schemes http and https [go_router]: Bad state: Origin is only applicable to schemes http and https May 17, 2024
@lokalathlet
Copy link
Author

lokalathlet commented May 21, 2024

Hi @darshankawar, here a simple code sample. Click the button "Go to custom scheme".
Backround:
We sign-in using a third party library to authenticate. This library call back to the app thru a custom tab. The scheme is registered as an intent-filter

 <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="anyapp" />
  </intent-filter>

main.dart

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

/// This sample app shows an app with two screens.
///
/// The first route '/' is mapped to [HomeScreen], and the second route
/// '/details' is mapped to [DetailsScreen].
///
/// The buttons use context.go() to navigate to each destination. On mobile
/// devices, each destination is deep-linkable and on the web, can be navigated
/// to using the address bar.
void main() => runApp(const MyApp());

/// The route configuration.
final GoRouter _router = GoRouter(
  routes: <RouteBase>[
    GoRoute(
      path: '/',
      builder: (BuildContext context, GoRouterState state) {
        return const HomeScreen();
      },
      routes: <RouteBase>[
        GoRoute(
          path: 'details',
          builder: (BuildContext context, GoRouterState state) {
            return const DetailsScreen();
          },
        ),
      ],
    ),
  ],
);

/// The main app.
class MyApp extends StatelessWidget {
  /// Constructs a [MyApp]
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: _router,
    );
  }
}

/// The home screen
class HomeScreen extends StatelessWidget {
  /// Constructs a [HomeScreen]
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Screen')),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
              onPressed: () => context.go('/details'),
              child: const Text('Go to the Details screen'),
            ),
            ElevatedButton(
              onPressed: () => context.go('anyapp://redirect'),
              child: const Text('Go to custom scheme'),
            ),
          ],
        ),
      ),
    );
  }
}

/// The details screen
class DetailsScreen extends StatelessWidget {
  /// Constructs a [DetailsScreen]
  const DetailsScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Details Screen')),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
              onPressed: () => context.go('/'),
              child: const Text('Go back to the Home screen'),
            ),
          ],
        ),
      ),
    );
  }
}

pubspec.yaml:

name: flutter_application_1
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: '>=3.3.4 <4.0.0'

dependencies:
  flutter:
    sdk: flutter


  cupertino_icons: ^1.0.6
  go_router: 13.2.2 # working
  # go_router: ^13.2.5 # not working

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0

flutter:

  uses-material-design: true`

The working example with the old go_router 13.2.2 directs to the error page
Bildschirmfoto 2024-05-21 um 18 59 49

The non-working example runs into an exception (13.2.5 and higher), change the dependencies.
Bildschirmfoto 2024-05-21 um 19 03 21

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 21, 2024
@darshankawar
Copy link
Member

Thanks for the update. I was able to replicate this as reported.

stable, master flutter doctor -v
[!] Flutter (Channel stable, 3.22.0, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.22.0 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5dcb86f68f (5 days ago), 2024-05-09 07:39:20 -0500
    • Engine revision f6344b75dc
    • Dart version 3.4.0
    • DevTools version 2.34.3
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.22.0-39.0.pre.2, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 3.22.0-39.0.pre.2 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d02292dbc4 (5 hours ago), 2024-05-20 21:25:37 -0700
    • Engine revision c2ef01f6f1
    • Dart version 3.5.0 (build 3.5.0-172.0.dev)
    • DevTools version 2.36.0-dev.10
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/dhs/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13C100
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 65.1.4
    • Dart plugin version 213.7228

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.29.0

[✓] Connected device (3 available)
    • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
      • iOS 15.3.1 19D52
    • macOS (desktop)           • macos                                    •
      darwin-x64     • macOS 12.2.1 21D62 darwin-x64
    • Chrome (web)              • chrome                                   •
      web-javascript • Google Chrome 109.0.5414.119

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
      
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.



@darshankawar darshankawar added package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package team-go_router Owned by Go Router team found in release: 3.22 Found to occur in 3.22 and removed in triage Presently being triaged by the triage team labels May 22, 2024
@godilite
Copy link

godilite commented Jun 1, 2024

Any fix yet? Experiencing same issue

@godilite
Copy link

godilite commented Jun 1, 2024

I had to revert to 3.2.2 fixed version to get it working

@Omar-PDing
Copy link

Facing the same issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package package flutter/packages repository. See also p: labels. team-go_router Owned by Go Router team
Projects
None yet
Development

No branches or pull requests

4 participants