felnanuke2 / flutter_google_cast

BSD 3-Clause "New" or "Revised" License
4 stars 4 forks source link

How to proper initialize? #9

Open MigAlex opened 3 months ago

MigAlex commented 3 months ago

At the readme file above initPlatformState() there is sth like: GoogleCast.instance.initialize(); but there is no such class like GoogleCast under the package. Is there any alternative approach?

felnanuke2 commented 3 months ago

Hi there,

Thank you for pointing out the issue in the documentation. You are correct, the documentation is outdated. To initialize the platform state, you need to use the following method:

Future<void> initPlatformState() async {
  const appId = GoogleCastDiscoveryCriteria.kDefaultApplicationId;
  GoogleCastOptions? options;
  if (Platform.isIOS) {
    options = IOSGoogleCastOptions(
      GoogleCastDiscoveryCriteriaInitialize.initWithApplicationID(appId),
    );
  } else if (Platform.isAndroid) {
    options = GoogleCastOptionsAndroid(
      appId: appId,
    );
  }
  GoogleCastContext.instance.setSharedInstanceWithOptions(options!);
}

The key part is to use GoogleCastContext.instance.setSharedInstanceWithOptions to set up the Google Cast context with the appropriate options based on the platform (iOS or Android).

I apologize for any confusion caused by the outdated documentation. We will update the documentation soon to reflect this change.

MigAlex commented 3 months ago

Hey, thanks for reply :)

If there is chance for the answer I'd like to ask about 'GoogleCastContext.instance.setSharedInstanceWithOptions(options!)' I fetched your example and hence signature of that part is Future<bool> I did in initPlatformState():

  final x = await GoogleCastContext.instance.setSharedInstanceWithOptions(options!);
    debugPrint('is it set up: $x');

but basically I didn't receive any return value. Overall, what I'm trying to do is getting information whether integration setup is working without active chromecast device around. So basically my question are:

Am working with Flutter 3.22 and Dart 3.4.0 and aiming for Android Devices.