diff --git a/image_cropper/example/lib/main.dart b/image_cropper/example/lib/main.dart index d1536e0d..c53caada 100644 --- a/image_cropper/example/lib/main.dart +++ b/image_cropper/example/lib/main.dart @@ -132,8 +132,8 @@ class _HomePageState extends State { } Widget _image() { - final screenWidth = MediaQuery.of(context).size.width; - final screenHeight = MediaQuery.of(context).size.height; + final screenWidth = MediaQuery.sizeOf(context).width; + final screenHeight = MediaQuery.sizeOf(context).height; if (_croppedFile != null) { final path = _croppedFile!.path; return ConstrainedBox( diff --git a/image_cropper_for_web/example/lib/main.dart b/image_cropper_for_web/example/lib/main.dart index e80c3eb8..3fea7cf3 100644 --- a/image_cropper_for_web/example/lib/main.dart +++ b/image_cropper_for_web/example/lib/main.dart @@ -1,4 +1,3 @@ - import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/material.dart'; import 'package:image_cropper/image_cropper.dart'; @@ -48,7 +47,9 @@ class MyApp extends StatelessWidget { side: MaterialStateBorderSide.resolveWith( (states) => const BorderSide(color: Color(0xFFBC764A))), ), - ), colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue).copyWith(background: const Color(0xFFFDF5EC))), + ), + colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue) + .copyWith(background: const Color(0xFFFDF5EC))), home: const MyHomePage(title: 'Image Cropper Demo'), ); } @@ -61,7 +62,7 @@ class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { - final screenWidth = MediaQuery.of(context).size.width; + final screenWidth = MediaQuery.sizeOf(context).width; if (screenWidth > 700) { return _HomePage( key: const ValueKey('desktop'), @@ -158,8 +159,8 @@ class _HomePageState extends State<_HomePage> { } Widget _image() { - final screenWidth = MediaQuery.of(context).size.width; - final screenHeight = MediaQuery.of(context).size.height; + final screenWidth = MediaQuery.sizeOf(context).width; + final screenHeight = MediaQuery.sizeOf(context).height; if (_croppedBlobUrl != null) { return ConstrainedBox( constraints: BoxConstraints( @@ -242,9 +243,10 @@ class _HomePageState extends State<_HomePage> { const SizedBox(height: 24.0), Text( 'Upload an image to start', - style: Theme.of(context).textTheme.headlineSmall!.copyWith( - color: Theme.of(context).highlightColor, - ), + style: + Theme.of(context).textTheme.headlineSmall!.copyWith( + color: Theme.of(context).highlightColor, + ), ) ], ), @@ -268,8 +270,8 @@ class _HomePageState extends State<_HomePage> { if (_uploadedBlobUrl != null) { WebUiSettings settings; if (widget.displayStyle == PageDisplayStyle.mobile) { - final screenWidth = MediaQuery.of(context).size.width; - final screenHeight = MediaQuery.of(context).size.height; + final screenWidth = MediaQuery.sizeOf(context).width; + final screenHeight = MediaQuery.sizeOf(context).height; settings = WebUiSettings( context: context, presentStyle: CropperPresentStyle.page, diff --git a/image_cropper_for_web/lib/image_cropper_for_web.dart b/image_cropper_for_web/lib/image_cropper_for_web.dart index 06b0821f..344783d8 100644 --- a/image_cropper_for_web/lib/image_cropper_for_web.dart +++ b/image_cropper_for_web/lib/image_cropper_for_web.dart @@ -1,7 +1,8 @@ library image_cropper_for_web; import 'dart:html' as html; -import 'dart:ui' as ui; +import 'src/universal_ui/dart_fake_ui.dart' + if (dart.library.html) 'src/universal_ui/dart_real_ui.dart' as ui; import 'package:flutter/material.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; @@ -130,8 +131,7 @@ class ImageCropperPlugin extends ImageCropperPlatform { final viewId = 'croppie-view-${DateTime.now().millisecondsSinceEpoch}'; - // ignore: undefined_prefixed_name - ui.platformViewRegistry + ui.PlatformViewRegistry() .registerViewFactory(viewId, (int viewId) => element); final cropper = HtmlElementView( diff --git a/image_cropper_for_web/lib/src/universal_ui/dart_fake_ui.dart b/image_cropper_for_web/lib/src/universal_ui/dart_fake_ui.dart new file mode 100644 index 00000000..71af38f9 --- /dev/null +++ b/image_cropper_for_web/lib/src/universal_ui/dart_fake_ui.dart @@ -0,0 +1,20 @@ +class PlatformViewRegistry { + /// Register [viewType] as being created by the given [viewFactory]. + /// + /// [viewFactory] can be any function that takes an integer and optional + /// `params` and returns an `HTMLElement` DOM object. + bool registerViewFactory( + String viewType, + Function viewFactory, { + bool isVisible = true, + }) { + return false; + } + + /// Returns the view previously created for [viewId]. + /// + /// Throws if no view has been created for [viewId]. + Object getViewById(int viewId) { + return ''; + } +} diff --git a/image_cropper_for_web/lib/src/universal_ui/dart_real_ui.dart b/image_cropper_for_web/lib/src/universal_ui/dart_real_ui.dart new file mode 100644 index 00000000..e38110eb --- /dev/null +++ b/image_cropper_for_web/lib/src/universal_ui/dart_real_ui.dart @@ -0,0 +1 @@ +export 'dart:ui' if (dart.library.html) 'dart:ui_web';