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

HomeWidgetLaunchIntent duplicates the current route in flutter on Android #333

Open
1 task
sinan-aktepe opened this issue Feb 10, 2025 · 0 comments
Open
1 task
Labels
bug Something isn't working

Comments

@sinan-aktepe
Copy link

sinan-aktepe commented Feb 10, 2025

What happened?

On android, when i tap the home widget, it duplicates the current route. This is the kotlin side

override fun onUpdate(
    context: Context,
    appWidgetManager: AppWidgetManager,
    appWidgetIds: IntArray,
    widgetData: SharedPreferences
) {
    appWidgetIds.forEach { widgetId ->
        val views =
            RemoteViews(context.packageName, R.layout.widget_layout).apply {
                val pendingIntent = HomeWidgetLaunchIntent.getActivity(
                    context,
                    MainActivity::class.java,
                    Uri.parse("test://test.com")
                )
                setOnClickPendingIntent(R.id.widget_title, pendingIntent)
            }

        appWidgetManager.updateAppWidget(widgetId, views)
    }
}

This is my implementation on home_view

@override
  void initState() {
    super.initState();

    HomeWidgetService.instance.init();
    _getHomeWidgetInitialUri();
  }


_getHomeWidgetInitialUri() async {
    final uri = await HomeWidgetService.instance.getInitialUri();
    if (uri != null) {
      goToNewsDetailFromUri(uri);
    }
  }


@override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _listenHomeWidgetClicked();
  }


_listenHomeWidgetClicked() {
    _homeWidgetSub = HomeWidgetService.instance.onWidgetClicked.listen((event) {
      if (event != null && mounted) {
        goToNewsDetailFromUri(event);
      }
    });
  }

What do you expect?

I was expecting to see the app navigate to detail page. But it pushes to another home_view.

Relevant log output

Execute in a terminal and put output into the code block below

[✓] Flutter (Channel stable, 3.27.0, on macOS 15.3 24D60 darwin-arm64, locale
    en-TR)
    • Flutter version 3.27.0 on channel stable at
      /Users/sinanaktepe/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8495dee1fd (9 weeks ago), 2024-12-10 14:23:39 -0800
    • Engine revision 83bacfc525
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/sinanaktepe/Library/Android/sdk
    • Platform android-35, build-tools 34.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.2)
    • 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 21.0.4+-12422083-b607.1)

[✓] VS Code (version 1.77.3)
    • VS Code at /Users/sinanaktepe/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.104.0

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile)     • emulator-5554             •
      android-arm64  • Android 13 (API 33) (emulator)
    • Sinan’s iPhone (mobile)         • 00008120-000C593A2EB8201E • ios
      • iOS 18.1.1 22B91
    • macOS (desktop)                 • macos                     • darwin-arm64
      • macOS 15.3 24D60 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin
      • macOS 15.3 24D60 darwin-arm64
    • Chrome (web)                    • chrome                    •
      web-javascript • Google Chrome 133.0.6943.53

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

On which Platform do you experience this issue?

Android

Other information

No response

Are you interested in working on a PR for this?

  • I want to work on this
@sinan-aktepe sinan-aktepe added the bug Something isn't working label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant