diff --git a/example/lib/main.dart b/example/lib/main.dart index d24e6842..c16a7983 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -453,7 +453,10 @@ class CropScreen extends StatelessWidget { child: AnimatedInteractiveViewer( maxScale: 2.4, child: CropGridViewer( - controller: controller, horizontalMargin: 60), + controller: controller, + horizontalMargin: 60, + enableGestureResizeCrop: true, + ), ), ), SizedBox(height: 15), @@ -471,7 +474,7 @@ class CropScreen extends StatelessWidget { ), buildSplashTap("16:9", 16 / 9, padding: Margin.horizontal(10)), buildSplashTap("1:1", 1 / 1), - buildSplashTap("4:5", 4 / 5, padding: Margin.horizontal(10)), + buildSplashTap("4:5", 3 / 2, padding: Margin.horizontal(10)), buildSplashTap("NO", null, padding: Margin.right(10)), Expanded( child: SplashTap( diff --git a/example/pubspec.lock b/example/pubspec.lock index 820aa181..65f0c0d7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,7 +21,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: @@ -42,7 +42,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" cross_file: dependency: transitive description: @@ -50,34 +50,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.3.2" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.1" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.4" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" ffi: dependency: transitive description: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.2" ffmpeg_kit_flutter_min_gpl: dependency: transitive description: @@ -98,7 +91,7 @@ packages: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.0" + version: "6.1.2" flutter: dependency: "direct main" description: flutter @@ -110,7 +103,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.5" flutter_test: dependency: "direct dev" description: flutter @@ -128,20 +121,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.1" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.15.0" http: dependency: transitive description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.1" + version: "0.13.3" http_parser: dependency: transitive description: @@ -155,35 +141,42 @@ packages: name: image_picker url: "https://pub.dartlang.org" source: hosted - version: "0.8.4+4" + version: "0.8.4+1" image_picker_for_web: dependency: transitive description: name: image_picker_for_web url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" + version: "2.1.6" image_picker_platform_interface: dependency: transitive description: name: image_picker_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.4.1" + version: "2.4.4" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4" meta: dependency: transitive description: @@ -197,70 +190,70 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" path_provider: dependency: transitive description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.4" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.5" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.5" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.3" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.5" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.11.0" + version: "1.11.1" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.2" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "4.2.1" + version: "4.2.3" sky_engine: dependency: transitive description: flutter @@ -272,7 +265,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -307,7 +300,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.2" + version: "0.4.9" typed_data: dependency: transitive description: @@ -321,7 +314,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.2" video_editor: dependency: "direct main" description: @@ -335,7 +328,7 @@ packages: name: video_player url: "https://pub.dartlang.org" source: hosted - version: "2.2.6" + version: "2.2.3" video_player_platform_interface: dependency: transitive description: @@ -349,7 +342,7 @@ packages: name: video_player_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.7" video_thumbnail: dependency: transitive description: @@ -363,14 +356,14 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.2.10" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.2.0+1" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=2.5.0" + dart: ">=2.17.0-0 <3.0.0" + flutter: ">=2.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2d96cd27..db5c02ad 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -17,7 +17,7 @@ dependencies: helpers: ^1.1.1 image_picker: ^0.8.4 cupertino_icons: ^1.0.2 - video_player: ^2.2.6 + video_player: ^2.2.3 dev_dependencies: flutter_test: diff --git a/lib/ui/cover/cover_selection.dart b/lib/ui/cover/cover_selection.dart index c95e4dfb..f1e4f011 100644 --- a/lib/ui/cover/cover_selection.dart +++ b/lib/ui/cover/cover_selection.dart @@ -60,7 +60,7 @@ class _CoverSelectionState extends State widget.controller.addListener(_scaleRect); // init the widget with controller values - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { _scaleRect(); }); } diff --git a/lib/ui/cover/cover_viewer.dart b/lib/ui/cover/cover_viewer.dart index fdd7ce5f..ea0b1e2b 100644 --- a/lib/ui/cover/cover_viewer.dart +++ b/lib/ui/cover/cover_viewer.dart @@ -111,7 +111,7 @@ class _CoverViewerState extends State { if (_layout != size) { _layout = size; // init the widget with controller values - WidgetsBinding.instance! + WidgetsBinding.instance .addPostFrameCallback((_) { _scaleRect(); }); diff --git a/lib/ui/crop/crop_grid.dart b/lib/ui/crop/crop_grid.dart index 459fc8b3..365953cd 100644 --- a/lib/ui/crop/crop_grid.dart +++ b/lib/ui/crop/crop_grid.dart @@ -20,12 +20,13 @@ enum _CropBoundaries { class CropGridViewer extends StatefulWidget { ///It is the viewer that allows you to crop the video - CropGridViewer( - {Key? key, - required this.controller, - this.showGrid = true, - this.horizontalMargin = 0.0}) - : super(key: key); + CropGridViewer({ + Key? key, + required this.controller, + this.showGrid = true, + this.horizontalMargin = 0.0, + this.enableGestureResizeCrop = true, + }) : super(key: key); /// If it is true, it shows the grid and allows cropping the video, if it is false /// does not show the grid and cannot be cropped @@ -37,6 +38,9 @@ class CropGridViewer extends StatefulWidget { ///Space to put around the grid to compute when the video is rotated final double horizontalMargin; + ///enabled crop resize, default true + final bool enableGestureResizeCrop; + @override _CropGridViewerState createState() => _CropGridViewerState(); } @@ -65,12 +69,12 @@ class _CropGridViewerState extends State { _controller.cacheMinCrop = _controller.minCrop; // init the crop area with preferredCropAspectRatio - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { _updateRect(); }); } else { // init the widget with controller values if it is not the croping screen - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { _scaleRect(); }); } @@ -138,25 +142,29 @@ class _CropGridViewerState extends State { ); //CORNERS - if (pos >= topLeft.topLeft && pos <= topLeft.bottomRight) { - _boundary = _CropBoundaries.topLeft; - } else if (pos >= topRight.topLeft && pos <= topRight.bottomRight) { - _boundary = _CropBoundaries.topRight; - } else if (pos >= bottomRight.topLeft && pos <= bottomRight.bottomRight) { - _boundary = _CropBoundaries.bottomRight; - } else if (pos >= bottomLeft.topLeft && pos <= bottomLeft.bottomRight) { - _boundary = _CropBoundaries.bottomLeft; - } else if (_controller.preferredCropAspectRatio == null) { - //CENTERS - if (pos >= topLeft.topRight && pos <= topRight.bottomLeft) { - _boundary = _CropBoundaries.topCenter; - } else if (pos >= bottomLeft.topRight && - pos <= bottomRight.bottomLeft) { - _boundary = _CropBoundaries.bottomCenter; - } else if (pos >= topLeft.bottomLeft && pos <= bottomLeft.topRight) { - _boundary = _CropBoundaries.centerLeft; - } else if (pos >= topRight.bottomLeft && pos <= bottomRight.topRight) { - _boundary = _CropBoundaries.centerRight; + if (widget.enableGestureResizeCrop) { + if (pos >= topLeft.topLeft && pos <= topLeft.bottomRight) { + _boundary = _CropBoundaries.topLeft; + } else if (pos >= topRight.topLeft && pos <= topRight.bottomRight) { + _boundary = _CropBoundaries.topRight; + } else if (pos >= bottomRight.topLeft && + pos <= bottomRight.bottomRight) { + _boundary = _CropBoundaries.bottomRight; + } else if (pos >= bottomLeft.topLeft && pos <= bottomLeft.bottomRight) { + _boundary = _CropBoundaries.bottomLeft; + } else if (_controller.preferredCropAspectRatio == null) { + //CENTERS + if (pos >= topLeft.topRight && pos <= topRight.bottomLeft) { + _boundary = _CropBoundaries.topCenter; + } else if (pos >= bottomLeft.topRight && + pos <= bottomRight.bottomLeft) { + _boundary = _CropBoundaries.bottomCenter; + } else if (pos >= topLeft.bottomLeft && pos <= bottomLeft.topRight) { + _boundary = _CropBoundaries.centerLeft; + } else if (pos >= topRight.bottomLeft && + pos <= bottomRight.topRight) { + _boundary = _CropBoundaries.centerRight; + } } //OTHERS else if (pos >= minMargin[1] && pos <= maxMargin[0]) { @@ -186,6 +194,8 @@ class _CropGridViewerState extends State { break; //CORNERS case _CropBoundaries.topLeft: + if (!widget.enableGestureResizeCrop) break; + final Offset pos = _rect.value.topLeft + delta; _changeRect( top: _preferredCropAspectRatio == null ? pos.dy : pos.dy, @@ -199,6 +209,8 @@ class _CropGridViewerState extends State { ); break; case _CropBoundaries.topRight: + if (!widget.enableGestureResizeCrop) break; + _changeRect( top: _preferredCropAspectRatio == null ? _rect.value.topRight.dy + delta.dy @@ -211,12 +223,16 @@ class _CropGridViewerState extends State { ); break; case _CropBoundaries.bottomRight: + if (!widget.enableGestureResizeCrop) break; + _changeRect( width: _rect.value.width + delta.dx, height: _rect.value.height + delta.dy, ); break; case _CropBoundaries.bottomLeft: + if (!widget.enableGestureResizeCrop) break; + _changeRect( left: _rect.value.bottomLeft.dx + delta.dx, width: _rect.value.width - delta.dx, @@ -273,9 +289,9 @@ class _CropGridViewerState extends State { height = height ?? _rect.value.height; if (_preferredCropAspectRatio != null) { - if (height > width) { + if (_preferredCropAspectRatio! >= 1) { height = width / _preferredCropAspectRatio!; - } else if (height < width) { + } else if (_preferredCropAspectRatio! < 1) { width = height / _preferredCropAspectRatio!; } } @@ -335,7 +351,7 @@ class _CropGridViewerState extends State { if (_layout != size) { _layout = size; if (widget.showGrid) { - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { _calculatePreferedCrop(); }); } else { diff --git a/lib/ui/trim/thumbnail_slider.dart b/lib/ui/trim/thumbnail_slider.dart index 82604bc6..7e5fe82e 100644 --- a/lib/ui/trim/thumbnail_slider.dart +++ b/lib/ui/trim/thumbnail_slider.dart @@ -45,7 +45,7 @@ class _ThumbnailSliderState extends State { widget.controller.addListener(_scaleRect); // init the widget with controller values - WidgetsBinding.instance!.addPostFrameCallback((_) { + WidgetsBinding.instance.addPostFrameCallback((_) { _scaleRect(); }); diff --git a/pubspec.lock b/pubspec.lock index 1d8e9079..b2f2ff48 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -21,7 +21,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: @@ -42,28 +42,21 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.1" + version: "1.16.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" ffi: dependency: transitive description: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.2" ffmpeg_kit_flutter_min_gpl: dependency: "direct main" description: @@ -84,7 +77,7 @@ packages: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.0" + version: "6.1.2" flutter: dependency: "direct main" description: flutter @@ -100,27 +93,27 @@ packages: description: flutter source: sdk version: "0.0.0" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.15.0" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4" meta: dependency: transitive description: @@ -134,63 +127,63 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" path_provider: dependency: "direct main" description: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.4" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.5" path_provider_macos: dependency: transitive description: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.5" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.3" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.5" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.2" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "4.2.1" + version: "4.2.3" sky_engine: dependency: transitive description: flutter @@ -202,7 +195,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -237,28 +230,21 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.2" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.4.9" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.2" video_player: dependency: "direct main" description: name: video_player url: "https://pub.dartlang.org" source: hosted - version: "2.2.6" + version: "2.2.3" video_player_platform_interface: dependency: transitive description: @@ -272,7 +258,7 @@ packages: name: video_player_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.0.7" video_thumbnail: dependency: "direct main" description: @@ -286,14 +272,14 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.2.10" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.2.0+1" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=2.5.0" + dart: ">=2.17.0-0 <3.0.0" + flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 92b99895..47aa7647 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: sdk: flutter path: ^1.8.0 path_provider: ^2.0.2 - video_player: ^2.2.6 + video_player: ^2.2.3 video_thumbnail: ^0.4.3 dev_dependencies: