Skip to content

Commit 2db6f59

Browse files
committed
use named constructor for raw editor
1 parent 1b44569 commit 2db6f59

File tree

2 files changed

+73
-67
lines changed

2 files changed

+73
-67
lines changed

lib/src/widgets/editor.dart

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ String _standardizeImageUrl(String url) {
145145

146146
bool _isMobile() => io.Platform.isAndroid || io.Platform.isIOS;
147147

148-
Widget _defaultEmbedBuilder(
148+
Widget defaultEmbedBuilder(
149149
BuildContext context, leaf.Embed node, bool readOnly) {
150150
assert(!kIsWeb, 'Please provide EmbedBuilder for Web');
151151
switch (node.value.type) {
@@ -251,7 +251,7 @@ class QuillEditor extends StatefulWidget {
251251
this.onSingleLongTapStart,
252252
this.onSingleLongTapMoveUpdate,
253253
this.onSingleLongTapEnd,
254-
this.embedBuilder = _defaultEmbedBuilder,
254+
this.embedBuilder = defaultEmbedBuilder,
255255
this.customStyleBuilder,
256256
Key? key});
257257

@@ -377,51 +377,53 @@ class _QuillEditorState extends State<QuillEditor>
377377
throw UnimplementedError();
378378
}
379379

380+
final child = RawEditor(
381+
key: _editorKey,
382+
controller: widget.controller,
383+
focusNode: widget.focusNode,
384+
scrollController: widget.scrollController,
385+
scrollable: widget.scrollable,
386+
scrollBottomInset: widget.scrollBottomInset,
387+
padding: widget.padding,
388+
readOnly: widget.readOnly,
389+
placeholder: widget.placeholder,
390+
onLaunchUrl: widget.onLaunchUrl,
391+
toolbarOptions: ToolbarOptions(
392+
copy: widget.enableInteractiveSelection,
393+
cut: widget.enableInteractiveSelection,
394+
paste: widget.enableInteractiveSelection,
395+
selectAll: widget.enableInteractiveSelection,
396+
),
397+
showSelectionHandles: theme.platform == TargetPlatform.iOS ||
398+
theme.platform == TargetPlatform.android,
399+
showCursor: widget.showCursor,
400+
cursorStyle: CursorStyle(
401+
color: cursorColor,
402+
backgroundColor: Colors.grey,
403+
width: 2,
404+
radius: cursorRadius,
405+
offset: cursorOffset,
406+
paintAboveText: widget.paintCursorAboveText ?? paintCursorAboveText,
407+
opacityAnimates: cursorOpacityAnimates,
408+
),
409+
textCapitalization: widget.textCapitalization,
410+
minHeight: widget.minHeight,
411+
maxHeight: widget.maxHeight,
412+
customStyles: widget.customStyles,
413+
expands: widget.expands,
414+
autoFocus: widget.autoFocus,
415+
selectionColor: selectionColor,
416+
selectionCtrls: textSelectionControls,
417+
keyboardAppearance: widget.keyboardAppearance,
418+
enableInteractiveSelection: widget.enableInteractiveSelection,
419+
scrollPhysics: widget.scrollPhysics,
420+
embedBuilder: widget.embedBuilder,
421+
customStyleBuilder: widget.customStyleBuilder,
422+
);
423+
380424
return _selectionGestureDetectorBuilder.build(
381425
HitTestBehavior.translucent,
382-
RawEditor(
383-
_editorKey,
384-
widget.controller,
385-
widget.focusNode,
386-
widget.scrollController,
387-
widget.scrollable,
388-
widget.scrollBottomInset,
389-
widget.padding,
390-
widget.readOnly,
391-
widget.placeholder,
392-
widget.onLaunchUrl,
393-
ToolbarOptions(
394-
copy: widget.enableInteractiveSelection,
395-
cut: widget.enableInteractiveSelection,
396-
paste: widget.enableInteractiveSelection,
397-
selectAll: widget.enableInteractiveSelection,
398-
),
399-
theme.platform == TargetPlatform.iOS ||
400-
theme.platform == TargetPlatform.android,
401-
widget.showCursor,
402-
CursorStyle(
403-
color: cursorColor,
404-
backgroundColor: Colors.grey,
405-
width: 2,
406-
radius: cursorRadius,
407-
offset: cursorOffset,
408-
paintAboveText: widget.paintCursorAboveText ?? paintCursorAboveText,
409-
opacityAnimates: cursorOpacityAnimates,
410-
),
411-
widget.textCapitalization,
412-
widget.maxHeight,
413-
widget.minHeight,
414-
widget.customStyles,
415-
widget.expands,
416-
widget.autoFocus,
417-
selectionColor,
418-
textSelectionControls,
419-
widget.keyboardAppearance,
420-
widget.enableInteractiveSelection,
421-
widget.scrollPhysics,
422-
widget.embedBuilder,
423-
widget.customStyleBuilder,
424-
),
426+
child,
425427
);
426428
}
427429

lib/src/widgets/raw_editor.dart

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,45 @@ import 'text_line.dart';
3232
import 'text_selection.dart';
3333

3434
class RawEditor extends StatefulWidget {
35-
const RawEditor(
36-
Key key,
37-
this.controller,
38-
this.focusNode,
39-
this.scrollController,
40-
this.scrollable,
41-
this.scrollBottomInset,
42-
this.padding,
43-
this.readOnly,
35+
const RawEditor({
36+
required this.controller,
37+
required this.focusNode,
38+
required this.scrollController,
39+
required this.scrollBottomInset,
40+
required this.cursorStyle,
41+
required this.selectionColor,
42+
required this.selectionCtrls,
43+
Key? key,
44+
this.scrollable = true,
45+
this.padding = EdgeInsets.zero,
46+
this.readOnly = false,
4447
this.placeholder,
4548
this.onLaunchUrl,
46-
this.toolbarOptions,
47-
this.showSelectionHandles,
49+
this.toolbarOptions = const ToolbarOptions(
50+
copy: true,
51+
cut: true,
52+
paste: true,
53+
selectAll: true,
54+
),
55+
this.showSelectionHandles = false,
4856
bool? showCursor,
49-
this.cursorStyle,
50-
this.textCapitalization,
57+
this.textCapitalization = TextCapitalization.none,
5158
this.maxHeight,
5259
this.minHeight,
5360
this.customStyles,
54-
this.expands,
55-
this.autoFocus,
56-
this.selectionColor,
57-
this.selectionCtrls,
58-
this.keyboardAppearance,
59-
this.enableInteractiveSelection,
61+
this.expands = false,
62+
this.autoFocus = false,
63+
this.keyboardAppearance = Brightness.light,
64+
this.enableInteractiveSelection = true,
6065
this.scrollPhysics,
61-
this.embedBuilder,
66+
this.embedBuilder = defaultEmbedBuilder,
6267
this.customStyleBuilder,
63-
) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
68+
}) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
6469
assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'),
6570
assert(maxHeight == null || minHeight == null || maxHeight >= minHeight,
6671
'maxHeight cannot be null'),
6772
showCursor = showCursor ?? true,
6873
super(key: key);
69-
7074
final QuillController controller;
7175
final FocusNode focusNode;
7276
final ScrollController scrollController;

0 commit comments

Comments
 (0)