use named constructor for raw editor

pull/515/head
li3317 3 years ago
parent 1b44569436
commit 2db6f59dac
  1. 92
      lib/src/widgets/editor.dart
  2. 48
      lib/src/widgets/raw_editor.dart

@ -145,7 +145,7 @@ String _standardizeImageUrl(String url) {
bool _isMobile() => io.Platform.isAndroid || io.Platform.isIOS; bool _isMobile() => io.Platform.isAndroid || io.Platform.isIOS;
Widget _defaultEmbedBuilder( Widget defaultEmbedBuilder(
BuildContext context, leaf.Embed node, bool readOnly) { BuildContext context, leaf.Embed node, bool readOnly) {
assert(!kIsWeb, 'Please provide EmbedBuilder for Web'); assert(!kIsWeb, 'Please provide EmbedBuilder for Web');
switch (node.value.type) { switch (node.value.type) {
@ -251,7 +251,7 @@ class QuillEditor extends StatefulWidget {
this.onSingleLongTapStart, this.onSingleLongTapStart,
this.onSingleLongTapMoveUpdate, this.onSingleLongTapMoveUpdate,
this.onSingleLongTapEnd, this.onSingleLongTapEnd,
this.embedBuilder = _defaultEmbedBuilder, this.embedBuilder = defaultEmbedBuilder,
this.customStyleBuilder, this.customStyleBuilder,
Key? key}); Key? key});
@ -377,51 +377,53 @@ class _QuillEditorState extends State<QuillEditor>
throw UnimplementedError(); throw UnimplementedError();
} }
final child = RawEditor(
key: _editorKey,
controller: widget.controller,
focusNode: widget.focusNode,
scrollController: widget.scrollController,
scrollable: widget.scrollable,
scrollBottomInset: widget.scrollBottomInset,
padding: widget.padding,
readOnly: widget.readOnly,
placeholder: widget.placeholder,
onLaunchUrl: widget.onLaunchUrl,
toolbarOptions: ToolbarOptions(
copy: widget.enableInteractiveSelection,
cut: widget.enableInteractiveSelection,
paste: widget.enableInteractiveSelection,
selectAll: widget.enableInteractiveSelection,
),
showSelectionHandles: theme.platform == TargetPlatform.iOS ||
theme.platform == TargetPlatform.android,
showCursor: widget.showCursor,
cursorStyle: CursorStyle(
color: cursorColor,
backgroundColor: Colors.grey,
width: 2,
radius: cursorRadius,
offset: cursorOffset,
paintAboveText: widget.paintCursorAboveText ?? paintCursorAboveText,
opacityAnimates: cursorOpacityAnimates,
),
textCapitalization: widget.textCapitalization,
minHeight: widget.minHeight,
maxHeight: widget.maxHeight,
customStyles: widget.customStyles,
expands: widget.expands,
autoFocus: widget.autoFocus,
selectionColor: selectionColor,
selectionCtrls: textSelectionControls,
keyboardAppearance: widget.keyboardAppearance,
enableInteractiveSelection: widget.enableInteractiveSelection,
scrollPhysics: widget.scrollPhysics,
embedBuilder: widget.embedBuilder,
customStyleBuilder: widget.customStyleBuilder,
);
return _selectionGestureDetectorBuilder.build( return _selectionGestureDetectorBuilder.build(
HitTestBehavior.translucent, HitTestBehavior.translucent,
RawEditor( child,
_editorKey,
widget.controller,
widget.focusNode,
widget.scrollController,
widget.scrollable,
widget.scrollBottomInset,
widget.padding,
widget.readOnly,
widget.placeholder,
widget.onLaunchUrl,
ToolbarOptions(
copy: widget.enableInteractiveSelection,
cut: widget.enableInteractiveSelection,
paste: widget.enableInteractiveSelection,
selectAll: widget.enableInteractiveSelection,
),
theme.platform == TargetPlatform.iOS ||
theme.platform == TargetPlatform.android,
widget.showCursor,
CursorStyle(
color: cursorColor,
backgroundColor: Colors.grey,
width: 2,
radius: cursorRadius,
offset: cursorOffset,
paintAboveText: widget.paintCursorAboveText ?? paintCursorAboveText,
opacityAnimates: cursorOpacityAnimates,
),
widget.textCapitalization,
widget.maxHeight,
widget.minHeight,
widget.customStyles,
widget.expands,
widget.autoFocus,
selectionColor,
textSelectionControls,
widget.keyboardAppearance,
widget.enableInteractiveSelection,
widget.scrollPhysics,
widget.embedBuilder,
widget.customStyleBuilder,
),
); );
} }

@ -32,41 +32,45 @@ import 'text_line.dart';
import 'text_selection.dart'; import 'text_selection.dart';
class RawEditor extends StatefulWidget { class RawEditor extends StatefulWidget {
const RawEditor( const RawEditor({
Key key, required this.controller,
this.controller, required this.focusNode,
this.focusNode, required this.scrollController,
this.scrollController, required this.scrollBottomInset,
this.scrollable, required this.cursorStyle,
this.scrollBottomInset, required this.selectionColor,
this.padding, required this.selectionCtrls,
this.readOnly, Key? key,
this.scrollable = true,
this.padding = EdgeInsets.zero,
this.readOnly = false,
this.placeholder, this.placeholder,
this.onLaunchUrl, this.onLaunchUrl,
this.toolbarOptions, this.toolbarOptions = const ToolbarOptions(
this.showSelectionHandles, copy: true,
cut: true,
paste: true,
selectAll: true,
),
this.showSelectionHandles = false,
bool? showCursor, bool? showCursor,
this.cursorStyle, this.textCapitalization = TextCapitalization.none,
this.textCapitalization,
this.maxHeight, this.maxHeight,
this.minHeight, this.minHeight,
this.customStyles, this.customStyles,
this.expands, this.expands = false,
this.autoFocus, this.autoFocus = false,
this.selectionColor, this.keyboardAppearance = Brightness.light,
this.selectionCtrls, this.enableInteractiveSelection = true,
this.keyboardAppearance,
this.enableInteractiveSelection,
this.scrollPhysics, this.scrollPhysics,
this.embedBuilder, this.embedBuilder = defaultEmbedBuilder,
this.customStyleBuilder, this.customStyleBuilder,
) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'), }) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'), assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'),
assert(maxHeight == null || minHeight == null || maxHeight >= minHeight, assert(maxHeight == null || minHeight == null || maxHeight >= minHeight,
'maxHeight cannot be null'), 'maxHeight cannot be null'),
showCursor = showCursor ?? true, showCursor = showCursor ?? true,
super(key: key); super(key: key);
final QuillController controller; final QuillController controller;
final FocusNode focusNode; final FocusNode focusNode;
final ScrollController scrollController; final ScrollController scrollController;

Loading…
Cancel
Save