Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add webview and video widgets to the sample app #2355

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
Expand All @@ -23,6 +24,8 @@
// import 'package:sqflite_common_ffi/sqflite_ffi.dart';
// import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';
import 'package:universal_platform/universal_platform.dart';
import 'package:video_player/video_player.dart';
import 'package:webview_flutter/webview_flutter.dart';

import 'auto_close_screen.dart';
import 'drift/connection/connection.dart';
Expand Down Expand Up @@ -207,6 +210,24 @@
'Long press a button to see more information. (hover on web)'),
),
),
Text('webview_flutter:'),

Check notice on line 213 in flutter/example/lib/main.dart

View workflow job for this annotation

GitHub Actions / analyze / analyze

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.
SizedBox.fromSize(
size: Size(400, 200),

Check notice on line 215 in flutter/example/lib/main.dart

View workflow job for this annotation

GitHub Actions / analyze / analyze

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.
child: WebViewWidget(
controller: WebViewController()
..loadRequest(Uri.parse('https://sentry.io/')))),
Text('flutter_inappwebview:'),

Check notice on line 219 in flutter/example/lib/main.dart

View workflow job for this annotation

GitHub Actions / analyze / analyze

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.
SizedBox.fromSize(
size: Size(400, 200),

Check notice on line 221 in flutter/example/lib/main.dart

View workflow job for this annotation

GitHub Actions / analyze / analyze

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.
child: InAppWebView(
initialUrlRequest:
URLRequest(url: WebUri('https://sentry.io/')),
)),
Text('video:'),

Check notice on line 226 in flutter/example/lib/main.dart

View workflow job for this annotation

GitHub Actions / analyze / analyze

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.
SizedBox.fromSize(
size: Size(400, 200),

Check notice on line 228 in flutter/example/lib/main.dart

View workflow job for this annotation

GitHub Actions / analyze / analyze

Use 'const' with the constructor to improve performance.

Try adding the 'const' keyword to the constructor invocation. See https://dart.dev/diagnostics/prefer_const_constructors to learn more about this problem.
child: _BumbleBeeRemoteVideo(),
),
TooltipButton(
onPressed: () => navigateToAutoCloseScreen(context),
text:
Expand Down Expand Up @@ -1120,3 +1141,138 @@
}
return a - 1;
}

// https://pub.dev/packages/video_player/example
class _BumbleBeeRemoteVideo extends StatefulWidget {
@override
_BumbleBeeRemoteVideoState createState() => _BumbleBeeRemoteVideoState();
}

class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
late VideoPlayerController _controller;

@override
void initState() {
super.initState();
_controller = VideoPlayerController.networkUrl(
Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'),
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
);

_controller.addListener(() {
setState(() {});
});
_controller.setLooping(true);
_controller.initialize();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Container(padding: const EdgeInsets.only(top: 20.0)),
const Text('With remote mp4'),
Container(
padding: const EdgeInsets.all(20),
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
VideoPlayer(_controller),
_ControlsOverlay(controller: _controller),
VideoProgressIndicator(_controller, allowScrubbing: true),
],
),
),
),
],
),
);
}
}

// https://pub.dev/packages/video_player/example
class _ControlsOverlay extends StatelessWidget {
const _ControlsOverlay({required this.controller});

static const List<double> _examplePlaybackRates = <double>[
0.25,
0.5,
1.0,
1.5,
2.0,
3.0,
5.0,
10.0,
];

final VideoPlayerController controller;

@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
AnimatedSwitcher(
duration: const Duration(milliseconds: 50),
reverseDuration: const Duration(milliseconds: 200),
child: controller.value.isPlaying
? const SizedBox.shrink()
: const ColoredBox(
color: Colors.black26,
child: Center(
child: Icon(
Icons.play_arrow,
color: Colors.white,
size: 100.0,
semanticLabel: 'Play',
),
),
),
),
GestureDetector(
onTap: () {
controller.value.isPlaying ? controller.pause() : controller.play();
},
),
Align(
alignment: Alignment.topRight,
child: PopupMenuButton<double>(
initialValue: controller.value.playbackSpeed,
tooltip: 'Playback speed',
onSelected: (double speed) {
controller.setPlaybackSpeed(speed);
},
itemBuilder: (BuildContext context) {
return <PopupMenuItem<double>>[
for (final double speed in _examplePlaybackRates)
PopupMenuItem<double>(
value: speed,
child: Text('${speed}x'),
)
];
},
child: Padding(
padding: const EdgeInsets.symmetric(
// Using less vertical padding as the text is also longer
// horizontally, so it feels like it would need more spacing
// horizontally (matching the aspect ratio of the video).
vertical: 12,
horizontal: 16,
),
child: Text('${controller.value.playbackSpeed}x'),
),
),
),
],
);
}
}
3 changes: 3 additions & 0 deletions flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ dependencies:
http: ^1.0.0
hive: any # This gets constrained by `sentry_hive`
sqlite3_flutter_libs: ^0.5.0
flutter_inappwebview: ^6.1.5
webview_flutter: ^4.10.0
video_player: ^2.9.2

dev_dependencies:
flutter_lints: ^2.0.0
Expand Down
Loading