image_button.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:flutter_quill/flutter_quill.dart';
  2. import 'package:flutter/material.dart';
  3. import 'toolbar_icon_button.dart';
  4. class FlowyImageButton extends StatelessWidget {
  5. const FlowyImageButton({
  6. required this.controller,
  7. required this.tooltipText,
  8. this.iconSize = defaultIconSize,
  9. this.onImagePickCallback,
  10. this.fillColor,
  11. this.filePickImpl,
  12. this.webImagePickImpl,
  13. this.mediaPickSettingSelector,
  14. Key? key,
  15. }) : super(key: key);
  16. final double iconSize;
  17. final Color? fillColor;
  18. final QuillController controller;
  19. final OnImagePickCallback? onImagePickCallback;
  20. final WebImagePickImpl? webImagePickImpl;
  21. final FilePickImpl? filePickImpl;
  22. final MediaPickSettingSelector? mediaPickSettingSelector;
  23. final String tooltipText;
  24. @override
  25. Widget build(BuildContext context) {
  26. return ToolbarIconButton(
  27. iconName: 'editor/image',
  28. width: iconSize * 1.77,
  29. onPressed: () => _onPressedHandler(context),
  30. isToggled: false,
  31. tooltipText: tooltipText,
  32. );
  33. }
  34. Future<void> _onPressedHandler(BuildContext context) async {
  35. // if (onImagePickCallback != null) {
  36. // final selector = mediaPickSettingSelector ?? ImageVideoUtils.selectMediaPickSetting;
  37. // final source = await selector(context);
  38. // if (source != null) {
  39. // if (source == MediaPickSetting.Gallery) {
  40. // _pickImage(context);
  41. // } else {
  42. // _typeLink(context);
  43. // }
  44. // }
  45. // } else {
  46. // _typeLink(context);
  47. // }
  48. }
  49. // void _pickImage(BuildContext context) => ImageVideoUtils.handleImageButtonTap(
  50. // context,
  51. // controller,
  52. // ImageSource.gallery,
  53. // onImagePickCallback!,
  54. // filePickImpl: filePickImpl,
  55. // webImagePickImpl: webImagePickImpl,
  56. // );
  57. // void _typeLink(BuildContext context) {
  58. // TextFieldDialog(
  59. // title: 'URL',
  60. // value: "",
  61. // confirm: (newValue) {
  62. // if (newValue.isEmpty) {
  63. // return;
  64. // }
  65. // final index = controller.selection.baseOffset;
  66. // final length = controller.selection.extentOffset - index;
  67. // controller.replaceText(index, length, BlockEmbed.image(newValue), null);
  68. // },
  69. // ).show(context);
  70. // }
  71. }