Basic CastButton implementation;

Basic CastIcon implementation;
Added images from: https://developers.google.com/cast/docs/developers#download_cast_icons
This commit is contained in:
gianlucaparadise 2019-11-09 10:00:49 +01:00
parent 344c5b6b8a
commit 4af81e646d
11 changed files with 279 additions and 3 deletions

22
assets/ic_cast0_24dp.svg Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.2.2 (9983) - http://www.bohemiancoding.com/sketch -->
<title>ic_cast0_black_24dp</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="ic_cast0_black_24dp" sketch:type="MSArtboardGroup">
<g id="ic_remove_circle_white_24dp" sketch:type="MSLayerGroup">
<path d="M1,18 L1,21 L4,21 C4,19.34 2.66,18 1,18 L1,18 Z" id="Path" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M1,14 L1,16 C3.76,16 6,18.24 6,21 L8,21 C8,17.13 4.87,14 1,14 L1,14 Z" id="Path" opacity="0.3" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M1,10 L1,12 C5.97,12 10,16.03 10,21 L12,21 C12,14.92 7.07,10 1,10 L1,10 Z" id="Path" opacity="0.3" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M21,3 L3,3 C1.9,3 1,3.9 1,5 L1,8 L3,8 L3,5 L21,5 L21,19 L14,19 L14,21 L21,21 C22.1,21 23,20.1 23,19 L23,5 C23,3.9 22.1,3 21,3 L21,3 Z" id="Path" fill="#000000" sketch:type="MSShapeGroup"></path>
<rect id="bounds" sketch:type="MSShapeGroup" x="0" y="0" width="24" height="24"></rect>
</g>
</g>
<g id="assets" sketch:type="MSLayerGroup" transform="translate(-240.000000, -106.000000)">
<g id="64px" transform="translate(0.000000, 114.000000)"></g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

22
assets/ic_cast1_24dp.svg Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.2.2 (9983) - http://www.bohemiancoding.com/sketch -->
<title>ic_cast1_black_24dp</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="ic_cast1_black_24dp" sketch:type="MSArtboardGroup">
<g id="ic_remove_circle_white_24dp" sketch:type="MSLayerGroup">
<path d="M1,18 L1,21 L4,21 C4,19.34 2.66,18 1,18 L1,18 Z" id="Path" opacity="0.3" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M1,14 L1,16 C3.76,16 6,18.24 6,21 L8,21 C8,17.13 4.87,14 1,14 L1,14 Z" id="Path" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M1,10 L1,12 C5.97,12 10,16.03 10,21 L12,21 C12,14.92 7.07,10 1,10 L1,10 Z" id="Path" opacity="0.3" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M21,3 L3,3 C1.9,3 1,3.9 1,5 L1,8 L3,8 L3,5 L21,5 L21,19 L14,19 L14,21 L21,21 C22.1,21 23,20.1 23,19 L23,5 C23,3.9 22.1,3 21,3 L21,3 Z" id="cast" fill="#000000" sketch:type="MSShapeGroup"></path>
<rect id="bounds" sketch:type="MSShapeGroup" x="0" y="0" width="24" height="24"></rect>
</g>
</g>
<g id="assets" sketch:type="MSLayerGroup" transform="translate(-272.000000, -106.000000)">
<g id="64px" transform="translate(0.000000, 114.000000)"></g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

22
assets/ic_cast2_24dp.svg Normal file
View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.2.2 (9983) - http://www.bohemiancoding.com/sketch -->
<title>ic_cast2_black_24dp</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="ic_cast2_black_24dp" sketch:type="MSArtboardGroup">
<g id="ic_remove_circle_white_24dp" sketch:type="MSLayerGroup">
<path d="M1,18 L1,21 L4,21 C4,19.34 2.66,18 1,18 L1,18 Z" id="Path" opacity="0.3" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M1,14 L1,16 C3.76,16 6,18.24 6,21 L8,21 C8,17.13 4.87,14 1,14 L1,14 Z" id="Path" opacity="0.3" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M1,10 L1,12 C5.97,12 10,16.03 10,21 L12,21 C12,14.92 7.07,10 1,10 L1,10 Z" id="Path" fill="#000000" sketch:type="MSShapeGroup"></path>
<path d="M21,3 L3,3 C1.9,3 1,3.9 1,5 L1,8 L3,8 L3,5 L21,5 L21,19 L14,19 L14,21 L21,21 C22.1,21 23,20.1 23,19 L23,5 C23,3.9 22.1,3 21,3 L21,3 Z" id="cast" fill="#000000" sketch:type="MSShapeGroup"></path>
<rect id="bounds" sketch:type="MSShapeGroup" x="0" y="0" width="24" height="24"></rect>
</g>
</g>
<g id="assets" sketch:type="MSLayerGroup" transform="translate(-304.000000, -106.000000)">
<g id="64px" transform="translate(0.000000, 114.000000)"></g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

19
assets/ic_cast_24dp.svg Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.2.2 (9983) - http://www.bohemiancoding.com/sketch -->
<title>ic_cast_black_24dp</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="ic_cast_black_24dp" sketch:type="MSArtboardGroup">
<g id="ic_remove_circle_white_24dp" sketch:type="MSLayerGroup">
<path d="M1,18 L1,21 L4,21 C4,19.34 2.66,18 1,18 L1,18 Z M1,14 L1,16 C3.76,16 6,18.24 6,21 L8,21 C8,17.13 4.87,14 1,14 L1,14 Z M1,10 L1,12 C5.97,12 10,16.03 10,21 L12,21 C12,14.92 7.07,10 1,10 L1,10 Z M21,3 L3,3 C1.9,3 1,3.9 1,5 L1,8 L3,8 L3,5 L21,5 L21,19 L14,19 L14,21 L21,21 C22.1,21 23,20.1 23,19 L23,5 C23,3.9 22.1,3 21,3 L21,3 Z" id="cast" fill="#000000" sketch:type="MSShapeGroup"></path>
<rect id="bounds" sketch:type="MSShapeGroup" x="0" y="0" width="24" height="24"></rect>
</g>
</g>
<g id="assets" sketch:type="MSLayerGroup" transform="translate(-208.000000, -106.000000)">
<g id="64px" transform="translate(0.000000, 114.000000)"></g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg"
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.2.2 (9983) - http://www.bohemiancoding.com/sketch -->
<title>ic_cast_connected_black_24dp</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="ic_cast_connected_black_24dp" sketch:type="MSArtboardGroup">
<g id="ic_remove_circle_white_24dp" sketch:type="MSLayerGroup">
<path d="M1,18 L1,21 L4,21 C4,19.34 2.66,18 1,18 L1,18 Z M1,14 L1,16 C3.76,16 6,18.24 6,21 L8,21 C8,17.13 4.87,14 1,14 L1,14 Z M19,7 L5,7 L5,8.63 C8.96,9.91 12.09,13.04 13.37,17 L19,17 L19,7 L19,7 Z M1,10 L1,12 C5.97,12 10,16.03 10,21 L12,21 C12,14.92 7.07,10 1,10 L1,10 Z M21,3 L3,3 C1.9,3 1,3.9 1,5 L1,8 L3,8 L3,5 L21,5 L21,19 L14,19 L14,21 L21,21 C22.1,21 23,20.1 23,19 L23,5 C23,3.9 22.1,3 21,3 L21,3 Z" id="cast-on" fill="#000000" sketch:type="MSShapeGroup"></path>
<rect id="bounds" sketch:type="MSShapeGroup" x="0" y="0" width="24" height="24"></rect>
</g>
</g>
<g id="assets" sketch:type="MSLayerGroup" transform="translate(-336.000000, -106.000000)">
<g id="64px" transform="translate(0.000000, 114.000000)"></g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_cast_framework/cast/CastContext.dart';
import 'package:flutter_cast_framework/cast/widget/CastButton.dart';
import 'package:flutter_cast_framework/flutter_cast_framework.dart';
void main() => runApp(MyApp());
@ -32,7 +33,12 @@ class _MyAppState extends State<MyApp> {
title: const Text('Cast plugin example app'),
),
body: Center(
child: Text('Cast State: $_castState'),
child: Column(
children: [
Text('Cast State: $_castState'),
CastButton()
],
)
),
),
);

View file

@ -29,6 +29,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
cupertino_icons:
dependency: "direct main"
description:
@ -48,6 +55,13 @@ packages:
relative: true
source: path
version: "0.0.1"
flutter_svg:
dependency: transitive
description:
name: flutter_svg
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.3"
flutter_test:
dependency: "direct dev"
description: flutter
@ -74,6 +88,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
path_drawing:
dependency: transitive
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
pedantic:
dependency: transitive
description:
@ -81,6 +109,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
@ -149,5 +184,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks:
dart: ">=2.2.2 <3.0.0"
dart: ">=2.4.0 <3.0.0"
flutter: ">=1.5.9-pre.94 <2.0.0"

View file

@ -0,0 +1,12 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_cast_framework/cast/widget/CastIcon.dart';
class CastButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
child: CastIcon(),
onTap: () => debugPrint("Clicked"),
);
}
}

View file

@ -0,0 +1,64 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_cast_framework/cast/CastContext.dart';
import 'package:flutter_cast_framework/flutter_cast_framework.dart';
import 'package:flutter_svg/flutter_svg.dart';
class CastIcon extends StatefulWidget {
@override
_CastIconState createState() => _CastIconState();
}
class _CastIconState extends State<CastIcon> {
static const _connectingAssetNameList = {
2: "assets/ic_cast_24dp.svg",
3: "assets/ic_cast1_24dp.svg",
4: "assets/ic_cast_connected_24dp.svg",
};
CastState _castState = CastState.unavailable;
CastState get castState => _castState;
@override
void initState() {
super.initState();
FlutterCastFramework.castContext.state.addListener(_onCastStateChanged);
}
void _onCastStateChanged() {
setState(() {
_castState = FlutterCastFramework.castContext.state.value;
});
}
Widget getEmpty() => Container();
Widget getButton() {
int stateIndex = FlutterCastFramework.castContext.state.value.index;
String assetName = _connectingAssetNameList[stateIndex];
return SvgPicture.asset(
assetName,
package: 'flutter_cast_framework',
semanticsLabel: 'Cast Button',
);
}
@override
Widget build(BuildContext context) {
switch (_castState) {
case CastState.unavailable:
return getEmpty();
case CastState.unconnected:
case CastState.connecting:
case CastState.connected:
return getButton();
case CastState.default_state:
default:
debugPrint("State not handled: $_castState");
return getEmpty();
}
}
}

View file

@ -29,11 +29,25 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_svg:
dependency: "direct main"
description:
name: flutter_svg
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.3"
flutter_test:
dependency: "direct dev"
description: flutter
@ -60,6 +74,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
path_drawing:
dependency: transitive
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
pedantic:
dependency: transitive
description:
@ -67,6 +95,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
@ -135,5 +170,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks:
dart: ">=2.2.2 <3.0.0"
dart: ">=2.4.0 <3.0.0"
flutter: ">=1.5.9-pre.94 <2.0.0"

View file

@ -10,6 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_svg: ^0.14.3
dev_dependencies:
flutter_test:
@ -39,6 +40,9 @@ flutter:
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
assets:
- assets/
# To add custom fonts to your plugin package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a