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.
129 lines
4.2 KiB
129 lines
4.2 KiB
4 years ago
|
import 'package:flutter/material.dart';
|
||
3 years ago
|
import 'package:flutter_quill/flutter_quill.dart' hide Text;
|
||
4 years ago
|
import 'package:image_picker/image_picker.dart';
|
||
|
|
||
3 years ago
|
import 'package:flutter_quill/translations.dart';
|
||
|
|
||
|
import '../embed_types.dart';
|
||
|
import 'image_video_utils.dart';
|
||
4 years ago
|
|
||
|
class CameraButton extends StatelessWidget {
|
||
|
const CameraButton({
|
||
|
required this.icon,
|
||
|
required this.controller,
|
||
|
this.iconSize = kDefaultIconSize,
|
||
|
this.fillColor,
|
||
|
this.onImagePickCallback,
|
||
|
this.onVideoPickCallback,
|
||
|
this.filePickImpl,
|
||
|
this.webImagePickImpl,
|
||
|
this.webVideoPickImpl,
|
||
3 years ago
|
this.cameraPickSettingSelector,
|
||
4 years ago
|
this.iconTheme,
|
||
4 years ago
|
Key? key,
|
||
|
}) : super(key: key);
|
||
|
|
||
|
final IconData icon;
|
||
|
final double iconSize;
|
||
|
|
||
|
final Color? fillColor;
|
||
|
|
||
|
final QuillController controller;
|
||
|
|
||
|
final OnImagePickCallback? onImagePickCallback;
|
||
|
|
||
|
final OnVideoPickCallback? onVideoPickCallback;
|
||
|
|
||
|
final WebImagePickImpl? webImagePickImpl;
|
||
|
|
||
|
final WebVideoPickImpl? webVideoPickImpl;
|
||
|
|
||
|
final FilePickImpl? filePickImpl;
|
||
|
|
||
3 years ago
|
final MediaPickSettingSelector? cameraPickSettingSelector;
|
||
3 years ago
|
|
||
4 years ago
|
final QuillIconTheme? iconTheme;
|
||
|
|
||
4 years ago
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final theme = Theme.of(context);
|
||
|
|
||
4 years ago
|
final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color;
|
||
|
final iconFillColor =
|
||
|
iconTheme?.iconUnselectedFillColor ?? (fillColor ?? theme.canvasColor);
|
||
|
|
||
4 years ago
|
return QuillIconButton(
|
||
4 years ago
|
icon: Icon(icon, size: iconSize, color: iconColor),
|
||
4 years ago
|
highlightElevation: 0,
|
||
|
hoverElevation: 0,
|
||
|
size: iconSize * 1.77,
|
||
4 years ago
|
fillColor: iconFillColor,
|
||
3 years ago
|
borderRadius: iconTheme?.borderRadius ?? 2,
|
||
3 years ago
|
onPressed: () => _handleCameraButtonTap(context, controller,
|
||
4 years ago
|
onImagePickCallback: onImagePickCallback,
|
||
|
onVideoPickCallback: onVideoPickCallback,
|
||
|
filePickImpl: filePickImpl,
|
||
|
webImagePickImpl: webImagePickImpl),
|
||
|
);
|
||
|
}
|
||
|
|
||
3 years ago
|
Future<void> _handleCameraButtonTap(
|
||
4 years ago
|
BuildContext context, QuillController controller,
|
||
|
{OnImagePickCallback? onImagePickCallback,
|
||
|
OnVideoPickCallback? onVideoPickCallback,
|
||
|
FilePickImpl? filePickImpl,
|
||
|
WebImagePickImpl? webImagePickImpl}) async {
|
||
|
if (onImagePickCallback != null && onVideoPickCallback != null) {
|
||
3 years ago
|
final selector = cameraPickSettingSelector ??
|
||
|
(context) => showDialog<MediaPickSetting>(
|
||
|
context: context,
|
||
|
builder: (ctx) => AlertDialog(
|
||
|
contentPadding: EdgeInsets.zero,
|
||
|
backgroundColor: Colors.transparent,
|
||
|
content: Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: [
|
||
|
TextButton.icon(
|
||
|
icon: const Icon(
|
||
|
Icons.camera,
|
||
|
color: Colors.orangeAccent,
|
||
|
),
|
||
|
label: Text('Camera'.i18n),
|
||
|
onPressed: () =>
|
||
|
Navigator.pop(ctx, MediaPickSetting.Camera),
|
||
|
),
|
||
|
TextButton.icon(
|
||
|
icon: const Icon(
|
||
|
Icons.video_call,
|
||
|
color: Colors.cyanAccent,
|
||
|
),
|
||
|
label: Text('Video'.i18n),
|
||
|
onPressed: () =>
|
||
|
Navigator.pop(ctx, MediaPickSetting.Video),
|
||
|
)
|
||
|
],
|
||
3 years ago
|
),
|
||
3 years ago
|
),
|
||
|
);
|
||
|
|
||
|
final source = await selector(context);
|
||
|
if (source != null) {
|
||
|
switch (source) {
|
||
|
case MediaPickSetting.Camera:
|
||
|
await ImageVideoUtils.handleImageButtonTap(
|
||
|
context, controller, ImageSource.camera, onImagePickCallback,
|
||
|
filePickImpl: filePickImpl, webImagePickImpl: webImagePickImpl);
|
||
|
break;
|
||
|
case MediaPickSetting.Video:
|
||
|
await ImageVideoUtils.handleVideoButtonTap(
|
||
|
context, controller, ImageSource.camera, onVideoPickCallback,
|
||
|
filePickImpl: filePickImpl, webVideoPickImpl: webVideoPickImpl);
|
||
|
break;
|
||
|
default:
|
||
|
throw ArgumentError('Invalid MediaSetting');
|
||
|
}
|
||
|
}
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
}
|