I am using https://pub.dev/packages/flutter_inappwebview plugin as webview now, I am loading a page where a video is running, then I selecting enlarge button to make video run in full view, I am trigger below function
onEnterFullscreen: (controller) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
},
onExitFullscreen: (controller) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
},
But the problem is that, now when my screen rotated to landscape, and when I am again rotating to opposite landscape, it is not rotating where as the same media player in Chrome which is in full view, auto rotate to any landscape mode. (either rotation is on/off).
Note- I have enable the javascript.
What I am getting- I successfully manage that when I used click video play enlarge button then video now runs in landscape and I am dismissing the full view, I am coming back to portrait mode. All fine here.
What I want- When the Video is running in the landscape mode then is it fixed in the landscape.right and when I am rotating device then is not coming to landscape.left. And I have seen in Chrome that this is working fine either auto rotation is on or off.
Here is the full code-
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static const mainUrl =
"https://www.hotstar.com/in/sports/cricket/indian-premier-league/sunrisers-hyderabad-vs-kings-xi-punjab-m701672/match-clips/highlights-srh-reign-over-kxip/1540002246";
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Test Browser',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
InAppWebViewController controller;
String url = MyApp.mainUrl;
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: Text("Test Browser"),
),
body: Column(children: [
Expanded(
child: InAppWebView(
initialUrl: url,
onWebViewCreated: (InAppWebViewController webViewController) {
controller = webViewController;
},
onEnterFullscreen: (controller) async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
},
onExitFullscreen: (controller) async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
},
initialOptions: InAppWebViewGroupOptions(
android: AndroidInAppWebViewOptions(
disableDefaultErrorPage: true,
),
crossPlatform: InAppWebViewOptions(
mediaPlaybackRequiresUserGesture: false,
horizontalScrollBarEnabled: false,
// userAgent: userAgent,
verticalScrollBarEnabled: false),
),
androidOnPermissionRequest: (InAppWebViewController controller,
String origin, List<String> resources) async {
return PermissionRequestResponse(
resources: resources,
action: PermissionRequestResponseAction.GRANT);
},
),
),
Container(
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero,
child: Icon(Icons.refresh),
onPressed: () {
if (controller != null) {
controller.reload();
}
},
),
MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero,
child: Icon(Icons.share),
onPressed: () async {},
),
MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero,
child: Icon(Icons.arrow_back),
onPressed: () => _handleBack(context),
),
MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero,
child: Icon(Icons.arrow_forward),
onPressed: () {
if (controller != null) {
controller.goForward();
}
},
),
],
),
),
]),
);
}
Future<bool> _handleBack(context) async {
var status = await controller.canGoBack();
var _exitMsg = 'Do you want to exit ?';
if (status) {
controller.goBack();
} else {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(_exitMsg),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('No'),
),
FlatButton(
onPressed: () => SystemNavigator.pop(),
child: Text('Yes'),
),
],
));
}
return false;
}
}