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

Fix web warrning #456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions image_cropper/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,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 (_croppedFile != null) {
final path = _croppedFile!.path;
return ConstrainedBox(
Expand Down
22 changes: 12 additions & 10 deletions image_cropper_for_web/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:image_cropper/image_cropper.dart';
Expand Down Expand Up @@ -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'),
);
}
Expand All @@ -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'),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
),
)
],
),
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions image_cropper_for_web/lib/image_cropper_for_web.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions image_cropper_for_web/lib/src/universal_ui/dart_fake_ui.dart
Original file line number Diff line number Diff line change
@@ -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 '';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'dart:ui' if (dart.library.html) 'dart:ui_web';