Video demo is unsupported on simulator (#13333)

* Video demo is unsupported on simulator

Display a message stating this.

* Address review
This commit is contained in:
Sigurd Meldgaard
2017-12-05 13:39:24 +01:00
committed by GitHub
parent b46d79041a
commit 2352e31f4e
2 changed files with 36 additions and 17 deletions

View File

@@ -3,9 +3,11 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:device_info/device_info.dart';
// TODO(sigurdm): These should not be stored here.
const String butterflyUri =
@@ -348,6 +350,12 @@ class VideoDemo extends StatefulWidget {
_VideoDemoState createState() => new _VideoDemoState();
}
final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
Future<bool> isIOSSimulator() async {
return Platform.isIOS && !(await deviceInfoPlugin.iosInfo).isPhysicalDevice;
}
class _VideoDemoState extends State<VideoDemo>
with SingleTickerProviderStateMixin {
final VideoPlayerController butterflyController = new VideoPlayerController(
@@ -359,6 +367,7 @@ class _VideoDemoState extends State<VideoDemo>
final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
final Completer<Null> connectedCompleter = new Completer<Null>();
bool isSupported = true;
@override
void initState() {
@@ -375,6 +384,9 @@ class _VideoDemoState extends State<VideoDemo>
initController(butterflyController);
initController(beeController);
isIOSSimulator().then((bool result) {
isSupported = !result;
});
}
@override
@@ -391,24 +403,30 @@ class _VideoDemoState extends State<VideoDemo>
appBar: new AppBar(
title: const Text('Videos'),
),
body: new ConnectivityOverlay(
child: new ListView(
children: <Widget>[
new VideoCard(
title: 'Butterfly',
subtitle: '… flutters by',
controller: butterflyController,
body: (isSupported)
? new ConnectivityOverlay(
child: new ListView(
children: <Widget>[
new VideoCard(
title: 'Butterfly',
subtitle: '… flutters by',
controller: butterflyController,
),
new VideoCard(
title: 'Bee',
subtitle: '… gently buzzing',
controller: beeController,
),
],
),
connectedCompleter: connectedCompleter,
scaffoldKey: scaffoldKey,
)
: const Center(
child: const Text(
'The video demo is not supported on the iOS Simulator.',
),
),
new VideoCard(
title: 'Bee',
subtitle: '… gently buzzing',
controller: beeController,
),
],
),
connectedCompleter: connectedCompleter,
scaffoldKey: scaffoldKey,
),
);
}
}

View File

@@ -3,6 +3,7 @@ dependencies:
flutter:
sdk: flutter
collection: 1.14.3
device_info: 0.0.5
intl: 0.15.2
connectivity: 0.1.0
string_scanner: 1.0.2