flutter_google_cast_button

Last updated:

0 purchases

flutter_google_cast_button Image
flutter_google_cast_button Images
Add to Cart

Description:

flutter google cast button

flutter_google_cast_button #
A Flutter plugin provides a cast button widget and sync cast state with it.
Use this package as a library #
Install #
1. Depend on it #
Add this to your package's pubspec.yaml file:
dependencies:
flutter_google_cast_button: {last_version}
copied to clipboard
2. Install it #
You can install packages from the command line:
with pub:
$ pub get
copied to clipboard
with Flutter:
$ flutter packages get
copied to clipboard
Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.
Android Settings #
0. Support AndroidX #
Add following properties to gradle.properties.
android.useAndroidX=true
android.enableJetifier=true
copied to clipboard
1. Add google cast dependency #
Add play-services-cast-framework dependency into android/build.gradle
implementation "com.google.android.gms:play-services-cast-framework:16.2.0"
copied to clipboard
2. Create CastOptionsProvider class for configure cast library #
class DefaultCastOptionsProvider : OptionsProvider {
override fun getCastOptions(context: Context): CastOptions {
return CastOptions.Builder()
.setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
.build()
}

override fun getAdditionalSessionProviders(context: Context): List<SessionProvider>? {
return null
}
}
copied to clipboard
3. Add options provider metadata #
Add meta-data to project's AndroidManifest.xml
<meta-data
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="github.showang.flutter_google_cast_button_example.DefaultCastOptionsProvider" />
copied to clipboard
4. Updating in live cycle #
Add following code into MainActivity for update new state when resume.
override fun onResume() {
super.onResume()
FlutterGoogleCastButtonPlugin.instance?.onResume()
}
copied to clipboard
iOS settings #


Get packages
Run pod install before open Xcode.


Initializing CastContext when application didFinishLaunching. EX:


let kReceiverAppID = kGCKDefaultMediaReceiverApplicationID
let kDebugLoggingEnabled = true

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
let criteria = GCKDiscoveryCriteria(applicationID: kReceiverAppID)
let options = GCKCastOptions(discoveryCriteria: criteria)
GCKCastContext.setSharedInstanceWith(options)

// Enable logger.
GCKLogger.sharedInstance().delegate = self

GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
copied to clipboard
Usage in Dart #
1. Import it #
Package paths relative with button widget.
import 'package:flutter_google_cast_button/bloc_media_route.dart';
import 'package:flutter_google_cast_button/cast_button_widget.dart';
copied to clipboard
2. Init MediaRouteBloc #
Initialize/Dispose bloc when scope of widget's life cycle for saving/release state.
MediaRouteBloc _mediaRouteBloc;

@override
void initState() {
super.initState();
mediaRouteBloc = MediaRouteBloc();
}

@override
void dispose() {
mediaRouteBloc.dispose();
super.dispose();
}

copied to clipboard
3. Provide MediaRouteBloc #
Using bloc provider or any injection frameworks what you prefer.
BlocProvider Example
Provide a bloc.
var widgetTree = new BlocProvider(
bloc: _mediaRouteBloc,
child: WidgetDependentWithBloc(),
);
copied to clipboard
4. Use the CastButtonWidget #
If you are using BlocProvider.
var _castButtonWidget = new CastButtonWidget();
copied to clipboard
else, inject the bloc for widget.
var _castButtonWidget = new CastButtonWidget(bloc: _mediaRouteBloc);
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.