Rename to QuillStyles class

pull/13/head
singerdmx 4 years ago
parent c907f0cce4
commit 9bce3f94fe
  1. 26
      lib/widgets/default_styles.dart
  2. 15
      lib/widgets/editor.dart

@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
class QuillTheme extends InheritedWidget { class QuillStyles extends InheritedWidget {
final DefaultStyles data; final DefaultStyles data;
QuillTheme({ QuillStyles({
Key key, Key key,
@required this.data, @required this.data,
@required Widget child, @required Widget child,
@ -14,12 +14,12 @@ class QuillTheme extends InheritedWidget {
super(key: key, child: child); super(key: key, child: child);
@override @override
bool updateShouldNotify(QuillTheme oldWidget) { bool updateShouldNotify(QuillStyles oldWidget) {
return data != oldWidget.data; return data != oldWidget.data;
} }
static DefaultStyles of(BuildContext context, nullOk) { static DefaultStyles getStyles(BuildContext context, nullOk) {
var widget = context.dependOnInheritedWidgetOfExactType<QuillTheme>(); var widget = context.dependOnInheritedWidgetOfExactType<QuillStyles>();
if (widget == null && nullOk) { if (widget == null && nullOk) {
return null; return null;
} }
@ -157,4 +157,20 @@ class DefaultStyles {
borderRadius: BorderRadius.circular(2), borderRadius: BorderRadius.circular(2),
))); )));
} }
DefaultStyles merge(DefaultStyles other) {
return DefaultStyles(
other.h1 ?? this.h1,
other.h2 ?? this.h2,
other.h3 ?? this.h3,
other.paragraph ?? this.paragraph,
other.bold ?? this.bold,
other.italic ?? this.italic,
other.underline ?? this.underline,
other.strikeThrough ?? this.strikeThrough,
other.link ?? this.link,
other.lists ?? this.lists,
other.quote ?? this.quote,
other.code ?? this.code);
}
} }

@ -9,6 +9,7 @@ import 'package:flutter_quill/models/documents/nodes/container.dart'
as container; as container;
import 'package:flutter_quill/models/documents/nodes/node.dart'; import 'package:flutter_quill/models/documents/nodes/node.dart';
import 'package:flutter_quill/utils/diff_delta.dart'; import 'package:flutter_quill/utils/diff_delta.dart';
import 'package:flutter_quill/widgets/default_styles.dart';
import 'package:flutter_quill/widgets/text_selection.dart'; import 'package:flutter_quill/widgets/text_selection.dart';
import 'box.dart'; import 'box.dart';
@ -324,6 +325,8 @@ class RawEditorState extends EditorState
CursorCont _cursorCont; CursorCont _cursorCont;
ScrollController _scrollController; ScrollController _scrollController;
KeyboardListener _keyboardListener; KeyboardListener _keyboardListener;
bool _didAutoFocus = false;
DefaultStyles _styles;
final ClipboardStatusNotifier _clipboardStatus = ClipboardStatusNotifier(); final ClipboardStatusNotifier _clipboardStatus = ClipboardStatusNotifier();
bool get _hasFocus => widget.focusNode.hasFocus; bool get _hasFocus => widget.focusNode.hasFocus;
@ -736,7 +739,17 @@ class RawEditorState extends EditorState
@override @override
didChangeDependencies() { didChangeDependencies() {
// TODO super.didChangeDependencies();
DefaultStyles parentStyles = QuillStyles.getStyles(context, true);
DefaultStyles defaultStyles = DefaultStyles.getInstance(context);
_styles = (parentStyles != null)
? defaultStyles.merge(parentStyles)
: defaultStyles;
if (!_didAutoFocus && widget.autoFocus) {
FocusScope.of(context).autofocus(widget.focusNode);
_didAutoFocus = true;
}
} }
@override @override

Loading…
Cancel
Save