avioli / uni_links

Flutter plugin for accepting incoming links.
BSD 2-Clause "Simplified" License
564 stars 316 forks source link

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getInitialLink on channel uni_links/messages) #142

Open koddr opened 3 years ago

koddr commented 3 years ago

Hi,

I consistently get a weird bug on macOS (desktop) when adding Supabase.initialize() to the main() function. On Android and iOS (both emulators and real devices) this bug does not… 😞

Similar issue at the supabase/supabase-flutter repository here. The authors have written that they are waiting to add support from your package.

To Reproduce

My β€œone-file” ./lib/main.dart (for short):

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

import 'package:supabase_flutter/supabase_flutter.dart';

Future<void> main() async {
  // Add instance of the WidgetsBinding.
  // See: https://github.com/supabase/supabase-flutter#getting-started
  WidgetsFlutterBinding.ensureInitialized();

  // Add Supabase connector.
  // See: https://github.com/supabase-community/supabase-flutter-quickstart/blob/main/lib/main.dart
  await Supabase.initialize(
    url: '[SUPABASE_ENDPOINT_URL]',
    anonKey: '[SUPABASE_ANON_KEY]',
    authCallbackUrlHostname: 'login-callback',
    debug: true,
  );

  // Run main application widget.
  runApp(const MyApp());
}

/// Main application widget.
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My App',
      debugShowCheckedModeBanner: false,
      themeMode: ThemeMode.system,
      initialRoute: '/',
      routes: <String, WidgetBuilder>{
        '/': (_) => const SplashScreen(),
      },
    );
  }
}

/// Create AuthState.
class AuthState<T extends StatefulWidget> extends SupabaseAuthState<T> {
  @override
  void onUnauthenticated() {}

  @override
  void onAuthenticated(Session session) {}

  @override
  void onPasswordRecovery(Session session) {}

  @override
  void onErrorAuthenticating(String message) {}
}

/// Screen for the Splash page (initial page of the app).
class SplashScreen extends StatefulWidget {
  const SplashScreen({Key? key}) : super(key: key);

  @override
  _SplashScreenState createState() => _SplashScreenState();
}

/// State for the splash screen.
class _SplashScreenState extends AuthState<SplashScreen> {
  @override
  void initState() {
    // Recovery Supabase session.
    recoverSupabaseSession();
    // Init state.
    super.initState();
  }

  @override
  void dispose() => super.dispose();

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: CircularProgressIndicator(color: Color(0xFF00AB55)),
      ),
    );
  }
}

Expected behavior

It would be great to run a desktop macOS (and probably Windows and GNU/Linux) app with Supabase without errors. Like it does on Android and iOS.

Screenshots

I run project with VS Code standard debugger (F5):

Launching lib/main.dart on macOS in debug mode...

lib/main.dart:1

--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:x86_64, id:3F1370FE-97D5-54BC-9DF8-54CF550D3229 }
{ platform:macOS, name:Any Mac }

Connecting to VM Service at ws://127.0.0.1:58514/LbvTAgExSus=/ws

flutter: ***** Supabase init completed Instance of 'Supabase'
flutter: ***** SupabaseAuthState startAuthObserver
flutter: ***** SupabaseDeepLinkingMixin startAuthObserver

════════ Exception caught by services library ══════════════════════════════════
The following MissingPluginException was thrown while activating platform stream on channel uni_links/events:
MissingPluginException(No implementation found for method listen on channel uni_links/events)

When the exception was thrown, this was the stack
#0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:154
<asynchronous suspension>
#1      EventChannel.receiveBroadcastStream.<anonymous closure>
package:flutter/…/services/platform_channel.dart:486
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════

...

The debugger shows line 154 in the /usr/local/Caskroom/flutter/2.5.3/flutter/packages/flutter/lib/src/services/platform_channel.dart file:

Screenshot 2021-11-20 at 11 02 38

OK. I click β€œContinue” button (F5) and debugger shows line 15 in /usr/local/Caskroom/flutter/2.5.3/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.5.1/lib/uni_links.dart file:

Screenshot 2021-11-20 at 11 04 39

Next, click F5 once again and see line 52 in /usr/local/Caskroom/flutter/2.5.3/flutter/.pub-cache/hosted/pub.dartlang.org/supabase_flutter-0.2.9/lib/src/supabase_deep_linking_mixin.dart file:

Screenshot 2021-11-20 at 11 06 59

If I click F5 again, debugger run app with this message:

...

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getInitialLink on channel uni_links/messages)
#0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:154
<asynchronous suspension>
#1      getInitialUri
package:uni_links/uni_links.dart:15
<asynchronous suspension>
#2      SupabaseDeepLinkingMixin._handleInitialUri
package:supabase_flutter/src/supabase_deep_linking_mixin.dart:52
<asynchronous suspension>

🀞 Yes, the application runs and works fine… but it is very inconvenient when debugging and developing! I constantly have to press F5 many times every time I change the code.

System information

$ flutter doctor -v

[βœ“] Flutter (Channel stable, 2.5.3, on macOS 11.6.1 20G224 darwin-x64, locale en-GB)
    β€’ Flutter version 2.5.3 at /usr/local/Caskroom/flutter/2.5.3/flutter
    β€’ Upstream repository https://github.com/flutter/flutter.git
    β€’ Framework revision 18116933e7 (5 weeks ago), 2021-10-15 10:46:35 -0700
    β€’ Engine revision d3ea636dc5
    β€’ Dart version 2.14.4

[βœ“] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    β€’ Android SDK at /Users/koddr/Library/Android/sdk
    β€’ Platform android-31, build-tools 31.0.0
    β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Xcode 13.1, Build version 13A1030d
    β€’ CocoaPods version 1.11.2

[βœ“] Chrome - develop for the web
    β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[βœ“] Android Studio (version 2020.3)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart
    β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[βœ“] VS Code (version 1.62.3)
    β€’ VS Code at /Applications/Visual Studio Code.app/Contents
    β€’ Flutter extension version 3.28.0

[βœ“] Connected device (2 available)
    β€’ macOS (desktop) β€’ macos  β€’ darwin-x64     β€’ macOS 11.6.1 20G224 darwin-x64
    β€’ Chrome (web)    β€’ chrome β€’ web-javascript β€’ Google Chrome 95.0.4638.69

β€’ No issues found!

Additional context

Commands flutter clean and flutter pub get did not resolve the problem.

wolfenrain commented 2 years ago

Side note: You can as a temporary fix override the startDeeplinkObserver in your Supabase state.

/// Create AuthState.
class AuthState<T extends StatefulWidget> extends SupabaseAuthState<T> {
  @override
  void startDeeplinkObserver() {
    if (Platform.isAndroid || Platform.isIOS) {
      return super.startDeeplinkObserver();
    }
    print('***** Overridden startDeeplinkObserver for Desktop support');
  }
}
Djihanegh commented 2 years ago

I have the same issue in android, i'am trying to run the offcial example of the package, on a real device. Flutter version : 3.0.5 uni_links version : ^0.5.1

Screenshots

image