Giphy / giphy-flutter-sdk

Apache License 2.0
3 stars 0 forks source link

The app crashes when I load the GiphyGridView in both IOS and Android #28

Closed dancb10 closed 1 month ago

dancb10 commented 1 month ago

Below is the code I use

_getGifPanel() {
    try {
      if (_searchGifKeyword == "") {
        GiphyContentRequest searchGifs = GiphyContentRequest.search(
          mediaType: GiphyMediaType.gif,
          searchQuery: _searchGifKeyword,
        );

        return Expanded(
          child: GiphyGridView(
            content: searchGifs,
            renditionType: GiphyRendition.fixedWidth,
            theme: GiphyTheme.automaticTheme,
            onMediaSelect: (GiphyMedia media) {
              print("send gif");
            },
          ),
        );
      } else {
        GiphyContentRequest _trendingGifs = GiphyContentRequest.trendingGifs();

        return Expanded(
          child: GiphyGridView(
            content: _trendingGifs,
            renditionType: GiphyRendition.fixedWidth,
            theme: GiphyTheme.automaticTheme,
            onMediaSelect: (GiphyMedia media) {
              print("send gif");
            },
          ),
        );
      }
    } catch (e, stacktrace) {
      print("_getGifPanel: error in GiphyGridView rendering: $e");
      print("_getGifPanel: stacktrace: $stacktrace");
    }
  }

The above widget is part of a column Widget build(BuildContext context) { return Column( mainAxisSize: MainAxisSize.min, children: [ _getGifPanel[)} and the whole widget is loaded within a showModalBottomSheet

Using flutter: [✓] Flutter (Channel stable, 3.24.1, on macOS 14.6.1 23G93 darwin-arm64, locale en-GB) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 16.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.93.1) [✓] Connected device (6 available) [✓] Network resources

Getting this error: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(unregistered_view_type, A UIKitView widget is trying to create a PlatformView with an unregistered type: < com.giphyfluttersdk/gridView >, If you are the author of the PlatformView, make sure registerViewFactory is invoked. See: https://docs.flutter.dev/development/platform-integration/platform-views#on-the-platform-side-1 for more details. If you are not the author of the PlatformView, make sure to call GeneratedPluginRegistrant.register., null)

0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)

message_codecs.dart:648

1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)

platform_channel.dart:334

#2 PlatformViewsService.initUiKitView (package:flutter/src/services/platform_views.dart:248:5) platform_views.dart:248 #3 _DarwinViewState._createNewUiKitView (package:flutter/src/widgets/platform_view.dart:918:36) platform_view.dart:918
dancb10 commented 1 month ago

If i build this on physical and or simulator both ios and android it fails

dancb10 commented 1 month ago

On Android I get

A problem occurred configuring project ':giphy_flutter_sdk'.
> defaultConfig contains custom BuildConfig fields, but the feature is disabled.
dancb10 commented 1 month ago

Also: Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported. Recommendation: remove package="com.giphy.giphy_flutter_sdk" from the source AndroidManifest.xml:

dancb10 commented 1 month ago

Also ERROR: R8: Missing class kotlinx.parcelize.Parcelize (referenced from: com.giphy.sdk.analytics.models.AnalyticsEvent and 26 other contexts)

ALexanderLonsky commented 1 month ago

Hey @dancb10, That's quite unexpected behavior. Could you confirm if the example app works for you? When you tap on the search input, it should open the grid view.

I can even display it using a ModalBottomSheet, but the issue is that the bottom sheet captures all gesture events, making the grid view unscrollable. I’m not sure if we can easily resolve this soon since the grid is implemented as a platform view, relying on native iOS and Android components.

dancb10 commented 1 month ago

I did a bunch of changes within the package and my build.gradle files for android, on IOS i have not fixed it. Now it seems it loads the gridview but you really have to change multiple things in the code. I will post later what I did to fix for Android, for IOS it still crashes when I open it. The problem is that it does not even load the widget, as soon as it builds GiphyGridView it completely crashes. Happens consistently on IOS simulator, Android physical device and IOS physical device. I will look later on this. I tried with example as well, same thing happens

ALexanderLonsky commented 1 month ago

I’m sorry to hear that, but I think there might be an issue with your setup. I just created a new project from scratch, integrated the Giphy SDK, and it works as expected.

dancb10 commented 1 month ago

In order to fix this for Android I had to do the following in android/gradle.properties i added android.defaults.buildfeatures.buildconfig=true in android/build.gradle i added classpath 'com.android.tools.build:gradle:8.0.2' under buildscript/dependencies in android/gradle/wrapper/gradle-wrapper.properties i added distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip

in android/app/build.gradle i added apply plugin: 'kotlin-parcelize' under android section. I also added under dependencies implementation "org.jetbrains.kotlin:kotlin-parcelize-runtime:1.8.0"

In the package .pub-cache/hosted/pub.dev/giphy_flutter_sdk-1.0.0/android/src/main/AndroidManifest.xml I removed the package name tag. Only after doing these changes I was able to run this

dancb10 commented 1 month ago

Ok now i can see the trending and search but the problem is that the GriView is not scrollable being opened in a showModalBottomSheet

dancb10 commented 1 month ago

Oh it works if I just disable dragging on the showModalBottomSheet, everything is fine. thank you