braze-inc / braze-flutter-sdk

Public repo for the Braze Flutter SDK
Other
15 stars 29 forks source link

Example Code Has a Static Compilation Error #32

Closed zkjxx1548 closed 1 year ago

zkjxx1548 commented 1 year ago

Background:

Flutter 2.10.5 braze_plugin 2.6.1 example code: https://github.com/braze-inc/braze-flutter-sdk/commit/5276be6c1ce7ec53219e04b4eede0f71ebed1e4f#diff-72fd825ad17ce7800a2078e06f0dff1e12836ee59760465e78d9a5d222cebd15:~:text=inAppMessage%2C%20prefix%3A%20%22STREAM%22)%3B-,return,-%3B

_braze?.subscribeToInAppMessages((BrazeInAppMessage inAppMessage) {
      return;
});

# It will throw **The return value is missing after 'return'.**
OlegLozovyi commented 1 year ago

contentCardsStreamSubscription = _brazePlugin.subscribeToContentCards((cards) => (){});

//for any reason =>(){} empty funcrtion or not empty works same. on event function its not called anyway by the braze.

then add a listener on subscription itself

contentCardsStreamSubscription.onData((data) {
  if(data is List<BrazeContentCard>){
    _onNewData(data);
  }
});

something like this helped me. But on IoS the subscription is not starting for some reason.

zkjxx1548 commented 1 year ago

@OlegLozovyi Thanks for you code. @hokstuff Still hope braze flutter team will update the example code soon.

hokstuff commented 1 year ago

Hi @zkjxx1548,

We are unable to reproduce this issue in the sample app using both Flutter 2.10.5 and the latest Flutter version 3.3.8. Can you try to restart the analysis server and/or clear any cache for your IDE and try again? And is it accurate to say that this is just a warning and that our sample app still compiles and runs on your computer?

zkjxx1548 commented 1 year ago

@hokstuff Thanks for reply. I download the example code and open it in my local. It really has no error.

But you can reproduce the error by this way:

  1. create a new flutter repo.
  2. add dependency in yaml

    dependencies:
    flutter:
    sdk: flutter
    
    # The following adds the Cupertino Icons font to your application.
    # Use with the CupertinoIcons class for iOS style icons.
    cupertino_icons: ^1.0.2
    braze_plugin: ^2.6.1
  3. use example code in any dart file

    class _MyHomePageState extends State<MyHomePage> {
    int _counter = 0;
    
    @override
    void initState() {
    super.initState();
    
    BrazePlugin().subscribeToInAppMessages((BrazeInAppMessage inAppMessage) {
      return; // dart will return error: The return value is missing after 'return'.(dart return_without_value)
    });
    }
    }

you will see the dart error. The return value is missing after 'return'

hokstuff commented 1 year ago

Thanks for verifying the sample app in the codebase. It is odd that you are seeing an error in your app but not in the sample app in our Flutter codebase. The API's parameter passes in a Function type, so it's interesting that the compiler says it expects a value.

If you aren't able to find a workaround and this is blocking your development, please send an email to support@braze.com with more details on your integration to figure out what is happening in your application. Since there are no direct action items and the code in the sample application is working as expected without errors, I will close out this issue.

Thank you!

zkjxx1548 commented 1 year ago

I am very curious whether you have seen the error report through the reproduction steps I provided.

And the listen function's parameter type is void Function(BrazeInAppMessage)?. But the type of parameter passed in by subscribeToInAppMessages is Function Function(BrazeInAppMessage)

Looking forward your reply.

hokstuff commented 1 year ago

Hi @zkjxx1548,

Thanks for getting back on this. We have been able to reproduce based on your steps above. If we updated the braze_plugin APIs to be the following, does that fix your issue (it follows the syntax described here from this comment):

StreamSubscription subscribeToInAppMessages(void Function(BrazeInAppMessage) onEvent) {
    // implementation code
}

StreamSubscription subscribeToContentCards(void Function(List<BrazeContentCard>) onEvent) {
    // implementation code
}
hokstuff commented 1 year ago

Hi @zkjxx1548,

We have released version 3.0.0 which updates the syntax for these two APIs to the proposed method signatures above.

Thanks!