flutter_google_cast_button 0.1.2

pub

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}

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.

android.useAndroidX=true
android.enableJetifier=true

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()
                .setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
                .build()
    }

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

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" />

4. Setup/Release android context #

Add following code into MainActivity. (Avoid context leak)

override fun onStart() {
    super.onStart()
    FlutterGoogleCastButtonPlugin.instance.initContext(this)
}

override fun onStop() {
    FlutterGoogleCastButtonPlugin.instance.disposeContext()
    releaseMediaController()
    super.onStop()
}

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)
  	GCKCastContext.setSharedInstanceWith(options)

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

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

@override
void dispose() {
  mediaRouteBloc.dispose();
  super.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.

example/README.md

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:


dependencies:
  flutter_google_cast_button: ^0.1.2

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
60
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

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' was not 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).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
bloc ^0.14.1 0.14.4 0.15.0
equatable ^0.2.3 0.2.6 0.4.0
flutter 0.0.0
flutter_bloc ^0.15.0 0.15.1 0.21.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
rxdart 0.22.1+1
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test