Skip to content

Commit

Permalink
fix(extensions)!: drop support for YouTube iframeView for non-web pla…
Browse files Browse the repository at this point in the history
…tforms, remove youtube_player_flutter dependency, throw warnings for anything related to YoutubeVideoApp in development mode (#2286)

* fix: drop support for YouTube iframeView for non-web platforms, throw warnings for anything related to YoutubeVideoApp in development mode
  • Loading branch information
EchoEllet authored Sep 25, 2024
1 parent 92e4c74 commit 0193230
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 59 deletions.
13 changes: 8 additions & 5 deletions example/lib/screens/quill/my_quill_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ class MyQuillEditor extends StatelessWidget {
},
),
videoEmbedConfigurations: QuillEditorVideoEmbedConfigurations(
// Loading YouTube videos on Desktop is not supported yet
// when using iframe platform view
youtubeVideoSupportMode: isDesktopApp
? YoutubeVideoSupportMode.customPlayerWithDownloadUrl
: YoutubeVideoSupportMode.iframeView,
customVideoBuilder: (videoUrl, readOnly) {
// Example: Check for YouTube Video URL and return your
// YouTube video widget here.

// Otherwise return null to fallback to the defualt logic
return null;
},
ignoreYouTubeSupport: true,
),
)),
TimeStampEmbedBuilderWidget(),
Expand Down
6 changes: 0 additions & 6 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ PODS:
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- quill_native_bridge (0.0.1):
- FlutterMacOS
- share_plus (0.0.1):
- FlutterMacOS
- sqflite (0.0.3):
Expand All @@ -42,7 +40,6 @@ DEPENDENCIES:
- gal (from `Flutter/ephemeral/.symlinks/plugins/gal/darwin`)
- irondash_engine_context (from `Flutter/ephemeral/.symlinks/plugins/irondash_engine_context/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- quill_native_bridge (from `Flutter/ephemeral/.symlinks/plugins/quill_native_bridge/macos`)
- share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`)
- sqflite (from `Flutter/ephemeral/.symlinks/plugins/sqflite/darwin`)
- super_native_extensions (from `Flutter/ephemeral/.symlinks/plugins/super_native_extensions/macos`)
Expand Down Expand Up @@ -70,8 +67,6 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/irondash_engine_context/macos
path_provider_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
quill_native_bridge:
:path: Flutter/ephemeral/.symlinks/plugins/quill_native_bridge/macos
share_plus:
:path: Flutter/ephemeral/.symlinks/plugins/share_plus/macos
sqflite:
Expand All @@ -93,7 +88,6 @@ SPEC CHECKSUMS:
irondash_engine_context: da62996ee25616d2f01bbeb85dc115d813359478
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
quill_native_bridge: 1a3a4bfab7cbe4ed0232a17d8aae201a3ce6d302
share_plus: 36537c04ce0c3e3f5bd297ce4318b6d5ee5fd6cf
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
super_native_extensions: 85efee3a7495b46b04befcfc86ed12069264ebf3
Expand Down
5 changes: 1 addition & 4 deletions flutter_quill_extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ The package uses the following plugins:
platform-specific setup.
2. [`image_picker`](https://pub.dev/packages/image_picker) for picking images.
See the [Installation](https://pub.dev/packages/image_picker#installation) section.
3. [`youtube_player_flutter`](https://pub.dev/packages/youtube_player_flutter) which
uses [`flutter_inappwebview`](https://pub.dev/packages/flutter_inappwebview) which has a requirement setup on web.
See the [Installation - Web support](https://pub.dev/packages/flutter_inappwebview#installation---web-support).
4. [`super_clipboard`](https://pub.dev/packages/super_clipboard) which needs some setup on Android only, it's used to
3. [`super_clipboard`](https://pub.dev/packages/super_clipboard) which needs some setup on Android only, it's used to
support copying images and pasting them into editor, it's also required to support rich text pasting feature on
non-web platforms, Open the [Android Support](https://pub.dev/packages/super_clipboard#android-support) page for
instructions.
Expand Down
4 changes: 4 additions & 0 deletions flutter_quill_extensions/lib/src/common/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ bool isImageBase64(String imageUrl) {
return !isHttpBasedUrl(imageUrl) && isBase64(imageUrl);
}

@Deprecated(
'Will be removed in future releases. See https://github.com/singerdmx/flutter-quill/issues/2284'
' and https://github.com/singerdmx/flutter-quill/issues/2276',
)
bool isYouTubeUrl(String videoUrl) {
try {
final uri = Uri.parse(videoUrl);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import 'package:flutter/widgets.dart' show GlobalKey;
import 'package:meta/meta.dart' show immutable;
import 'package:flutter/widgets.dart' show GlobalKey, Widget;
import 'package:meta/meta.dart' show experimental, immutable;

import 'youtube_video_support_mode.dart';

@immutable
class QuillEditorVideoEmbedConfigurations {
const QuillEditorVideoEmbedConfigurations({
this.onVideoInit,
this.youtubeVideoSupportMode = YoutubeVideoSupportMode.iframeView,
@Deprecated(
'Loading youtube videos is no longer built-in feature of flutter_quill_extensions.\n'
'See https://github.com/singerdmx/flutter-quill/issues/2284.\n'
'Try to use the experimental `customVideoBuilder` property to implement\n'
'your own YouTube logic using packages such as '
'https://pub.dev/packages/youtube_video_player or https://pub.dev/packages/youtube_player_flutter',
)
this.youtubeVideoSupportMode = YoutubeVideoSupportMode.disabled,
this.ignoreYouTubeSupport = false,
this.customVideoBuilder,
});

/// [onVideoInit] is a callback function that gets triggered when
Expand All @@ -27,5 +36,49 @@ class QuillEditorVideoEmbedConfigurations {

/// Specifies how YouTube videos should be loaded if the video URL
/// is YouTube video.
@Deprecated(
'Loading youtube videos is no longer built-in feature of flutter_quill_extensions.\n'
'See https://github.com/singerdmx/flutter-quill/issues/2284.\n'
'Try to use the experimental `customVideoBuilder` property to implement\n'
'your own YouTube logic using packages such as '
'https://pub.dev/packages/youtube_video_player or https://pub.dev/packages/youtube_player_flutter',
)
final YoutubeVideoSupportMode youtubeVideoSupportMode;

/// Pass `true` to ignore anything related to YouTube which will disable
/// This functionality is without any warnings.
///
/// Making it `true`, means that the video embed widget will no longer
/// check for the video URL and expect it a valid and a standrad video URL.
///
/// This property will be removed in future releases once YouTube support is
/// removed.
///
/// Use [customVideoBuilder] to load youtube videos.
@experimental
@Deprecated(
'Will be removed in future releases. Exist to allow users to ignore warnings.',
)
final bool ignoreYouTubeSupport;

/// [customVideoBuilder] is a callback function that receives the
/// video URL and a read-only flag. This allows users to define
/// their own logic for rendering video widgets, enabling support
/// for various video platforms, such as YouTube.
///
/// Example usage:
/// ```dart
/// customVideoBuilder: (videoUrl, readOnly) {
/// // Return `null` to fallback to defualt logic of QuillEditorVideoEmbedBuilder
///
/// // Return a custom video widget based on the videoUrl
/// return CustomVideoWidget(videoUrl: videoUrl, readOnly: readOnly);
/// },
/// ```
///
/// It's a quick solution as response to https://github.com/singerdmx/flutter-quill/issues/2284
///
/// **Might be removed or changed in future releases.**
@experimental
final Widget? Function(String videoUrl, bool readOnly)? customVideoBuilder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ class QuillEditorWebVideoEmbedConfigurations {
this.constraints,
});

@Deprecated('This property is no longer used.')
final BoxConstraints? constraints;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
/// Enum represents the different modes for handling YouTube video support.
import 'package:meta/meta.dart';

/// **Will be removed soon in future releases**.
@experimental
@Deprecated(
'YouTube video support will be removed soon and completely in the next releases.',
)
enum YoutubeVideoSupportMode {
/// **Will be removed soon in future releases**.
/// Disable loading of YouTube videos.
/// **Will be removed soon in future releases**.
@Deprecated('Loading YouTube videos is already disabled by default.')
disabled,

/// **Will be removed soon in future releases**.
///
/// Load the video using the official YouTube IFrame API.
/// See [YouTube IFrame API](https://developers.google.com/youtube/iframe_api_reference) for more details.
///
/// This will use Platform View on native platforms to use WebView
/// The WebView might not be supported on Desktop and will throw an exception
///
/// See [Flutter InAppWebview Support for Flutter Desktop](https://github.com/pichillilorenzo/flutter_inappwebview/issues/460)
///
/// **Important**: We had to remove [flutter_inappwebview](https://pub.dev/packages/flutter_inappwebview)
/// and [youtube_player_flutter](https://pub.dev/packages/youtube_player_flutter)
/// as non breaking change since most users are unable to build the project,
/// preventing them from using
///
/// **Will be removed soon in future releases**.
@Deprecated(
'This functionality has been removed to fix build failure issues. See https://github.com/singerdmx/flutter-quill/issues/2284 for discussion.',
)
iframeView,

/// **Will be removed soon in future releases**.
///
/// Load the video using a custom video player by fetching the YouTube video URL.
/// Note: This might violate YouTube's terms of service.
/// See [YouTube Terms of Service](https://www.youtube.com/static?template=terms) for more details.
///
/// **WARNING**: We highly suggest to not use this solution,
/// can cause issues with YouTube Terms of Service and require a extra dependency for all users.
/// YouTube servers can reject requests and respond with `Sign in to confirm you’re not a bot`
/// See related issue: https://github.com/Hexer10/youtube_explode_dart/issues/282
///
/// **Will be removed soon in future releases**.
@Deprecated(
'Can cause issues with YouTube Terms of Service and require a extra dependency for all users - Will be removed soon.\n'
'YouTube servers can reject requests and respond with "Sign in to confirm you’re not a bot"\n'
'See related issue https://github.com/Hexer10/youtube_explode_dart/issues/282\n',
)
customPlayerWithDownloadUrl,
}
27 changes: 26 additions & 1 deletion flutter_quill_extensions/lib/src/editor/video/video_embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,35 @@ class QuillEditorVideoEmbedBuilder extends EmbedBuilder {
assert(!kIsWeb, 'Please provide video EmbedBuilder for Web');

final videoUrl = node.value.data;
if (isYouTubeUrl(videoUrl)) {

final customVideoBuilder = configurations.customVideoBuilder;
if (customVideoBuilder != null) {
final videoWidget = customVideoBuilder(videoUrl, readOnly);
if (videoWidget != null) {
return videoWidget;
}
}

// ignore: deprecated_member_use_from_same_package
if (isYouTubeUrl(videoUrl) && !configurations.ignoreYouTubeSupport) {
assert(() {
debugPrint(
"It seems that you're loading a youtube video URL.\n"
'Loading YouTube videos is no longer built-in feature as part of flutter_quill_extensions.\n'
'This message will only appear in development mode. See https://github.com/singerdmx/flutter-quill/issues/2284\n'
'Consider using the experimental property `QuillEditorVideoEmbedConfigurations.customVideoBuilder` in your configuration.\n'
'This message will only included in development mode.\n',
);
return true;
}());

/// Will be removed soon in future releases
// ignore: deprecated_member_use_from_same_package
return YoutubeVideoApp(
videoUrl: videoUrl,
readOnly: readOnly,
// ignore: deprecated_member_use_from_same_package
youtubeVideoSupportMode: configurations.youtubeVideoSupportMode,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:universal_html/html.dart' as html;
import 'package:youtube_player_flutter/youtube_player_flutter.dart'
show YoutubePlayer;

import '../../common/utils/dart_ui/dart_ui_fake.dart'
if (dart.library.js_interop) '../../common/utils/dart_ui/dart_ui_real.dart'
as ui;
import '../../common/utils/element_utils/element_web_utils.dart';
import '../../common/utils/utils.dart';
import 'models/video_web_configurations.dart';
import 'youtube_video_url.dart';

class QuillEditorWebVideoEmbedBuilder extends EmbedBuilder {
const QuillEditorWebVideoEmbedBuilder({
Expand All @@ -34,8 +33,10 @@ class QuillEditorWebVideoEmbedBuilder extends EmbedBuilder {
TextStyle textStyle,
) {
var videoUrl = node.value.data;
// ignore: deprecated_member_use_from_same_package
if (isYouTubeUrl(videoUrl)) {
final youtubeID = YoutubePlayer.convertUrlToId(videoUrl);
// ignore: deprecated_member_use_from_same_package
final youtubeID = convertVideoUrlToId(videoUrl);
if (youtubeID != null) {
videoUrl = 'https://www.youtube.com/embed/$youtubeID';
}
Expand Down
Loading

0 comments on commit 0193230

Please sign in to comment.