use named constructor for raw editor

pull/515/head
li3317 3 years ago
parent 1b44569436
commit 2db6f59dac
  1. 68
      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,29 +377,27 @@ class _QuillEditorState extends State<QuillEditor>
throw UnimplementedError(); throw UnimplementedError();
} }
return _selectionGestureDetectorBuilder.build( final child = RawEditor(
HitTestBehavior.translucent, key: _editorKey,
RawEditor( controller: widget.controller,
_editorKey, focusNode: widget.focusNode,
widget.controller, scrollController: widget.scrollController,
widget.focusNode, scrollable: widget.scrollable,
widget.scrollController, scrollBottomInset: widget.scrollBottomInset,
widget.scrollable, padding: widget.padding,
widget.scrollBottomInset, readOnly: widget.readOnly,
widget.padding, placeholder: widget.placeholder,
widget.readOnly, onLaunchUrl: widget.onLaunchUrl,
widget.placeholder, toolbarOptions: ToolbarOptions(
widget.onLaunchUrl,
ToolbarOptions(
copy: widget.enableInteractiveSelection, copy: widget.enableInteractiveSelection,
cut: widget.enableInteractiveSelection, cut: widget.enableInteractiveSelection,
paste: widget.enableInteractiveSelection, paste: widget.enableInteractiveSelection,
selectAll: widget.enableInteractiveSelection, selectAll: widget.enableInteractiveSelection,
), ),
theme.platform == TargetPlatform.iOS || showSelectionHandles: theme.platform == TargetPlatform.iOS ||
theme.platform == TargetPlatform.android, theme.platform == TargetPlatform.android,
widget.showCursor, showCursor: widget.showCursor,
CursorStyle( cursorStyle: CursorStyle(
color: cursorColor, color: cursorColor,
backgroundColor: Colors.grey, backgroundColor: Colors.grey,
width: 2, width: 2,
@ -408,20 +406,24 @@ class _QuillEditorState extends State<QuillEditor>
paintAboveText: widget.paintCursorAboveText ?? paintCursorAboveText, paintAboveText: widget.paintCursorAboveText ?? paintCursorAboveText,
opacityAnimates: cursorOpacityAnimates, opacityAnimates: cursorOpacityAnimates,
), ),
widget.textCapitalization, textCapitalization: widget.textCapitalization,
widget.maxHeight, minHeight: widget.minHeight,
widget.minHeight, maxHeight: widget.maxHeight,
widget.customStyles, customStyles: widget.customStyles,
widget.expands, expands: widget.expands,
widget.autoFocus, autoFocus: widget.autoFocus,
selectionColor, selectionColor: selectionColor,
textSelectionControls, selectionCtrls: textSelectionControls,
widget.keyboardAppearance, keyboardAppearance: widget.keyboardAppearance,
widget.enableInteractiveSelection, enableInteractiveSelection: widget.enableInteractiveSelection,
widget.scrollPhysics, scrollPhysics: widget.scrollPhysics,
widget.embedBuilder, embedBuilder: widget.embedBuilder,
widget.customStyleBuilder, customStyleBuilder: widget.customStyleBuilder,
), );
return _selectionGestureDetectorBuilder.build(
HitTestBehavior.translucent,
child,
); );
} }

@ -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