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.
174 lines
5.1 KiB
174 lines
5.1 KiB
1 year ago
|
import 'package:flutter/material.dart';
|
||
1 year ago
|
import 'package:flutter_quill/flutter_quill.dart'
|
||
|
show
|
||
|
QuillController,
|
||
|
QuillIconTheme,
|
||
1 year ago
|
QuillSimpleToolbarExt,
|
||
1 year ago
|
QuillToolbarBaseButtonOptions,
|
||
1 year ago
|
QuillToolbarIconButton,
|
||
|
kDefaultIconSize,
|
||
1 year ago
|
kDefaultIconButtonFactor;
|
||
1 year ago
|
import 'package:flutter_quill/translations.dart';
|
||
|
|
||
8 months ago
|
import '../../editor_toolbar_shared/image_picker/image_options.dart';
|
||
|
import '../../editor_toolbar_shared/shared_configurations.dart';
|
||
1 year ago
|
import 'camera_types.dart';
|
||
8 months ago
|
import 'models/camera_configurations.dart';
|
||
1 year ago
|
import 'select_camera_action.dart';
|
||
1 year ago
|
|
||
|
class QuillToolbarCameraButton extends StatelessWidget {
|
||
|
const QuillToolbarCameraButton({
|
||
|
required this.controller,
|
||
1 year ago
|
this.options = const QuillToolbarCameraButtonOptions(),
|
||
1 year ago
|
super.key,
|
||
|
});
|
||
|
|
||
|
final QuillController controller;
|
||
|
final QuillToolbarCameraButtonOptions 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.photo_camera;
|
||
|
}
|
||
|
|
||
|
String _tooltip(BuildContext context) {
|
||
|
return options.tooltip ??
|
||
1 year ago
|
baseButtonExtraOptions(context)?.tooltip ??
|
||
1 year ago
|
context.loc.camera;
|
||
1 year ago
|
}
|
||
|
|
||
|
void _sharedOnPressed(BuildContext context) {
|
||
|
_onPressedHandler(
|
||
|
context,
|
||
|
controller,
|
||
|
);
|
||
|
_afterButtonPressed(context);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final iconTheme = _iconTheme(context);
|
||
|
final tooltip = _tooltip(context);
|
||
|
final iconSize = _iconSize(context);
|
||
|
final iconData = _iconData(context);
|
||
1 year ago
|
final iconButtonFactor = _iconButtonFactor(context);
|
||
1 year ago
|
|
||
|
final childBuilder =
|
||
1 year ago
|
options.childBuilder ?? baseButtonExtraOptions(context)?.childBuilder;
|
||
1 year ago
|
|
||
|
if (childBuilder != null) {
|
||
|
childBuilder(
|
||
|
QuillToolbarCameraButtonOptions(
|
||
|
afterButtonPressed: _afterButtonPressed(context),
|
||
|
iconData: options.iconData,
|
||
|
iconSize: options.iconSize,
|
||
1 year ago
|
iconButtonFactor: iconButtonFactor,
|
||
1 year ago
|
iconTheme: options.iconTheme,
|
||
|
tooltip: options.tooltip,
|
||
1 year ago
|
cameraConfigurations: options.cameraConfigurations,
|
||
1 year ago
|
),
|
||
|
QuillToolbarCameraButtonExtraOptions(
|
||
|
controller: controller,
|
||
|
context: context,
|
||
|
onPressed: () => _sharedOnPressed(context),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return QuillToolbarIconButton(
|
||
1 year ago
|
icon: Icon(
|
||
|
iconData,
|
||
|
size: iconButtonFactor * iconSize,
|
||
|
),
|
||
1 year ago
|
tooltip: tooltip,
|
||
1 year ago
|
isSelected: false,
|
||
1 year ago
|
// isDesktop(supportWeb: false) ? null :
|
||
1 year ago
|
onPressed: () => _sharedOnPressed(context),
|
||
1 year ago
|
iconTheme: iconTheme,
|
||
1 year ago
|
);
|
||
|
}
|
||
|
|
||
1 year ago
|
Future<CameraAction?> _getCameraAction(BuildContext context) async {
|
||
|
final customCallback =
|
||
|
options.cameraConfigurations.onRequestCameraActionCallback;
|
||
|
if (customCallback != null) {
|
||
|
return await customCallback(context);
|
||
|
}
|
||
1 year ago
|
final cameraAction = await showSelectCameraActionDialog(
|
||
1 year ago
|
context: context,
|
||
|
);
|
||
|
|
||
|
return cameraAction;
|
||
|
}
|
||
|
|
||
1 year ago
|
Future<void> _onPressedHandler(
|
||
|
BuildContext context,
|
||
1 year ago
|
QuillController controller,
|
||
|
) async {
|
||
1 year ago
|
final imagePickerService =
|
||
|
QuillSharedExtensionsConfigurations.get(context: context)
|
||
|
.imagePickerService;
|
||
1 year ago
|
|
||
|
final cameraAction = await _getCameraAction(context);
|
||
|
|
||
|
if (cameraAction == null) {
|
||
1 year ago
|
return;
|
||
|
}
|
||
1 year ago
|
|
||
|
switch (cameraAction) {
|
||
|
case CameraAction.video:
|
||
|
final videoFile = await imagePickerService.pickVideo(
|
||
|
source: ImageSource.camera,
|
||
1 year ago
|
);
|
||
1 year ago
|
if (videoFile == null) {
|
||
|
return;
|
||
|
}
|
||
1 year ago
|
await options.cameraConfigurations.onVideoInsertCallback(
|
||
|
videoFile.path,
|
||
|
controller,
|
||
|
);
|
||
|
await options.cameraConfigurations.onVideoInsertedCallback
|
||
|
?.call(videoFile.path);
|
||
1 year ago
|
case CameraAction.image:
|
||
|
final imageFile = await imagePickerService.pickImage(
|
||
|
source: ImageSource.camera,
|
||
1 year ago
|
);
|
||
1 year ago
|
if (imageFile == null) {
|
||
|
return;
|
||
|
}
|
||
1 year ago
|
await options.cameraConfigurations.onImageInsertCallback(
|
||
1 year ago
|
imageFile.path,
|
||
|
controller,
|
||
1 year ago
|
);
|
||
1 year ago
|
await options.cameraConfigurations.onImageInsertedCallback
|
||
|
?.call(imageFile.path);
|
||
1 year ago
|
}
|
||
|
}
|
||
|
}
|