parent
5afa35e02d
commit
25435c9bcc
41 changed files with 339 additions and 375 deletions
@ -0,0 +1,35 @@ |
|||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:flutter_quill/flutter_quill.dart'; |
||||||
|
|
||||||
|
class SimpleScreen extends StatefulWidget { |
||||||
|
const SimpleScreen({super.key}); |
||||||
|
|
||||||
|
@override |
||||||
|
State<SimpleScreen> createState() => _SimpleScreenState(); |
||||||
|
} |
||||||
|
|
||||||
|
class _SimpleScreenState extends State<SimpleScreen> { |
||||||
|
final _controller = QuillController.basic(); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return Scaffold( |
||||||
|
appBar: AppBar(), |
||||||
|
body: Column( |
||||||
|
children: [ |
||||||
|
QuillToolbar.simple( |
||||||
|
QuillSimpleToolbarConfigurations(controller: _controller), |
||||||
|
), |
||||||
|
Expanded( |
||||||
|
child: QuillEditor.basic( |
||||||
|
configurations: QuillEditorConfigurations( |
||||||
|
controller: _controller, |
||||||
|
padding: const EdgeInsets.all(16), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
], |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,93 @@ |
|||||||
|
import 'package:flutter/widgets.dart' show BuildContext; |
||||||
|
|
||||||
|
import '../../flutter_quill.dart'; |
||||||
|
|
||||||
|
extension QuillControllerExt on BuildContext { |
||||||
|
/// return nullable [QuillController] |
||||||
|
QuillController? get quilController { |
||||||
|
return quillSimpleToolbarConfigurations?.controller ?? |
||||||
|
quillEditorConfigurations?.controller; |
||||||
|
} |
||||||
|
|
||||||
|
/// return [QuillController] as not null |
||||||
|
QuillController get requireQuillController { |
||||||
|
return quillSimpleToolbarConfigurations?.controller ?? |
||||||
|
quillEditorConfigurations?.controller ?? |
||||||
|
(throw ArgumentError( |
||||||
|
'The quill provider is required, you must only call requireQuillController inside the QuillToolbar and QuillEditor')); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
extension QuillSharedExt on BuildContext { |
||||||
|
/// return nullable [QuillSharedConfigurations] |
||||||
|
QuillSharedConfigurations? get quillSharedConfigurations { |
||||||
|
return quillSimpleToolbarConfigurations?.sharedConfigurations ?? |
||||||
|
quillEditorConfigurations?.sharedConfigurations; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
extension QuillEditorExt on BuildContext { |
||||||
|
/// return [QuillEditorConfigurations] as not null |
||||||
|
QuillEditorConfigurations get requireQuillEditorConfigurations { |
||||||
|
return QuillEditorProvider.ofNotNull(this).editorConfigurations; |
||||||
|
} |
||||||
|
|
||||||
|
/// return nullable [QuillEditorConfigurations] |
||||||
|
QuillEditorConfigurations? get quillEditorConfigurations { |
||||||
|
return QuillEditorProvider.of(this)?.editorConfigurations; |
||||||
|
} |
||||||
|
|
||||||
|
/// return nullable [QuillToolbarBaseButtonOptions]. Since the quill |
||||||
|
/// quill editor block options is in the [QuillEditorProvider] then we need to |
||||||
|
/// get the provider widget first and then we will return block options |
||||||
|
/// throw exception if [QuillEditorProvider] is not in the widget tree |
||||||
|
QuillEditorElementOptions? get quillEditorElementOptions { |
||||||
|
return quillEditorConfigurations?.elementOptions; |
||||||
|
} |
||||||
|
|
||||||
|
/// return [QuillToolbarBaseButtonOptions] as not null. Since the quill |
||||||
|
/// quill editor block options is in the [QuillEditorProvider] then we need to |
||||||
|
/// get the provider widget first and then we will return block options |
||||||
|
/// don't throw exception if [QuillEditorProvider] is not in the widget tree |
||||||
|
QuillEditorElementOptions get requireQuillEditorElementOptions { |
||||||
|
return requireQuillEditorConfigurations.elementOptions; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
extension QuillSimpleToolbarExt on BuildContext { |
||||||
|
/// return [QuillSimpleToolbarConfigurations] as not null |
||||||
|
QuillSimpleToolbarConfigurations get requireQuillSimpleToolbarConfigurations { |
||||||
|
return QuillToolbarProvider.ofNotNull(this).toolbarConfigurations; |
||||||
|
} |
||||||
|
|
||||||
|
/// return nullable [QuillSimpleToolbarConfigurations] |
||||||
|
QuillSimpleToolbarConfigurations? get quillSimpleToolbarConfigurations { |
||||||
|
return QuillToolbarProvider.of(this)?.toolbarConfigurations; |
||||||
|
} |
||||||
|
|
||||||
|
/// return nullable [QuillToolbarBaseButtonOptions]. |
||||||
|
QuillToolbarBaseButtonOptions? get quillToolbarBaseButtonOptions { |
||||||
|
return quillSimpleToolbarConfigurations?.buttonOptions.base; |
||||||
|
} |
||||||
|
|
||||||
|
/// return [QuillToolbarBaseButtonOptions] as not null. |
||||||
|
QuillToolbarBaseButtonOptions get requireQuillToolbarBaseButtonOptions { |
||||||
|
return quillSimpleToolbarConfigurations?.buttonOptions.base ?? |
||||||
|
quillToolbarConfigurations?.buttonOptions.base ?? |
||||||
|
(throw ArgumentError( |
||||||
|
"The buttonOptions is required and it's null because the toolbar configurations is.", |
||||||
|
)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
extension QuillToolbarExt on BuildContext { |
||||||
|
/// return [QuillToolbarConfigurations] as not null |
||||||
|
QuillToolbarConfigurations get requireQuillToolbarConfigurations { |
||||||
|
return QuillBaseToolbarProvider.ofNotNull(this).toolbarConfigurations; |
||||||
|
} |
||||||
|
|
||||||
|
/// return nullable [QuillToolbarConfigurations]. |
||||||
|
QuillToolbarConfigurations? get quillToolbarConfigurations { |
||||||
|
return QuillBaseToolbarProvider.of(this)?.toolbarConfigurations; |
||||||
|
} |
||||||
|
} |
@ -1,7 +1,7 @@ |
|||||||
import 'package:flutter/widgets.dart' show BuildContext; |
import 'package:flutter/widgets.dart' show BuildContext; |
||||||
|
|
||||||
import '../../flutter_quill.dart' show QuillController, QuillProvider; |
import '../../flutter_quill.dart' show QuillController; |
||||||
import 'quill_provider.dart'; |
import 'quill_configurations_ext.dart'; |
||||||
|
|
||||||
extension QuillControllerNullableExt on QuillController? { |
extension QuillControllerNullableExt on QuillController? { |
||||||
/// Simple logic to use the current passed controller if not null |
/// Simple logic to use the current passed controller if not null |
@ -1,142 +0,0 @@ |
|||||||
import 'package:flutter/widgets.dart' show BuildContext; |
|
||||||
|
|
||||||
import '../../flutter_quill.dart'; |
|
||||||
|
|
||||||
// TODO: The comments of this file is outdated and needs to be updated |
|
||||||
|
|
||||||
/// Public shared extension |
|
||||||
extension QuillProviderExt on BuildContext { |
|
||||||
/// return nullable [QuillProvider] |
|
||||||
/// don't throw exception if it's not in the widget tree |
|
||||||
/// instead it will be null |
|
||||||
QuillProvider? get quillProvider { |
|
||||||
return QuillProvider.of(this); |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillController] |
|
||||||
/// since the quill controller is in the [QuillProvider] then we need to get |
|
||||||
/// the provider widget first and then we will return the controller |
|
||||||
/// don't throw exception if [QuillProvider] is not in the widget tree |
|
||||||
/// instead it will be null |
|
||||||
QuillController? get quilController { |
|
||||||
return quillToolbarConfigurations?.controller ?? |
|
||||||
quillEditorConfigurations?.controller; |
|
||||||
} |
|
||||||
|
|
||||||
/// return [QuillController] as not null |
|
||||||
/// since the quill controller is in the [QuillProvider] then we need to get |
|
||||||
/// the provider widget first and then we will return the controller |
|
||||||
/// throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillController get requireQuillController { |
|
||||||
return quillToolbarConfigurations?.controller ?? |
|
||||||
quillEditorConfigurations?.controller ?? |
|
||||||
(throw ArgumentError( |
|
||||||
'The quill provider is required, you must only call requireQuillController inside the QuillToolbar and QuillEditor')); |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillConfigurations] |
|
||||||
/// since the quill configurations is in the [QuillProvider] then we need to |
|
||||||
/// get the provider widget first and then we will return quill configurations |
|
||||||
/// don't throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillConfigurations? get quillConfigurations { |
|
||||||
return quillProvider?.configurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillSharedConfigurations] . Since the quill |
|
||||||
/// shared configurations is in the [QuillProvider] then we need to get the |
|
||||||
/// provider widget first and then we will return shared configurations |
|
||||||
/// don't throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillSharedConfigurations? get quillSharedConfigurations { |
|
||||||
return quillConfigurations?.sharedConfigurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return [QuillEditorConfigurations] as not null . Since the quill |
|
||||||
/// editor configurations is in the [QuillEditorProvider] |
|
||||||
/// then we need to get the |
|
||||||
/// provider widget first and then we will return editor configurations |
|
||||||
/// throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillEditorConfigurations get requireQuillEditorConfigurations { |
|
||||||
return QuillEditorProvider.ofNotNull(this).editorConfigurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillEditorConfigurations]. Since the quill |
|
||||||
/// editor configurations is in the [QuillEditorProvider] |
|
||||||
/// then we need to get the |
|
||||||
/// provider widget first and then we will return editor configurations |
|
||||||
/// don't throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillEditorConfigurations? get quillEditorConfigurations { |
|
||||||
return QuillEditorProvider.of(this)?.editorConfigurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return [QuillSimpleToolbarConfigurations] as not null . Since the quill |
|
||||||
/// toolbar configurations is in the [QuillToolbarProvider] |
|
||||||
/// then we need to get the |
|
||||||
/// provider widget first and then we will return toolbar configurations |
|
||||||
/// throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillSimpleToolbarConfigurations get requireQuillToolbarConfigurations { |
|
||||||
return QuillToolbarProvider.ofNotNull(this).toolbarConfigurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillSimpleToolbarConfigurations]. Since the quill |
|
||||||
/// toolbar configurations is in the [QuillToolbarProvider] |
|
||||||
/// then we need to get the |
|
||||||
/// provider widget first and then we will return toolbar configurations |
|
||||||
/// don't throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillSimpleToolbarConfigurations? get quillToolbarConfigurations { |
|
||||||
return QuillToolbarProvider.of(this)?.toolbarConfigurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return [QuillToolbarConfigurations] as not null . Since the quill |
|
||||||
/// toolbar configurations is in the [QuillBaseToolbarProvider] |
|
||||||
/// then we need to get the |
|
||||||
/// provider widget first and then we will return toolbar configurations |
|
||||||
/// throw exception if [QuillBaseToolbarProvider] is not in the widget tree |
|
||||||
QuillToolbarConfigurations get requireQuillBaseToolbarConfigurations { |
|
||||||
return QuillBaseToolbarProvider.ofNotNull(this).toolbarConfigurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillToolbarConfigurations]. Since the quill |
|
||||||
/// toolbar configurations is in the [QuillBaseToolbarProvider] |
|
||||||
/// then we need to get the |
|
||||||
/// provider widget first and then we will return toolbar configurations |
|
||||||
/// don't throw exception if [QuillBaseToolbarProvider] is not in the widget tree |
|
||||||
QuillToolbarConfigurations? get quillBaseToolbarConfigurations { |
|
||||||
return QuillBaseToolbarProvider.of(this)?.toolbarConfigurations; |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillToolbarBaseButtonOptions]. Since the quill |
|
||||||
/// toolbar base button options is in the [QuillProvider] then we need to |
|
||||||
/// get the provider widget first and then we will return base button |
|
||||||
/// don't throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillToolbarBaseButtonOptions? get quillToolbarBaseButtonOptions { |
|
||||||
return quillToolbarConfigurations?.buttonOptions.base; |
|
||||||
} |
|
||||||
|
|
||||||
/// return [QuillToolbarBaseButtonOptions] as not null. Since the quill |
|
||||||
/// toolbar base button options is in the [QuillProvider] then we need to |
|
||||||
/// get the provider widget first and then we will return base button |
|
||||||
/// throw exception if [QuillProvider] is not in the widget tree |
|
||||||
QuillToolbarBaseButtonOptions get requireQuillToolbarBaseButtonOptions { |
|
||||||
return quillToolbarConfigurations?.buttonOptions.base ?? |
|
||||||
quillBaseToolbarConfigurations?.buttonOptions.base ?? |
|
||||||
(throw ArgumentError( |
|
||||||
"The buttonOptions is required and it's null because the toolbar configurations is.", |
|
||||||
)); |
|
||||||
} |
|
||||||
|
|
||||||
/// return nullable [QuillToolbarBaseButtonOptions]. Since the quill |
|
||||||
/// quill editor block options is in the [QuillEditorProvider] then we need to |
|
||||||
/// get the provider widget first and then we will return block options |
|
||||||
/// throw exception if [QuillEditorProvider] is not in the widget tree |
|
||||||
QuillEditorElementOptions? get quillEditorElementOptions { |
|
||||||
return quillEditorConfigurations?.elementOptions; |
|
||||||
} |
|
||||||
|
|
||||||
/// return [QuillToolbarBaseButtonOptions] as not null. Since the quill |
|
||||||
/// quill editor block options is in the [QuillEditorProvider] then we need to |
|
||||||
/// get the provider widget first and then we will return block options |
|
||||||
/// don't throw exception if [QuillEditorProvider] is not in the widget tree |
|
||||||
QuillEditorElementOptions get requireQuillEditorElementOptions { |
|
||||||
return requireQuillEditorConfigurations.elementOptions; |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue