Deprecate controller access through configurations

pull/2078/head
AtlasAutocode 9 months ago
parent d354ab21f9
commit 06d09b196a
  1. 16
      example/lib/screens/quill/quill_screen.dart
  2. 4
      lib/src/controller/provider.dart
  3. 16
      lib/src/controller/quill_controller.dart
  4. 12
      lib/src/controller/quill_controller_configurations.dart
  5. 3
      lib/src/editor/config/editor_configurations.dart
  6. 1
      lib/src/editor/editor.dart
  7. 1
      lib/src/editor/provider.dart
  8. 1
      lib/src/editor/raw_editor/config/raw_editor_configurations.dart
  9. 5
      lib/src/editor/raw_editor/raw_editor.dart
  10. 2
      lib/src/editor/raw_editor/raw_editor_state.dart
  11. 1
      lib/src/toolbar/config/simple_toolbar_configurations.dart
  12. 7
      lib/src/toolbar/simple_toolbar.dart

@ -34,17 +34,7 @@ class QuillScreen extends StatefulWidget {
class _QuillScreenState extends State<QuillScreen> { class _QuillScreenState extends State<QuillScreen> {
/// Instantiate the controller /// Instantiate the controller
final _controller = QuillController.basic( final _controller = QuillController.basic();
configurations: const QuillControllerConfigurations(
/// Set default editor configuration (Recommended if configuration will never change, but can be overridden when editor is built)
editorConfigurations:
QuillEditorConfigurations(padding: EdgeInsets.all(5)),
/// Set default toolbar configuration (Recommended if configuration will never change, but can be overridden when toolbar is built)
toolbarConfigurations: QuillSimpleToolbarConfigurations(
searchButtonType: SearchButtonType.modern)),
);
final _editorFocusNode = FocusNode(); final _editorFocusNode = FocusNode();
final _editorScrollController = ScrollController(); final _editorScrollController = ScrollController();
var _isReadOnly = false; var _isReadOnly = false;
@ -113,10 +103,6 @@ class _QuillScreenState extends State<QuillScreen> {
return Expanded( return Expanded(
child: MyQuillEditor( child: MyQuillEditor(
controller: _controller, controller: _controller,
/// configurations parameter:
/// Optional: if not provided will use the configuration set when the controller was instantiated.
/// Override: Provide parameter here to override the default configuration - useful if configuration will change.
configurations: QuillEditorConfigurations( configurations: QuillEditorConfigurations(
sharedConfigurations: _sharedConfigurations, sharedConfigurations: _sharedConfigurations,
), ),

@ -6,12 +6,16 @@ import 'quill_controller.dart';
extension QuillControllerExt on BuildContext { extension QuillControllerExt on BuildContext {
QuillController? get quilController { QuillController? get quilController {
// ignore: deprecated_member_use_from_same_package
return quillSimpleToolbarConfigurations?.controller ?? return quillSimpleToolbarConfigurations?.controller ??
// ignore: deprecated_member_use_from_same_package
quillEditorConfigurations?.controller; quillEditorConfigurations?.controller;
} }
QuillController get requireQuillController { QuillController get requireQuillController {
// ignore: deprecated_member_use_from_same_package
return quillSimpleToolbarConfigurations?.controller ?? return quillSimpleToolbarConfigurations?.controller ??
// ignore: deprecated_member_use_from_same_package
quillEditorConfigurations?.controller ?? quillEditorConfigurations?.controller ??
(throw ArgumentError( (throw ArgumentError(
'The quill provider is required, you must only call requireQuillController inside the QuillToolbar and QuillEditor')); 'The quill provider is required, you must only call requireQuillController inside the QuillToolbar and QuillEditor'));

@ -55,27 +55,19 @@ class QuillController extends ChangeNotifier {
/// Editor configurations /// Editor configurations
/// ///
/// Global default can be set in QuillControllerConfigurations. /// Caches configuration set in QuillEditor ctor.
/// Can be overridden by setting in QuillEditor ctor.
/// Fail safe: returns a default editor configuration.
QuillEditorConfigurations? _editorConfigurations; QuillEditorConfigurations? _editorConfigurations;
QuillEditorConfigurations get editorConfigurations => QuillEditorConfigurations get editorConfigurations =>
_editorConfigurations ?? _editorConfigurations ?? const QuillEditorConfigurations();
configurations.editorConfigurations ??
const QuillEditorConfigurations();
set editorConfigurations(QuillEditorConfigurations? value) => set editorConfigurations(QuillEditorConfigurations? value) =>
_editorConfigurations = value; _editorConfigurations = value;
/// Toolbar configurations /// Toolbar configurations
/// ///
/// Global default can be set in QuillControllerConfigurations. /// Caches configuration set in QuillSimpleToolbar ctor.
/// Can be overridden by setting in QuillSimpleToolbar ctor.
/// Fail safe: returns a default toolbar configuration.
QuillSimpleToolbarConfigurations? _toolbarConfigurations; QuillSimpleToolbarConfigurations? _toolbarConfigurations;
QuillSimpleToolbarConfigurations get toolbarConfigurations => QuillSimpleToolbarConfigurations get toolbarConfigurations =>
_toolbarConfigurations ?? _toolbarConfigurations ?? const QuillSimpleToolbarConfigurations();
configurations.toolbarConfigurations ??
const QuillSimpleToolbarConfigurations();
set toolbarConfigurations(QuillSimpleToolbarConfigurations? value) => set toolbarConfigurations(QuillSimpleToolbarConfigurations? value) =>
_toolbarConfigurations = value; _toolbarConfigurations = value;

@ -1,19 +1,17 @@
import '../editor/config/editor_configurations.dart' import '../editor/config/editor_configurations.dart'
show QuillEditorConfigurations; show QuillEditorConfigurations;
import '../toolbar/config/simple_toolbar_configurations.dart';
class QuillControllerConfigurations { class QuillControllerConfigurations {
const QuillControllerConfigurations( const QuillControllerConfigurations(
{this.editorConfigurations, {@Deprecated(
this.toolbarConfigurations, 'This parameter is not used and will be removed in future versions.')
this.editorConfigurations,
this.onClipboardPaste, this.onClipboardPaste,
this.requireScriptFontFeatures = false}); this.requireScriptFontFeatures = false});
/// Provides central access to editor configurations required for controller actions @Deprecated(
/// 'This parameter is not used and will be removed in future versions.')
/// Future: will be changed to 'required final'
final QuillEditorConfigurations? editorConfigurations; final QuillEditorConfigurations? editorConfigurations;
final QuillSimpleToolbarConfigurations? toolbarConfigurations;
/// Callback when the user pastes and data has not already been processed /// Callback when the user pastes and data has not already been processed
/// ///

@ -88,6 +88,7 @@ class QuillEditorConfigurations extends Equatable {
final QuillSharedConfigurations sharedConfigurations; final QuillSharedConfigurations sharedConfigurations;
@Deprecated('controller will be removed in future versions.')
final QuillController? controller; final QuillController? controller;
/// The text placeholder in the quill editor /// The text placeholder in the quill editor
@ -99,6 +100,7 @@ class QuillEditorConfigurations extends Equatable {
/// by any shortcut or keyboard operation. The text is still selectable. /// by any shortcut or keyboard operation. The text is still selectable.
/// ///
/// Defaults to `false`. Must not be `null`. /// Defaults to `false`. Must not be `null`.
// ignore: deprecated_member_use_from_same_package
bool get readOnly => controller?.readOnly != false; bool get readOnly => controller?.readOnly != false;
/// Override [readOnly] for checkbox. /// Override [readOnly] for checkbox.
@ -383,6 +385,7 @@ class QuillEditorConfigurations extends Equatable {
@override @override
List<Object?> get props => [ List<Object?> get props => [
placeholder, placeholder,
// ignore: deprecated_member_use_from_same_package
controller?.readOnly, controller?.readOnly,
]; ];

@ -149,6 +149,7 @@ class QuillEditor extends StatefulWidget {
QuillController? controller, QuillController? controller,
QuillEditorConfigurations? configurations, QuillEditorConfigurations? configurations,
}) { }) {
// ignore: deprecated_member_use_from_same_package
controller ??= configurations?.controller; controller ??= configurations?.controller;
assert(controller != null, assert(controller != null,
'controller required. Provide controller directly (preferred) or indirectly through configurations (not recommended - will be removed in future versions).'); 'controller required. Provide controller directly (preferred) or indirectly through configurations (not recommended - will be removed in future versions).');

@ -23,6 +23,7 @@ class QuillEditorProvider extends InheritedWidget {
controller?.editorConfigurations ?? controller?.editorConfigurations ??
const QuillEditorConfigurations(), const QuillEditorConfigurations(),
controller = controller ?? controller = controller ??
// ignore: deprecated_member_use_from_same_package
editorConfigurations?.controller ?? editorConfigurations?.controller ??
QuillController.basic(); QuillController.basic();

@ -95,6 +95,7 @@ class QuillRawEditorConfigurations extends Equatable {
}); });
/// Controls the document being edited. /// Controls the document being edited.
@Deprecated('controller will be removed in future versions.')
final QuillController? controller; final QuillController? controller;
/// Controls whether this editor has keyboard focus. /// Controls whether this editor has keyboard focus.

@ -23,7 +23,10 @@ class QuillRawEditor extends StatefulWidget {
required this.configurations, required this.configurations,
controller, controller,
super.key, super.key,
}) : assert((controller ?? configurations.controller) != null), }) :
// ignore: deprecated_member_use_from_same_package
assert((controller ?? configurations.controller) != null),
// ignore: deprecated_member_use_from_same_package
controller = controller ?? configurations.controller, controller = controller ?? configurations.controller,
assert( assert(
configurations.maxHeight == null || configurations.maxHeight! > 0, configurations.maxHeight == null || configurations.maxHeight! > 0,

@ -1274,7 +1274,7 @@ class QuillRawEditorState extends EditorState
_cursorCont.show.value = widget.configurations.showCursor; _cursorCont.show.value = widget.configurations.showCursor;
_cursorCont.style = widget.configurations.cursorStyle; _cursorCont.style = widget.configurations.cursorStyle;
if (controller != oldWidget.configurations.controller) { if (controller != oldWidget.controller) {
oldWidget.controller.removeListener(_didChangeTextEditingValue); oldWidget.controller.removeListener(_didChangeTextEditingValue);
controller.addListener(_didChangeTextEditingValue); controller.addListener(_didChangeTextEditingValue);
updateRemoteValueIfNeeded(); updateRemoteValueIfNeeded();

@ -168,6 +168,7 @@ class QuillSimpleToolbarConfigurations extends QuillSharedToolbarProperties {
final Map<String, String>? fontFamilyValues; final Map<String, String>? fontFamilyValues;
@Deprecated('controller will be removed in future versions.')
final QuillController? controller; final QuillController? controller;
/// By default it will be /// By default it will be

@ -12,14 +12,11 @@ import 'simple_toolbar_provider.dart';
class QuillSimpleToolbar extends StatelessWidget class QuillSimpleToolbar extends StatelessWidget
implements PreferredSizeWidget { implements PreferredSizeWidget {
factory QuillSimpleToolbar({ factory QuillSimpleToolbar({
/// Controller and configurations are required required QuillSimpleToolbarConfigurations? configurations,
///
/// Prefer: use controller and pass QuillEditorConfigurations in constructor for controller (using QuillControllerConfigurations).
/// Backward compatibility: use configurations and pass QuillController in constructor for configurations. (Will be removed in future versions.)
QuillSimpleToolbarConfigurations? configurations,
QuillController? controller, QuillController? controller,
Key? key, Key? key,
}) { }) {
// ignore: deprecated_member_use_from_same_package
controller ??= configurations?.controller; controller ??= configurations?.controller;
assert(controller != null, assert(controller != null,
'controller required. Provide controller directly (preferred) or indirectly through configurations (not recommended - will be removed in future versions).'); 'controller required. Provide controller directly (preferred) or indirectly through configurations (not recommended - will be removed in future versions).');

Loading…
Cancel
Save