parent
606806ff6f
commit
97375b5262
12 changed files with 172 additions and 108 deletions
@ -0,0 +1,111 @@ |
||||
import 'package:flutter/material.dart'; |
||||
|
||||
import '../models/themes/quill_dialog_theme.dart'; |
||||
import '../models/themes/quill_icon_theme.dart'; |
||||
import '../widgets/controller.dart'; |
||||
import 'embed_types.dart'; |
||||
import 'toolbar/camera_button.dart'; |
||||
import 'toolbar/formula_button.dart'; |
||||
import 'toolbar/image_button.dart'; |
||||
import 'toolbar/video_button.dart'; |
||||
|
||||
abstract class IEmbedToolbar { |
||||
Iterable<Widget> build(QuillController controller, double toolbarIconSize, |
||||
QuillIconTheme? iconTheme, QuillDialogTheme? dialogTheme); |
||||
|
||||
bool get notEmpty; |
||||
} |
||||
|
||||
class EmbedToolbar implements IEmbedToolbar { |
||||
EmbedToolbar({ |
||||
this.showImageButton = true, |
||||
this.showVideoButton = true, |
||||
this.showCameraButton = true, |
||||
this.showFormulaButton = false, |
||||
this.onImagePickCallback, |
||||
this.onVideoPickCallback, |
||||
this.mediaPickSettingSelector, |
||||
this.cameraPickSettingSelector, |
||||
this.filePickImpl, |
||||
this.webImagePickImpl, |
||||
this.webVideoPickImpl, |
||||
}); |
||||
|
||||
final bool showImageButton; |
||||
final bool showVideoButton; |
||||
final bool showCameraButton; |
||||
final bool showFormulaButton; |
||||
|
||||
final OnImagePickCallback? onImagePickCallback; |
||||
final OnVideoPickCallback? onVideoPickCallback; |
||||
final MediaPickSettingSelector? mediaPickSettingSelector; |
||||
final MediaPickSettingSelector? cameraPickSettingSelector; |
||||
final FilePickImpl? filePickImpl; |
||||
final WebImagePickImpl? webImagePickImpl; |
||||
final WebVideoPickImpl? webVideoPickImpl; |
||||
|
||||
@override |
||||
bool get notEmpty => |
||||
showImageButton || |
||||
showVideoButton || |
||||
(showCameraButton && |
||||
(onImagePickCallback != null || onVideoPickCallback != null)) || |
||||
showFormulaButton; |
||||
|
||||
@override |
||||
Iterable<Widget> build(QuillController controller, double toolbarIconSize, |
||||
QuillIconTheme? iconTheme, QuillDialogTheme? dialogTheme) { |
||||
return [ |
||||
if (showImageButton) |
||||
ImageButton( |
||||
icon: Icons.image, |
||||
iconSize: toolbarIconSize, |
||||
controller: controller, |
||||
onImagePickCallback: onImagePickCallback, |
||||
filePickImpl: filePickImpl, |
||||
webImagePickImpl: webImagePickImpl, |
||||
mediaPickSettingSelector: mediaPickSettingSelector, |
||||
iconTheme: iconTheme, |
||||
dialogTheme: dialogTheme, |
||||
), |
||||
if (showVideoButton) |
||||
VideoButton( |
||||
icon: Icons.movie_creation, |
||||
iconSize: toolbarIconSize, |
||||
controller: controller, |
||||
onVideoPickCallback: onVideoPickCallback, |
||||
filePickImpl: filePickImpl, |
||||
webVideoPickImpl: webImagePickImpl, |
||||
mediaPickSettingSelector: mediaPickSettingSelector, |
||||
iconTheme: iconTheme, |
||||
dialogTheme: dialogTheme, |
||||
), |
||||
if ((onImagePickCallback != null || onVideoPickCallback != null) && |
||||
showCameraButton) |
||||
CameraButton( |
||||
icon: Icons.photo_camera, |
||||
iconSize: toolbarIconSize, |
||||
controller: controller, |
||||
onImagePickCallback: onImagePickCallback, |
||||
onVideoPickCallback: onVideoPickCallback, |
||||
filePickImpl: filePickImpl, |
||||
webImagePickImpl: webImagePickImpl, |
||||
webVideoPickImpl: webVideoPickImpl, |
||||
cameraPickSettingSelector: cameraPickSettingSelector, |
||||
iconTheme: iconTheme, |
||||
), |
||||
if (showFormulaButton) |
||||
FormulaButton( |
||||
icon: Icons.functions, |
||||
iconSize: toolbarIconSize, |
||||
controller: controller, |
||||
onImagePickCallback: onImagePickCallback, |
||||
filePickImpl: filePickImpl, |
||||
webImagePickImpl: webImagePickImpl, |
||||
mediaPickSettingSelector: mediaPickSettingSelector, |
||||
iconTheme: iconTheme, |
||||
dialogTheme: dialogTheme, |
||||
) |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
import 'dart:io'; |
||||
|
||||
import 'package:flutter/material.dart'; |
||||
|
||||
typedef OnImagePickCallback = Future<String?> Function(File file); |
||||
typedef OnVideoPickCallback = Future<String?> Function(File file); |
||||
typedef FilePickImpl = Future<String?> Function(BuildContext context); |
||||
typedef WebImagePickImpl = Future<String?> Function( |
||||
OnImagePickCallback onImagePickCallback); |
||||
typedef WebVideoPickImpl = Future<String?> Function( |
||||
OnVideoPickCallback onImagePickCallback); |
||||
typedef MediaPickSettingSelector = Future<MediaPickSetting?> Function( |
||||
BuildContext context); |
||||
|
||||
enum MediaPickSetting { |
||||
Gallery, |
||||
Link, |
||||
Camera, |
||||
Video, |
||||
} |
Loading…
Reference in new issue