dartlangeditorflutterflutter-appsflutter-examplesflutter-packageflutter-widgetquillquill-deltaquilljsreactquillrich-textrich-text-editorwysiwygwysiwyg-editor
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
5.1 KiB
165 lines
5.1 KiB
1 year ago
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_quill/flutter_quill.dart';
|
||
1 year ago
|
import 'package:flutter_quill/translations.dart';
|
||
1 year ago
|
|
||
8 months ago
|
import '../../common/image_video_utils.dart';
|
||
|
import '../../editor_toolbar_shared/image_picker/image_options.dart';
|
||
|
import '../../editor_toolbar_shared/shared_configurations.dart';
|
||
|
import 'models/video.dart';
|
||
|
import 'models/video_configurations.dart';
|
||
1 year ago
|
import 'select_video_source.dart';
|
||
1 year ago
|
|
||
10 months ago
|
// TODO: Add custom callback to validate the video link input
|
||
|
|
||
1 year ago
|
class QuillToolbarVideoButton extends StatelessWidget {
|
||
|
const QuillToolbarVideoButton({
|
||
|
required this.controller,
|
||
1 year ago
|
this.options = const QuillToolbarVideoButtonOptions(),
|
||
1 year ago
|
super.key,
|
||
|
});
|
||
|
|
||
|
final QuillController controller;
|
||
|
|
||
|
final QuillToolbarVideoButtonOptions options;
|
||
|
|
||
|
double _iconSize(BuildContext context) {
|
||
1 year ago
|
final baseFontSize = baseButtonExtraOptions(context)?.iconSize;
|
||
1 year ago
|
final iconSize = options.iconSize;
|
||
1 year ago
|
return iconSize ?? baseFontSize ?? kDefaultIconSize;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
double _iconButtonFactor(BuildContext context) {
|
||
1 year ago
|
final baseIconFactor = baseButtonExtraOptions(context)?.iconButtonFactor;
|
||
1 year ago
|
final iconButtonFactor = options.iconButtonFactor;
|
||
1 year ago
|
return iconButtonFactor ?? baseIconFactor ?? kDefaultIconButtonFactor;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
VoidCallback? _afterButtonPressed(BuildContext context) {
|
||
|
return options.afterButtonPressed ??
|
||
1 year ago
|
baseButtonExtraOptions(context)?.afterButtonPressed;
|
||
1 year ago
|
}
|
||
|
|
||
|
QuillIconTheme? _iconTheme(BuildContext context) {
|
||
1 year ago
|
return options.iconTheme ?? baseButtonExtraOptions(context)?.iconTheme;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
QuillToolbarBaseButtonOptions? baseButtonExtraOptions(BuildContext context) {
|
||
|
return context.quillToolbarBaseButtonOptions;
|
||
1 year ago
|
}
|
||
|
|
||
|
IconData _iconData(BuildContext context) {
|
||
|
return options.iconData ??
|
||
1 year ago
|
baseButtonExtraOptions(context)?.iconData ??
|
||
1 year ago
|
Icons.movie_creation;
|
||
|
}
|
||
|
|
||
|
String _tooltip(BuildContext context) {
|
||
|
return options.tooltip ??
|
||
1 year ago
|
baseButtonExtraOptions(context)?.tooltip ??
|
||
1 year ago
|
'Insert video';
|
||
|
// ('Insert video'.i18n);
|
||
|
}
|
||
|
|
||
|
void _sharedOnPressed(BuildContext context) {
|
||
|
_onPressedHandler(context);
|
||
|
_afterButtonPressed(context);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final tooltip = _tooltip(context);
|
||
|
final iconSize = _iconSize(context);
|
||
1 year ago
|
final iconButtonFactor = _iconButtonFactor(context);
|
||
1 year ago
|
final iconData = _iconData(context);
|
||
|
final childBuilder =
|
||
1 year ago
|
options.childBuilder ?? baseButtonExtraOptions(context)?.childBuilder;
|
||
1 year ago
|
|
||
|
if (childBuilder != null) {
|
||
|
return childBuilder(
|
||
|
QuillToolbarVideoButtonOptions(
|
||
|
afterButtonPressed: _afterButtonPressed(context),
|
||
|
iconData: iconData,
|
||
|
dialogTheme: options.dialogTheme,
|
||
|
iconSize: options.iconSize,
|
||
1 year ago
|
iconButtonFactor: iconButtonFactor,
|
||
1 year ago
|
linkRegExp: options.linkRegExp,
|
||
|
tooltip: options.tooltip,
|
||
|
iconTheme: options.iconTheme,
|
||
1 year ago
|
videoConfigurations: options.videoConfigurations,
|
||
1 year ago
|
),
|
||
|
QuillToolbarVideoButtonExtraOptions(
|
||
|
context: context,
|
||
|
controller: controller,
|
||
|
onPressed: () => _sharedOnPressed(context),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return QuillToolbarIconButton(
|
||
1 year ago
|
icon: Icon(
|
||
|
iconData,
|
||
|
size: iconSize * iconButtonFactor,
|
||
|
),
|
||
1 year ago
|
tooltip: tooltip,
|
||
1 year ago
|
isSelected: false,
|
||
1 year ago
|
onPressed: () => _sharedOnPressed(context),
|
||
1 year ago
|
iconTheme: _iconTheme(context),
|
||
1 year ago
|
);
|
||
|
}
|
||
|
|
||
|
Future<void> _onPressedHandler(BuildContext context) async {
|
||
1 year ago
|
final imagePickerService =
|
||
|
QuillSharedExtensionsConfigurations.get(context: context)
|
||
|
.imagePickerService;
|
||
|
|
||
|
final onRequestPickVideo = options.videoConfigurations.onRequestPickVideo;
|
||
|
if (onRequestPickVideo != null) {
|
||
|
final videoUrl = await onRequestPickVideo(context, imagePickerService);
|
||
|
if (videoUrl != null) {
|
||
|
await options.videoConfigurations
|
||
|
.onVideoInsertCallback(videoUrl, controller);
|
||
|
await options.videoConfigurations.onVideoInsertedCallback
|
||
|
?.call(videoUrl);
|
||
1 year ago
|
}
|
||
1 year ago
|
return;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
final imageSource = await showSelectVideoSourceDialog(context: context);
|
||
|
|
||
|
if (imageSource == null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
final videoUrl = switch (imageSource) {
|
||
|
InsertVideoSource.gallery =>
|
||
|
(await imagePickerService.pickVideo(source: ImageSource.gallery))?.path,
|
||
|
InsertVideoSource.camera =>
|
||
|
(await imagePickerService.pickVideo(source: ImageSource.camera))?.path,
|
||
1 year ago
|
InsertVideoSource.link =>
|
||
|
context.mounted ? await _typeLink(context) : null,
|
||
1 year ago
|
};
|
||
|
if (videoUrl == null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (videoUrl.trim().isNotEmpty) {
|
||
|
await options.videoConfigurations
|
||
|
.onVideoInsertCallback(videoUrl, controller);
|
||
|
await options.videoConfigurations.onVideoInsertedCallback?.call(videoUrl);
|
||
|
}
|
||
|
}
|
||
1 year ago
|
|
||
1 year ago
|
Future<String?> _typeLink(BuildContext context) async {
|
||
1 year ago
|
final value = await showDialog<String>(
|
||
|
context: context,
|
||
1 year ago
|
builder: (_) => FlutterQuillLocalizationsWidget(
|
||
|
child: TypeLinkDialog(
|
||
|
dialogTheme: options.dialogTheme,
|
||
|
linkType: LinkType.video,
|
||
1 year ago
|
),
|
||
1 year ago
|
),
|
||
|
);
|
||
1 year ago
|
return value;
|
||
1 year ago
|
}
|
||
|
}
|