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.
190 lines
5.9 KiB
190 lines
5.9 KiB
1 year ago
|
// ignore_for_file: use_build_context_synchronously
|
||
|
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_quill/flutter_quill.dart';
|
||
1 year ago
|
import 'package:flutter_quill/translations.dart';
|
||
1 year ago
|
|
||
1 year ago
|
import '../../../models/config/shared_configurations.dart';
|
||
1 year ago
|
import '../../../models/config/toolbar/buttons/video.dart';
|
||
1 year ago
|
import '../../../services/image_picker/image_options.dart';
|
||
|
import '../../others/image_video_utils.dart';
|
||
|
import '../video.dart';
|
||
1 year ago
|
import 'select_video_source.dart';
|
||
1 year ago
|
|
||
|
class QuillToolbarVideoButton extends StatelessWidget {
|
||
|
const QuillToolbarVideoButton({
|
||
|
required this.options,
|
||
|
required this.controller,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final QuillController controller;
|
||
|
|
||
|
final QuillToolbarVideoButtonOptions options;
|
||
|
|
||
|
double _iconSize(BuildContext context) {
|
||
|
final baseFontSize = baseButtonExtraOptions(context).globalIconSize;
|
||
|
final iconSize = options.iconSize;
|
||
|
return iconSize ?? baseFontSize;
|
||
|
}
|
||
|
|
||
|
VoidCallback? _afterButtonPressed(BuildContext context) {
|
||
|
return options.afterButtonPressed ??
|
||
|
baseButtonExtraOptions(context).afterButtonPressed;
|
||
|
}
|
||
|
|
||
|
QuillIconTheme? _iconTheme(BuildContext context) {
|
||
|
return options.iconTheme ?? baseButtonExtraOptions(context).iconTheme;
|
||
|
}
|
||
|
|
||
|
QuillToolbarBaseButtonOptions baseButtonExtraOptions(BuildContext context) {
|
||
|
return context.requireQuillToolbarBaseButtonOptions;
|
||
|
}
|
||
|
|
||
|
IconData _iconData(BuildContext context) {
|
||
|
return options.iconData ??
|
||
|
baseButtonExtraOptions(context).iconData ??
|
||
|
Icons.movie_creation;
|
||
|
}
|
||
|
|
||
|
String _tooltip(BuildContext context) {
|
||
|
return options.tooltip ??
|
||
|
baseButtonExtraOptions(context).tooltip ??
|
||
|
'Insert video';
|
||
|
// ('Insert video'.i18n);
|
||
|
}
|
||
|
|
||
|
void _sharedOnPressed(BuildContext context) {
|
||
|
_onPressedHandler(context);
|
||
|
_afterButtonPressed(context);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final theme = Theme.of(context);
|
||
|
|
||
|
final iconTheme = _iconTheme(context);
|
||
|
|
||
|
final tooltip = _tooltip(context);
|
||
|
final iconSize = _iconSize(context);
|
||
|
final iconData = _iconData(context);
|
||
|
final childBuilder =
|
||
|
options.childBuilder ?? baseButtonExtraOptions(context).childBuilder;
|
||
|
|
||
|
final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
|
||
|
final iconFillColor = iconTheme?.iconUnselectedFillColor ??
|
||
|
(options.fillColor ?? theme.canvasColor);
|
||
|
|
||
|
if (childBuilder != null) {
|
||
|
return childBuilder(
|
||
|
QuillToolbarVideoButtonOptions(
|
||
|
afterButtonPressed: _afterButtonPressed(context),
|
||
|
iconData: iconData,
|
||
|
dialogTheme: options.dialogTheme,
|
||
|
fillColor: iconFillColor,
|
||
|
iconSize: options.iconSize,
|
||
1 year ago
|
iconButtonFactor: options.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(
|
||
|
icon: Icon(iconData, size: iconSize, color: iconColor),
|
||
|
tooltip: tooltip,
|
||
|
highlightElevation: 0,
|
||
|
hoverElevation: 0,
|
||
|
size: iconSize * 1.77,
|
||
|
fillColor: iconFillColor,
|
||
|
borderRadius: iconTheme?.borderRadius ?? 2,
|
||
|
onPressed: () => _sharedOnPressed(context),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
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,
|
||
|
InsertVideoSource.link => await _typeLink(context),
|
||
|
};
|
||
|
if (videoUrl == null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (videoUrl.trim().isNotEmpty) {
|
||
|
await options.videoConfigurations
|
||
|
.onVideoInsertCallback(videoUrl, controller);
|
||
|
await options.videoConfigurations.onVideoInsertedCallback?.call(videoUrl);
|
||
|
}
|
||
|
|
||
|
// if (options.onVideoPickCallback != null) {
|
||
|
// final selector = options.mediaPickSettingSelector ??
|
||
|
// ImageVideoUtils.selectMediaPickSetting;
|
||
|
// final source = await selector(context);
|
||
|
// if (source != null) {
|
||
|
// if (source == MediaPickSetting.gallery) {
|
||
|
// } else {
|
||
|
// await _typeLink(context);
|
||
|
// }
|
||
|
// }
|
||
|
// } else {}
|
||
|
}
|
||
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: (_) => QuillProvider.value(
|
||
|
value: context.requireQuillProvider,
|
||
|
child: FlutterQuillLocalizationsWidget(
|
||
|
child: TypeLinkDialog(
|
||
|
dialogTheme: options.dialogTheme,
|
||
|
linkType: LinkType.video,
|
||
|
),
|
||
|
),
|
||
1 year ago
|
),
|
||
|
);
|
||
1 year ago
|
return value;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
// void _linkSubmitted(String? value) {
|
||
|
// if (value != null && value.isNotEmpty) {
|
||
|
// final index = controller.selection.baseOffset;
|
||
|
// final length = controller.selection.extentOffset - index;
|
||
1 year ago
|
|
||
1 year ago
|
// controller.replaceText(index, length, BlockEmbed.video(value), null);
|
||
|
// }
|
||
|
// }
|
||
1 year ago
|
}
|