forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_picker.dart
More file actions
executable file
·72 lines (60 loc) · 1.96 KB
/
image_picker.dart
File metadata and controls
executable file
·72 lines (60 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
/// Specifies the source where the picked image should come from.
enum ImageSource {
/// Opens up the device camera, letting the user to take a new picture.
camera,
/// Opens the user's photo gallery.
gallery,
}
class ImagePicker {
static const MethodChannel _channel =
const MethodChannel('plugins.flutter.io/image_picker');
/// Returns a [File] object pointing to the image that was picked.
///
/// The [source] argument controls where the image comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
///
/// If specified, the image will be at most [maxWidth] wide and
/// [maxHeight] tall. Otherwise the image will be returned at it's
/// original width and height.
static Future<File> pickImage({
@required ImageSource source,
double maxWidth,
double maxHeight,
}) async {
assert(source != null);
if (maxWidth != null && maxWidth < 0) {
throw new ArgumentError.value(maxWidth, 'maxWidth cannot be negative');
}
if (maxHeight != null && maxHeight < 0) {
throw new ArgumentError.value(maxHeight, 'maxHeight cannot be negative');
}
final String path = await _channel.invokeMethod(
'pickImage',
<String, dynamic>{
'source': source.index,
'maxWidth': maxWidth,
'maxHeight': maxHeight,
},
);
return path == null ? null : new File(path);
}
static Future<File> pickVideo({
@required ImageSource source,
}) async {
assert(source != null);
final String path = await _channel.invokeMethod(
'pickVideo',
<String, dynamic>{
'source': source.index,
},
);
return path == null ? null : new File(path);
}
}