flutter_google_cast_button 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 61


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:

  flutter_google_cast_button: {last_version}

2. Install it #

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

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.


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"

2. Create CastOptionsProvider class for configure cast library #

class DefaultCastOptionsProvider : OptionsProvider {
    override fun getCastOptions(context: Context): CastOptions {
        return CastOptions.Builder()

    override fun getAdditionalSessionProviders(context: Context): List<SessionProvider>? {
        return null

3. Add options provider metadata #

Add meta-data to project's AndroidManifest.xml

    android:value="github.showang.flutter_google_cast_button_example.DefaultCastOptionsProvider" />

4. Updating in live cycle #

Add following code into MainActivity for update new state when resume.

override fun onResume() {

iOS settings #

  1. Get packages Run pod install before open Xcode.

  2. 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)

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

    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)

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';

2. Init MediaRouteBloc #

Initialize/Dispose bloc when scope of widget's life cycle for saving/release state.

MediaRouteBloc _mediaRouteBloc;

void initState() {
  mediaRouteBloc = MediaRouteBloc();

void dispose() {

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(),

4. Use the CastButtonWidget #

If you are using BlocProvider.

var _castButtonWidget = new CastButtonWidget();

else, inject the bloc for widget.

var _castButtonWidget = new CastButtonWidget(bloc: _mediaRouteBloc);  

0.0.1 #

  • TODO: Describe initial release.


flutter_google_cast_button_example #

Demonstrates how to use the flutter_google_cast_button plugin.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_google_cast_button: ^0.2.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_google_cast_button/flutter_google_cast_button.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Fix lib/cast_button_widget.dart. (-25 points)

Analysis of lib/cast_button_widget.dart failed with 1 error:

line 65 col 54: 2 positional argument(s) expected, but 1 found.

Fix lib/bloc_media_route.dart. (-0.50 points)

Analysis of lib/bloc_media_route.dart reported 1 hint:

line 31 col 3: The class 'Stream' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Format lib/flutter_google_cast_button.dart.

Run flutter format to format lib/flutter_google_cast_button.dart.

Maintenance issues and suggestions

Support latest dependencies. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (bloc, equatable, flutter_bloc).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
bloc ^0.14.1 0.14.4 3.0.0
equatable ^0.2.3 0.2.6 1.1.0
flutter 0.0.0
flutter_bloc ^0.15.0 0.15.1 3.2.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
rxdart 0.22.6 0.23.1
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies