chore: refactor the service type

This commit is contained in:
Lucas.Xu 2022-08-10 15:56:52 +08:00
parent ae0012ba37
commit 1eec97c761
6 changed files with 17 additions and 11 deletions

View File

@ -14,3 +14,7 @@ export 'src/render/selection/selectable.dart';
export 'src/service/editor_service.dart'; export 'src/service/editor_service.dart';
export 'src/service/render_plugin_service.dart'; export 'src/service/render_plugin_service.dart';
export 'src/service/service.dart'; export 'src/service/service.dart';
export 'src/service/selection_service.dart';
export 'src/service/scroll_service.dart';
export 'src/service/keyboard_service.dart';
export 'src/service/input_service.dart';

View File

@ -7,7 +7,7 @@ import 'package:flowy_editor/src/editor_state.dart';
import 'package:flowy_editor/src/extensions/node_extensions.dart'; import 'package:flowy_editor/src/extensions/node_extensions.dart';
import 'package:flowy_editor/src/operation/transaction_builder.dart'; import 'package:flowy_editor/src/operation/transaction_builder.dart';
mixin FlowyInputService { abstract class FlowyInputService {
void attach(TextEditingValue textEditingValue); void attach(TextEditingValue textEditingValue);
void apply(List<TextEditingDelta> deltas); void apply(List<TextEditingDelta> deltas);
void close(); void close();
@ -29,8 +29,7 @@ class FlowyInput extends StatefulWidget {
} }
class _FlowyInputState extends State<FlowyInput> class _FlowyInputState extends State<FlowyInput>
with FlowyInputService implements FlowyInputService, DeltaTextInputClient {
implements DeltaTextInputClient {
TextInputConnection? _textInputConnection; TextInputConnection? _textInputConnection;
TextRange? _composingTextRange; TextRange? _composingTextRange;

View File

@ -3,7 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
mixin FlowyKeyboardService<T extends StatefulWidget> on State<T> { abstract class FlowyKeyboardService {
void enable(); void enable();
void disable(); void disable();
} }
@ -31,7 +31,7 @@ class FlowyKeyboard extends StatefulWidget {
} }
class _FlowyKeyboardState extends State<FlowyKeyboard> class _FlowyKeyboardState extends State<FlowyKeyboard>
with FlowyKeyboardService { implements FlowyKeyboardService {
final FocusNode _focusNode = FocusNode(debugLabel: 'flowy_keyboard_service'); final FocusNode _focusNode = FocusNode(debugLabel: 'flowy_keyboard_service');
bool isFocus = true; bool isFocus = true;

View File

@ -1,7 +1,7 @@
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
mixin FlowyScrollService<T extends StatefulWidget> on State<T> { abstract class FlowyScrollService {
double get dy; double get dy;
void scrollTo(double dy); void scrollTo(double dy);
@ -22,7 +22,8 @@ class FlowyScroll extends StatefulWidget {
State<FlowyScroll> createState() => _FlowyScrollState(); State<FlowyScroll> createState() => _FlowyScrollState();
} }
class _FlowyScrollState extends State<FlowyScroll> with FlowyScrollService { class _FlowyScrollState extends State<FlowyScroll>
implements FlowyScrollService {
final _scrollController = ScrollController(); final _scrollController = ScrollController();
final _scrollViewKey = GlobalKey(); final _scrollViewKey = GlobalKey();

View File

@ -29,7 +29,7 @@ import 'package:flowy_editor/src/render/selection/selection_widget.dart';
/// final nodes = selectionService.currentSelectedNodes; /// final nodes = selectionService.currentSelectedNodes;
/// ``` /// ```
/// ///
mixin FlowySelectionService<T extends StatefulWidget> on State<T> { abstract class FlowySelectionService {
/// The current [Selection] in editor. /// The current [Selection] in editor.
/// ///
/// The value is null if there is no nodes are selected. /// The value is null if there is no nodes are selected.
@ -90,7 +90,8 @@ class FlowySelection extends StatefulWidget {
} }
class _FlowySelectionState extends State<FlowySelection> class _FlowySelectionState extends State<FlowySelection>
with FlowySelectionService, WidgetsBindingObserver { with WidgetsBindingObserver
implements FlowySelectionService {
final _cursorKey = GlobalKey(debugLabel: 'cursor'); final _cursorKey = GlobalKey(debugLabel: 'cursor');
final List<OverlayEntry> _selectionOverlays = []; final List<OverlayEntry> _selectionOverlays = [];

View File

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flowy_editor/flowy_editor.dart'; import 'package:flowy_editor/flowy_editor.dart';
import 'package:flowy_editor/src/render/selection/toolbar_widget.dart'; import 'package:flowy_editor/src/render/selection/toolbar_widget.dart';
mixin FlowyToolbarService { abstract class FlowyToolbarService {
/// Show the toolbar widget beside the offset. /// Show the toolbar widget beside the offset.
void showInOffset(Offset offset, LayerLink layerLink); void showInOffset(Offset offset, LayerLink layerLink);
@ -25,7 +25,8 @@ class FlowyToolbar extends StatefulWidget {
State<FlowyToolbar> createState() => _FlowyToolbarState(); State<FlowyToolbar> createState() => _FlowyToolbarState();
} }
class _FlowyToolbarState extends State<FlowyToolbar> with FlowyToolbarService { class _FlowyToolbarState extends State<FlowyToolbar>
implements FlowyToolbarService {
OverlayEntry? _toolbarOverlay; OverlayEntry? _toolbarOverlay;
@override @override