Fix platform checking logic (#1518)

* Fix platform checking logic

* Update _defaultOnTapOutside
pull/1519/head
Ellet 1 year ago committed by GitHub
parent db406d4b01
commit ebd2729f39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      example/lib/pages/home_page.dart
  3. 2
      example/lib/pages/read_only_page.dart
  4. 3
      flutter_quill_extensions/CHANGELOG.md
  5. 17
      flutter_quill_extensions/lib/presentation/embeds/editor/image/image.dart
  6. 2
      flutter_quill_extensions/lib/presentation/embeds/toolbar/image_button/select_image_source.dart
  7. 2
      flutter_quill_extensions/lib/presentation/embeds/toolbar/video_button/select_video_source.dart
  8. 10
      flutter_quill_extensions/lib/presentation/models/config/editor/image/image.dart
  9. 130
      lib/src/utils/platform.dart
  10. 2
      lib/src/widgets/cursor.dart
  11. 2
      lib/src/widgets/default_styles.dart
  12. 4
      lib/src/widgets/delegate.dart
  13. 23
      lib/src/widgets/editor/editor.dart
  14. 8
      lib/src/widgets/raw_editor/raw_editor_state.dart
  15. 6
      lib/src/widgets/text_line.dart
  16. 1
      pubspec.yaml
  17. 156
      test/utils/platform_test.dart
  18. 2
      test/widgets/controller_test.dart

@ -3,6 +3,7 @@
- **Breaking change**: the `customButtons` in the `QuillToolbarConfigurations` is now of type `List<QuillToolbarCustomButtonOptions>` - **Breaking change**: the `customButtons` in the `QuillToolbarConfigurations` is now of type `List<QuillToolbarCustomButtonOptions>`
- Bug fixes with the new `8.0.0` update - Bug fixes with the new `8.0.0` update
- Update `README.md` - Update `README.md`
- Improve the platform checking
## [8.3.0] ## [8.3.0]
- Added a `iconButtonFactor` property to `QuillToolbarBaseButtonOptions` to customise how big the button is compared to its icon size (defaults to `kIconButtonFactor` which is the same as previous releases) - Added a `iconButtonFactor` property to `QuillToolbarBaseButtonOptions` to customise how big the button is compared to its icon size (defaults to `kIconButtonFactor` which is the same as previous releases)

@ -414,7 +414,7 @@ class _HomePageState extends State<HomePage> {
placeholder: 'Add content', placeholder: 'Add content',
readOnly: _isReadOnly, readOnly: _isReadOnly,
autoFocus: false, autoFocus: false,
enableSelectionToolbar: isMobile(), enableSelectionToolbar: isMobile(supportWeb: false),
expands: false, expands: false,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onImagePaste: _onImagePaste, onImagePaste: _onImagePaste,
@ -500,7 +500,7 @@ class _HomePageState extends State<HomePage> {
// afterButtonPressed: _focusNode.requestFocus, // afterButtonPressed: _focusNode.requestFocus,
); );
} }
if (isDesktop()) { if (isDesktop(supportWeb: false)) {
return QuillToolbar( return QuillToolbar(
configurations: QuillToolbarConfigurations( configurations: QuillToolbarConfigurations(
customButtons: customButtons, customButtons: customButtons,

@ -23,7 +23,7 @@ class _ReadOnlyPageState extends State<ReadOnlyPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DemoScaffold( return DemoScaffold(
documentFilename: isDesktop() documentFilename: isDesktop(supportWeb: false)
? 'assets/sample_data_nomedia.json' ? 'assets/sample_data_nomedia.json'
: 'sample_data_nomedia.json', : 'sample_data_nomedia.json',
builder: _buildContent, builder: _buildContent,

@ -1,3 +1,6 @@
## 0.6.5
- Support the new improved platform checking of `flutter_quill`
## 0.6.4 ## 0.6.4
- Update `QuillImageUtilities` - Update `QuillImageUtilities`
- Add new extension on `QuillController` to access `QuillImageUtilities` instance easier - Add new extension on `QuillController` to access `QuillImageUtilities` instance easier

@ -41,7 +41,7 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
final style = node.style.attributes['style']; final style = node.style.attributes['style'];
if (style != null) { if (style != null) {
final attrs = base.isMobile() final attrs = base.isMobile(supportWeb: false)
? base.parseKeyValuePairs(style.value.toString(), { ? base.parseKeyValuePairs(style.value.toString(), {
Attribute.mobileWidth, Attribute.mobileWidth,
Attribute.mobileHeight, Attribute.mobileHeight,
@ -56,21 +56,21 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
}); });
if (attrs.isNotEmpty) { if (attrs.isNotEmpty) {
final width = double.tryParse( final width = double.tryParse(
(base.isMobile() (base.isMobile(supportWeb: false)
? attrs[Attribute.mobileWidth] ? attrs[Attribute.mobileWidth]
: attrs[Attribute.width.key]) ?? : attrs[Attribute.width.key]) ??
'', '',
); );
final height = double.tryParse( final height = double.tryParse(
(base.isMobile() (base.isMobile(supportWeb: false)
? attrs[Attribute.mobileHeight] ? attrs[Attribute.mobileHeight]
: attrs[Attribute.height.key]) ?? : attrs[Attribute.height.key]) ??
'', '',
); );
final alignment = base.getAlignment(base.isMobile() final alignment = base.getAlignment(base.isMobile(supportWeb: false)
? attrs[Attribute.mobileAlignment] ? attrs[Attribute.mobileAlignment]
: attrs[Attribute.alignment]); : attrs[Attribute.alignment]);
final margin = (base.isMobile() final margin = (base.isMobile(supportWeb: false)
? double.tryParse(Attribute.mobileMargin) ? double.tryParse(Attribute.mobileMargin)
: double.tryParse(Attribute.margin)) ?? : double.tryParse(Attribute.margin)) ??
0.0; 0.0;
@ -106,7 +106,7 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
} }
if (!readOnly && if (!readOnly &&
(base.isMobile() || (base.isMobile(supportWeb: false) ||
configurations.forceUseMobileOptionMenuForImageClick)) { configurations.forceUseMobileOptionMenuForImageClick)) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
@ -188,7 +188,8 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
getImageStyleString(controller), getImageStyleString(controller),
width: w, width: w,
height: h, height: h,
isMobile: base.isMobile(), isMobile:
base.isMobile(supportWeb: false),
); );
controller controller
..skipRequestKeyboard = true ..skipRequestKeyboard = true
@ -220,7 +221,7 @@ class QuillEditorImageEmbedBuilder extends EmbedBuilder {
if (!readOnly || isImageBase64(imageUrl)) { if (!readOnly || isImageBase64(imageUrl)) {
// To enforce using it on the desktop and other platforms // To enforce using it on the desktop and other platforms
// and that is up to the developer // and that is up to the developer
if (!base.isMobile() && if (!base.isMobile(supportWeb: false) &&
configurations.forceUseMobileOptionMenuForImageClick) { configurations.forceUseMobileOptionMenuForImageClick) {
return _menuOptionsForReadonlyImage( return _menuOptionsForReadonlyImage(
context: context, context: context,

@ -28,7 +28,7 @@ class SelectImageSourceDialog extends StatelessWidget {
'Take a photo using your phone camera', 'Take a photo using your phone camera',
), ),
leading: const Icon(Icons.camera), leading: const Icon(Icons.camera),
enabled: !isDesktop(), enabled: !isDesktop(supportWeb: false),
onTap: () => Navigator.of(context).pop(InsertImageSource.camera), onTap: () => Navigator.of(context).pop(InsertImageSource.camera),
), ),
ListTile( ListTile(

@ -28,7 +28,7 @@ class SelectVideoSourceDialog extends StatelessWidget {
'Record a video using your phone camera', 'Record a video using your phone camera',
), ),
leading: const Icon(Icons.camera), leading: const Icon(Icons.camera),
enabled: !isDesktop(), enabled: !isDesktop(supportWeb: false),
onTap: () => Navigator.of(context).pop(InsertVideoSource.camera), onTap: () => Navigator.of(context).pop(InsertVideoSource.camera),
), ),
ListTile( ListTile(

@ -112,7 +112,11 @@ class QuillEditorImageEmbedConfigurations {
static ImageEmbedBuilderOnRemovedCallback get defaultOnImageRemovedCallback { static ImageEmbedBuilderOnRemovedCallback get defaultOnImageRemovedCallback {
return (imageUrl) async { return (imageUrl) async {
final mobile = isMobile(); if (isWeb()) {
return;
}
final mobile = isMobile(supportWeb: false);
// If the platform is not mobile, return void; // If the platform is not mobile, return void;
// Since the mobile OS gives us a copy of the image // Since the mobile OS gives us a copy of the image
@ -134,10 +138,6 @@ class QuillEditorImageEmbedConfigurations {
// it without // it without
// permission // permission
if (isWeb()) {
return;
}
final dartIoImageFile = File(imageUrl); final dartIoImageFile = File(imageUrl);
final isFileExists = await dartIoImageFile.exists(); final isFileExists = await dartIoImageFile.exists();

@ -4,62 +4,113 @@ import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart' import 'package:flutter/foundation.dart'
show kIsWeb, TargetPlatform, defaultTargetPlatform; show kIsWeb, TargetPlatform, defaultTargetPlatform;
bool isWeb() { /// If you want to override the [kIsWeb] use [overrideIsWeb]
return kIsWeb; bool isWeb({bool? overrideIsWeb}) {
return overrideIsWeb ?? kIsWeb;
} }
bool isMobile([TargetPlatform? targetPlatform]) { /// [supportWeb] is a parameter that ask you if we should care about web support
if (isWeb()) return false; /// if the value is true then we will return the result no matter if we are
targetPlatform ??= defaultTargetPlatform; /// on web or using a native app to run the flutter app
return {TargetPlatform.iOS, TargetPlatform.android}.contains(targetPlatform); bool isMobile({
required bool supportWeb,
TargetPlatform? platform,
bool? overrideIsWeb,
}) {
if (isWeb(overrideIsWeb: overrideIsWeb) && !supportWeb) return false;
platform ??= defaultTargetPlatform;
return {TargetPlatform.iOS, TargetPlatform.android}.contains(platform);
} }
bool isDesktop([TargetPlatform? targetPlatform]) { /// [supportWeb] is a parameter that ask you if we should care about web support
if (isWeb()) return false; /// if the value is true then we will return the result no matter if we are
targetPlatform ??= defaultTargetPlatform; /// on web or using a native app to run the flutter app
bool isDesktop({
required bool supportWeb,
TargetPlatform? platform,
bool? overrideIsWeb,
}) {
if (isWeb(overrideIsWeb: overrideIsWeb) && !supportWeb) return false;
platform ??= defaultTargetPlatform;
return {TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows} return {TargetPlatform.macOS, TargetPlatform.linux, TargetPlatform.windows}
.contains(targetPlatform); .contains(platform);
} }
bool isKeyboardOS([TargetPlatform? targetPlatform]) { /// [supportWeb] is a parameter that ask you if we should care about web support
targetPlatform ??= defaultTargetPlatform; /// if the value is true then we will return the result no matter if we are
return isDesktop(targetPlatform) || targetPlatform == TargetPlatform.fuchsia; /// on web or using a native app to run the flutter app
bool isKeyboardOS({
required bool supportWeb,
TargetPlatform? platform,
bool? overrideIsWeb,
}) {
platform ??= defaultTargetPlatform;
return isDesktop(
platform: platform,
supportWeb: supportWeb,
overrideIsWeb: overrideIsWeb) ||
platform == TargetPlatform.fuchsia;
} }
bool isAppleOS([TargetPlatform? targetPlatform]) { /// [supportWeb] is a parameter that ask you if we should care about web support
if (isWeb()) return false; /// if the value is true then we will return the result no matter if we are
targetPlatform ??= defaultTargetPlatform; /// on web or using a native app to run the flutter app
bool isAppleOS({
required bool supportWeb,
TargetPlatform? platform,
bool? overrideIsWeb,
}) {
if (isWeb(overrideIsWeb: overrideIsWeb) && !supportWeb) return false;
platform ??= defaultTargetPlatform;
return { return {
TargetPlatform.macOS, TargetPlatform.macOS,
TargetPlatform.iOS, TargetPlatform.iOS,
}.contains(targetPlatform); }.contains(platform);
} }
bool isMacOS([TargetPlatform? targetPlatform]) { /// [supportWeb] is a parameter that ask you if we should care about web support
if (isWeb()) return false; /// if the value is true then we will return the result no matter if we are
targetPlatform ??= defaultTargetPlatform; /// on web or using a native app to run the flutter app
return TargetPlatform.macOS == targetPlatform; bool isMacOS({
required bool supportWeb,
TargetPlatform? platform,
bool? overrideIsWeb,
}) {
if (isWeb(overrideIsWeb: overrideIsWeb) && !supportWeb) return false;
platform ??= defaultTargetPlatform;
return TargetPlatform.macOS == platform;
} }
bool isIOS([TargetPlatform? targetPlatform]) { /// [supportWeb] is a parameter that ask you if we should care about web support
if (isWeb()) return false; /// if the value is true then we will return the result no matter if we are
targetPlatform ??= defaultTargetPlatform; /// on web or using a native app to run the flutter app
return TargetPlatform.iOS == targetPlatform; bool isIOS({
required bool supportWeb,
TargetPlatform? platform,
bool? overrideIsWeb,
}) {
if (isWeb(overrideIsWeb: overrideIsWeb) && !supportWeb) return false;
platform ??= defaultTargetPlatform;
return TargetPlatform.iOS == platform;
} }
bool isAndroid([TargetPlatform? targetPlatform]) { /// [supportWeb] is a parameter that ask you if we should care about web support
if (isWeb()) return false; /// if the value is true then we will return the result no matter if we are
targetPlatform ??= defaultTargetPlatform; /// on web or using a native app to run the flutter app
return TargetPlatform.android == targetPlatform; bool isAndroid({
required bool supportWeb,
TargetPlatform? platform,
bool? overrideIsWeb,
}) {
if (isWeb(overrideIsWeb: overrideIsWeb) && !supportWeb) return false;
platform ??= defaultTargetPlatform;
return TargetPlatform.android == platform;
} }
bool isFlutterTest() { Future<bool> isIOSSimulator({
if (isWeb()) return false; bool? overrideIsWeb,
return Platform.environment.containsKey('FLUTTER_TEST'); }) async {
} if (!isAppleOS(supportWeb: false, overrideIsWeb: overrideIsWeb)) {
Future<bool> isIOSSimulator() async {
if (!isAppleOS()) {
return false; return false;
} }
@ -73,3 +124,10 @@ Future<bool> isIOSSimulator() async {
} }
return false; return false;
} }
bool isFlutterTest({
bool? overrideIsWeb,
}) {
if (isWeb(overrideIsWeb: overrideIsWeb)) return false;
return Platform.environment.containsKey('FLUTTER_TEST');
}

@ -291,7 +291,7 @@ class CursorPainter {
final caretHeight = editable!.getFullHeightForCaret(position); final caretHeight = editable!.getFullHeightForCaret(position);
if (caretHeight != null) { if (caretHeight != null) {
if (isAppleOS()) { if (isAppleOS(supportWeb: true)) {
// Center the caret vertically along the text. // Center the caret vertically along the text.
caretRect = Rect.fromLTWH( caretRect = Rect.fromLTWH(
caretRect.left, caretRect.left,

@ -204,7 +204,7 @@ class DefaultStyles {
); );
const baseSpacing = VerticalSpacing(6, 0); const baseSpacing = VerticalSpacing(6, 0);
String fontFamily; String fontFamily;
if (isAppleOS(themeData.platform)) { if (isAppleOS(platform: themeData.platform, supportWeb: true)) {
fontFamily = 'Menlo'; fontFamily = 'Menlo';
} else { } else {
fontFamily = 'Roboto Mono'; fontFamily = 'Roboto Mono';

@ -331,7 +331,9 @@ class EditorTextSelectionGestureDetectorBuilder {
@protected @protected
void onDragSelectionEnd(DragEndDetails details) { void onDragSelectionEnd(DragEndDetails details) {
renderEditor!.handleDragEnd(details); renderEditor!.handleDragEnd(details);
if (isDesktop() && // TODO: Should we care if the platform is desktop using native desktop app
// or the flutter app is running using web app??
if (isDesktop(supportWeb: true) &&
delegate.selectionEnabled && delegate.selectionEnabled &&
shouldShowSelectionToolbar) { shouldShowSelectionToolbar) {
// added to show selection copy/paste toolbar after drag to select // added to show selection copy/paste toolbar after drag to select

@ -215,7 +215,10 @@ class QuillEditorState extends State<QuillEditor>
Color selectionColor; Color selectionColor;
Radius? cursorRadius; Radius? cursorRadius;
if (isAppleOS(theme.platform)) { if (isAppleOS(
platform: theme.platform,
supportWeb: true,
)) {
final cupertinoTheme = CupertinoTheme.of(context); final cupertinoTheme = CupertinoTheme.of(context);
textSelectionControls = cupertinoTextSelectionControls; textSelectionControls = cupertinoTextSelectionControls;
paintCursorAboveText = true; paintCursorAboveText = true;
@ -257,7 +260,10 @@ class QuillEditorState extends State<QuillEditor>
? (configurations.contextMenuBuilder ?? ? (configurations.contextMenuBuilder ??
QuillRawEditor.defaultContextMenuBuilder) QuillRawEditor.defaultContextMenuBuilder)
: null, : null,
showSelectionHandles: isMobile(theme.platform), showSelectionHandles: isMobile(
platform: theme.platform,
supportWeb: true,
),
showCursor: configurations.showCursor, showCursor: configurations.showCursor,
cursorStyle: CursorStyle( cursorStyle: CursorStyle(
color: cursorColor, color: cursorColor,
@ -407,7 +413,10 @@ class _QuillEditorSelectionGestureDetectorBuilder
} }
final platform = Theme.of(_state.context).platform; final platform = Theme.of(_state.context).platform;
if (isAppleOS(platform)) { if (isAppleOS(
platform: platform,
supportWeb: true,
)) {
renderEditor!.selectPositionAt( renderEditor!.selectPositionAt(
from: details.globalPosition, from: details.globalPosition,
cause: SelectionChangedCause.longPress, cause: SelectionChangedCause.longPress,
@ -480,7 +489,8 @@ class _QuillEditorSelectionGestureDetectorBuilder
try { try {
if (delegate.selectionEnabled && !_isPositionSelected(details)) { if (delegate.selectionEnabled && !_isPositionSelected(details)) {
final platform = Theme.of(_state.context).platform; final platform = Theme.of(_state.context).platform;
if (isAppleOS(platform) || isDesktop()) { if (isAppleOS(platform: platform, supportWeb: true) ||
isDesktop(platform: platform, supportWeb: true)) {
// added isDesktop() to enable extend selection in Windows platform // added isDesktop() to enable extend selection in Windows platform
switch (details.kind) { switch (details.kind) {
case PointerDeviceKind.mouse: case PointerDeviceKind.mouse:
@ -544,7 +554,10 @@ class _QuillEditorSelectionGestureDetectorBuilder
if (delegate.selectionEnabled) { if (delegate.selectionEnabled) {
final platform = Theme.of(_state.context).platform; final platform = Theme.of(_state.context).platform;
if (isAppleOS(platform)) { if (isAppleOS(
platform: platform,
supportWeb: true,
)) {
renderEditor!.selectPositionAt( renderEditor!.selectPositionAt(
from: details.globalPosition, from: details.globalPosition,
cause: SelectionChangedCause.longPress, cause: SelectionChangedCause.longPress,

@ -185,10 +185,6 @@ class QuillRawEditorState extends EditorState
} }
void _defaultOnTapOutside(PointerDownEvent event) { void _defaultOnTapOutside(PointerDownEvent event) {
if (isWeb()) {
widget.focusNode.unfocus();
}
/// The focus dropping behavior is only present on desktop platforms /// The focus dropping behavior is only present on desktop platforms
/// and mobile browsers. /// and mobile browsers.
switch (defaultTargetPlatform) { switch (defaultTargetPlatform) {
@ -322,7 +318,7 @@ class QuillRawEditorState extends EditorState
// so if we ovveride the platform in material app theme data // so if we ovveride the platform in material app theme data
// it will not depend on it and doesn't change here but I don't think // it will not depend on it and doesn't change here but I don't think
// we need to // we need to
final isDesktopMacOS = isMacOS(); final isDesktopMacOS = isMacOS(supportWeb: true);
return TextFieldTapRegion( return TextFieldTapRegion(
enabled: widget.enableUnfocusOnTapOutside, enabled: widget.enableUnfocusOnTapOutside,
@ -859,7 +855,7 @@ class QuillRawEditorState extends EditorState
_floatingCursorResetController = AnimationController(vsync: this); _floatingCursorResetController = AnimationController(vsync: this);
_floatingCursorResetController.addListener(onFloatingCursorResetTick); _floatingCursorResetController.addListener(onFloatingCursorResetTick);
if (isKeyboardOS()) { if (isKeyboardOS(supportWeb: true)) {
_keyboardVisible = true; _keyboardVisible = true;
} else if (!isWeb() && isFlutterTest()) { } else if (!isWeb() && isFlutterTest()) {
// treat tests like a keyboard OS // treat tests like a keyboard OS

@ -90,7 +90,7 @@ class _TextLineState extends State<TextLine> {
// Desktop platforms (macOS, Linux, Windows): // Desktop platforms (macOS, Linux, Windows):
// only allow Meta (Control) + Click combinations // only allow Meta (Control) + Click combinations
if (isDesktop()) { if (isDesktop(supportWeb: false)) {
return _metaOrControlPressed; return _metaOrControlPressed;
} }
// Mobile platforms (ios, android): always allow but we install a // Mobile platforms (ios, android): always allow but we install a
@ -434,7 +434,7 @@ class _TextLineState extends State<TextLine> {
} }
if (isLink && canLaunchLinks) { if (isLink && canLaunchLinks) {
if (isDesktop() || widget.readOnly) { if (isDesktop(supportWeb: true) || widget.readOnly) {
_linkRecognizers[segment] = TapGestureRecognizer() _linkRecognizers[segment] = TapGestureRecognizer()
..onTap = () => _tapNodeLink(segment); ..onTap = () => _tapNodeLink(segment);
} else { } else {
@ -896,7 +896,7 @@ class RenderEditableTextLine extends RenderEditableBox {
void _computeCaretPrototype() { void _computeCaretPrototype() {
// If the cursor is taller only on iOS and not AppleOS then we should check // If the cursor is taller only on iOS and not AppleOS then we should check
// only for iOS instead of AppleOS (macOS for example) // only for iOS instead of AppleOS (macOS for example)
if (isIOS()) { if (isIOS(supportWeb: true)) {
_caretPrototype = Rect.fromLTWH(0, 0, cursorWidth, cursorHeight + 2); _caretPrototype = Rect.fromLTWH(0, 0, cursorWidth, cursorHeight + 2);
} else { } else {
_caretPrototype = Rect.fromLTWH(0, 2, cursorWidth, cursorHeight - 4.0); _caretPrototype = Rect.fromLTWH(0, 2, cursorWidth, cursorHeight - 4.0);

@ -55,6 +55,7 @@ dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
flutter_quill_test: ^0.0.4 flutter_quill_test: ^0.0.4
test: ^1.24.3
flutter: flutter:
uses-material-design: true uses-material-design: true

@ -0,0 +1,156 @@
import 'package:flutter/foundation.dart' show TargetPlatform;
import 'package:flutter_quill/src/utils/platform.dart';
import 'package:test/test.dart';
void main() {
group('Test platform checking logic', () {
var platform = TargetPlatform.linux;
test('Check isDesktop()', () {
platform = TargetPlatform.android;
expect(
isDesktop(
platform: platform,
supportWeb: true,
),
false,
);
for (final desktopPlatform in [
TargetPlatform.macOS,
TargetPlatform.linux,
TargetPlatform.windows
]) {
expect(
isDesktop(
supportWeb: false,
platform: desktopPlatform,
overrideIsWeb: false,
),
true,
);
expect(
isDesktop(
supportWeb: false,
overrideIsWeb: true,
platform: desktopPlatform,
),
false,
);
expect(
isDesktop(
supportWeb: true,
overrideIsWeb: true,
platform: desktopPlatform,
),
true,
);
}
});
test('Check isMobile()', () {
platform = TargetPlatform.macOS;
expect(
isMobile(
platform: platform,
supportWeb: true,
),
false,
);
for (final mobilePlatform in [
TargetPlatform.android,
TargetPlatform.iOS,
]) {
expect(
isMobile(
supportWeb: false,
platform: mobilePlatform,
overrideIsWeb: false,
),
true,
);
expect(
isMobile(
supportWeb: false,
overrideIsWeb: true,
platform: mobilePlatform,
),
false,
);
expect(
isMobile(
supportWeb: true,
overrideIsWeb: true,
platform: mobilePlatform,
),
true,
);
}
});
test(
'Check supportWeb parameter when using desktop platform on web',
() {
platform = TargetPlatform.macOS;
expect(
isDesktop(
platform: platform,
supportWeb: true,
),
true,
);
expect(
isDesktop(
platform: platform,
supportWeb: false,
overrideIsWeb: false,
),
true,
);
expect(
isDesktop(
platform: platform,
supportWeb: false,
overrideIsWeb: true,
),
false,
);
},
);
test(
'Check supportWeb parameter when using mobile platform on web',
() {
platform = TargetPlatform.android;
expect(
isMobile(
platform: platform,
supportWeb: true,
overrideIsWeb: true,
),
true,
);
expect(
isMobile(
platform: platform,
supportWeb: false,
overrideIsWeb: false,
),
true,
);
expect(
isMobile(
platform: platform,
supportWeb: false,
overrideIsWeb: true,
),
false,
);
},
);
});
}

@ -1,6 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart'; import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:test/test.dart';
void main() { void main() {
const testDocumentContents = 'data'; const testDocumentContents = 'data';

Loading…
Cancel
Save