Откройте Slack из приложения Flutter - PullRequest
0 голосов
/ 07 мая 2020

Как я могу интегрировать Slack в свое приложение Flutter для обмена текстом и изображениями? Я использую этот пакет для запуска приложения https://pub.dev/packages/flutter_appavailability. Для простоты вопроса могу сказать, что на моем устройстве установлен Slack, поэтому сейчас я просто тестирую, можно ли открыть Slack. Я полностью осознаю, что могу проверить, установлено ли приложение, используя тот же плагин.

    AppAvailability.launchApp("slack://open").then((_) {
                      print("App slack launched");
                    }).catchError((err) {
                      Scaffold.of(context).showSnackBar(SnackBar(
                          content: Text(" App not found!")
                      ));
                      print(err);
                    });

https://api.slack.com/reference/deep-linking#open_slack # client Вот документация по API-интерфейсу Slack Open.

Stacktrace:

E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076): Failed to handle method call
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Activity.getApplicationContext()' on a null object reference
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.pichillilorenzo.flutter_appavailability.AppAvailability.getAppPackageInfo(AppAvailability.java:93)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.pichillilorenzo.flutter_appavailability.AppAvailability.launchApp(AppAvailability.java:131)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.pichillilorenzo.flutter_appavailability.AppAvailability.onMethodCall(AppAvailability.java:57)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076): Failed to handle method call
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Activity.getApplicationContext()' on a null object reference
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.pichillilorenzo.flutter_appavailability.AppAvailability.getAppPackageInfo(AppAvailability.java:93)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.pichillilorenzo.flutter_appavailability.AppAvailability.checkAvailability(AppAvailability.java:65)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.pichillilorenzo.flutter_appavailability.AppAvailability.onMethodCall(AppAvailability.java:46)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#com.pichillilorenzo/flutter_appavailability( 2076):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/flutter ( 2076): PlatformException(error, Attempt to invoke virtual method 'android.content.Context android.app.Activity.getApplicationContext()' on a null object reference, null)
E/flutter ( 2076): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'android.content.Context android.app.Activity.getApplicationContext()' on a null object reference, null)
E/flutter ( 2076): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 2076): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter ( 2076): <asynchronous suspension>
E/flutter ( 2076): #2      AppAvailability.checkAvailability (package:flutter_appavailability/flutter_appavailability.dart:29:50)
E/flutter ( 2076): #3      LaunchSlackWidget.getApps (package:remotebingo/screen/LaunchSlackWidget.dart:21:35)
E/flutter ( 2076): <asynchronous suspension>
E/flutter ( 2076): #4      _TitleWidget.build.<anonymous closure> (package:remotebingo/screen/EndGameSuccess.dart:104:28)
E/flutter ( 2076): #5      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter ( 2076): #6      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter ( 2076): #7      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 2076): #8      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter ( 2076): #9      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter ( 2076): #10     BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter ( 2076): #11     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
E/flutter ( 2076): #12     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 2076): #13     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter ( 2076): #14     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 2076): #15     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter ( 2076): #16     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter ( 2076): #17     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 2076): #18     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 2076): #19     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 2076): #20     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 2076): #21     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 2076): #22     _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 2076): #23     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 2076): #24     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 2076): #25     _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter ( 2076): #26     _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter ( 2076): 

Может ли кто-нибудь помочь мне понять, что я здесь делаю неправильно.

...