Refactor code: isMobile function

pull/593/head
X Code 3 years ago
parent 1d1d0757c6
commit 379f35d71f
  1. 3
      lib/src/utils/platform_helper.dart
  2. 5
      lib/src/widgets/editor.dart
  3. 7
      lib/src/widgets/toolbar/image_video_utils.dart

@ -0,0 +1,3 @@
import 'dart:io';
bool isMobile() => Platform.isAndroid || Platform.isIOS;

@ -14,6 +14,7 @@ import '../models/documents/document.dart';
import '../models/documents/nodes/container.dart' as container_node;
import '../models/documents/nodes/leaf.dart' as leaf;
import '../models/documents/nodes/line.dart';
import '../utils/platform_helper.dart';
import '../utils/string_helper.dart';
import 'box.dart';
import 'controller.dart';
@ -163,8 +164,6 @@ String _standardizeImageUrl(String url) {
return url;
}
bool _isMobile() => io.Platform.isAndroid || io.Platform.isIOS;
Widget defaultEmbedBuilder(
BuildContext context, leaf.Embed node, bool readOnly) {
assert(!kIsWeb, 'Please provide EmbedBuilder for Web');
@ -173,7 +172,7 @@ Widget defaultEmbedBuilder(
final imageUrl = _standardizeImageUrl(node.value.data);
var image;
final style = node.style.attributes['style'];
if (_isMobile() && style != null) {
if (isMobile() && style != null) {
final _attrs = parseKeyValuePairs(style.value.toString(),
{'mobileWidth', 'mobileHeight', 'mobileMargin', 'mobileAlignment'});
if (_attrs.isNotEmpty) {

@ -6,6 +6,7 @@ import 'package:image_picker/image_picker.dart';
import '../../models/documents/nodes/embed.dart';
import '../../translations/toolbar.i18n.dart';
import '../../utils/platform_helper.dart';
import '../controller.dart';
import '../toolbar.dart';
@ -60,7 +61,7 @@ class ImageVideoUtils {
'Please provide webImagePickImpl for Web '
'(check out example directory for how to do it)');
imageUrl = await webImagePickImpl!(onImagePickCallback);
} else if (_isMobile()) {
} else if (isMobile()) {
imageUrl = await _pickImage(imageSource, onImagePickCallback);
} else {
assert(filePickImpl != null, 'Desktop must provide filePickImpl');
@ -112,7 +113,7 @@ class ImageVideoUtils {
'Please provide webVideoPickImpl for Web '
'(check out example directory for how to do it)');
videoUrl = await webVideoPickImpl!(onVideoPickCallback);
} else if (_isMobile()) {
} else if (isMobile()) {
videoUrl = await _pickVideo(videoSource, onVideoPickCallback);
} else {
assert(filePickImpl != null, 'Desktop must provide filePickImpl');
@ -125,8 +126,6 @@ class ImageVideoUtils {
}
}
static bool _isMobile() => Platform.isAndroid || Platform.isIOS;
static Future<String?> _pickVideo(
ImageSource source, OnVideoPickCallback onVideoPickCallback) async {
final pickedFile = await ImagePicker().pickVideo(source: source);

Loading…
Cancel
Save