Skip to content

Commit bfce5a7

Browse files
ditmanEgor
authored andcommitted
[image_picker] Add web support to the example app. (flutter#2816)
1 parent 2f7c189 commit bfce5a7

File tree

9 files changed

+75
-4
lines changed

9 files changed

+75
-4
lines changed

packages/image_picker/image_picker/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.7+1
2+
3+
* Add web support to the example app.
4+
15
## 0.6.7
26

37
* Utilize the new platform_interface package.

packages/image_picker/image_picker/example/lib/main.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ class _MyHomePageState extends State<MyHomePage> {
5252
Future<void> _playVideo(PickedFile file) async {
5353
if (file != null && mounted) {
5454
await _disposeVideoController();
55-
_controller = VideoPlayerController.file(File(file.path));
55+
if (kIsWeb) {
56+
_controller = VideoPlayerController.network(file.path);
57+
} else {
58+
_controller = VideoPlayerController.file(File(file.path));
59+
}
5660
await _controller.setVolume(1.0);
5761
await _controller.initialize();
5862
await _controller.setLooping(true);
@@ -139,7 +143,13 @@ class _MyHomePageState extends State<MyHomePage> {
139143
return retrieveError;
140144
}
141145
if (_imageFile != null) {
142-
return Image.file(File(_imageFile.path));
146+
if (kIsWeb) {
147+
// Why network?
148+
// See https://pub.dev/packages/image_picker#getting-ready-for-the-web-platform
149+
return Image.network(_imageFile.path);
150+
} else {
151+
return Image.file(File(_imageFile.path));
152+
}
143153
} else if (_pickImageError != null) {
144154
return Text(
145155
'Pick image error: $_pickImageError',
@@ -180,7 +190,7 @@ class _MyHomePageState extends State<MyHomePage> {
180190
title: Text(widget.title),
181191
),
182192
body: Center(
183-
child: defaultTargetPlatform == TargetPlatform.android
193+
child: !kIsWeb && defaultTargetPlatform == TargetPlatform.android
184194
? FutureBuilder<void>(
185195
future: retrieveLostData(),
186196
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {

packages/image_picker/image_picker/example/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies:
99
flutter_plugin_android_lifecycle: ^1.0.2
1010
image_picker:
1111
path: ../
12+
image_picker_for_web: ^0.1.0
1213

1314
dev_dependencies:
1415
flutter_driver:
Loading
Loading
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
6+
<meta name="description" content="An example of the image_picker on the web.">
7+
8+
<!-- iOS meta tags & icons -->
9+
<meta name="apple-mobile-web-app-capable" content="yes">
10+
<meta name="apple-mobile-web-app-status-bar-style" content="black">
11+
<meta name="apple-mobile-web-app-title" content="example">
12+
<link rel="apple-touch-icon" href="icons/Icon-192.png">
13+
14+
<!-- Favicon -->
15+
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
16+
17+
<title>url_launcher web example</title>
18+
<link rel="manifest" href="manifest.json">
19+
</head>
20+
<body>
21+
<!-- This script installs service_worker.js to provide PWA functionality to
22+
application. For more information, see:
23+
https://developers.google.com/web/fundamentals/primers/service-workers -->
24+
<!-- <script>
25+
if ('serviceWorker' in navigator) {
26+
window.addEventListener('load', function () {
27+
navigator.serviceWorker.register('flutter_service_worker.js');
28+
});
29+
}
30+
</script> -->
31+
<script src="main.dart.js" type="application/javascript"></script>
32+
</body>
33+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "image_picker example",
3+
"short_name": "image_picker",
4+
"start_url": ".",
5+
"display": "minimal-ui",
6+
"background_color": "#0175C2",
7+
"theme_color": "#0175C2",
8+
"description": "An example of the image_picker on the web.",
9+
"orientation": "portrait-primary",
10+
"prefer_related_applications": false,
11+
"icons": [
12+
{
13+
"src": "icons/Icon-192.png",
14+
"sizes": "192x192",
15+
"type": "image/png"
16+
},
17+
{
18+
"src": "icons/Icon-512.png",
19+
"sizes": "512x512",
20+
"type": "image/png"
21+
}
22+
]
23+
}

packages/image_picker/image_picker/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: image_picker
22
description: Flutter plugin for selecting images from the Android and iOS image
33
library, and taking new pictures with the camera.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker
5-
version: 0.6.7
5+
version: 0.6.7+1
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)