The first steps of the major update (#1444)
parent
7c5a12b140
commit
45214576f5
29 changed files with 1059 additions and 875 deletions
@ -0,0 +1,54 @@ |
|||||||
|
import 'package:flutter/foundation.dart' show immutable; |
||||||
|
import 'package:flutter/material.dart' show Color, Colors; |
||||||
|
|
||||||
|
import '../../flutter_quill.dart'; |
||||||
|
|
||||||
|
// I will start on this in the major-update-2 |
||||||
|
|
||||||
|
@immutable |
||||||
|
class QuillToolbarConfigurations { |
||||||
|
const QuillToolbarConfigurations(); |
||||||
|
} |
||||||
|
|
||||||
|
/// |
||||||
|
@immutable |
||||||
|
class QuillEditorConfigurations { |
||||||
|
const QuillEditorConfigurations(); |
||||||
|
} |
||||||
|
|
||||||
|
/// The shared configurations between [QuillEditorConfigurations] and |
||||||
|
/// [QuillToolbarConfigurations] so we don't duplicate things |
||||||
|
class QuillSharedConfigurations { |
||||||
|
const QuillSharedConfigurations({ |
||||||
|
this.dialogBarrierColor = Colors.black54, |
||||||
|
}); |
||||||
|
|
||||||
|
// This is just example or showcase of this major update to make the library |
||||||
|
// more maintanable, flexible, and customizable |
||||||
|
/// The barrier color of the shown dialogs |
||||||
|
final Color dialogBarrierColor; |
||||||
|
} |
||||||
|
|
||||||
|
@immutable |
||||||
|
class QuillConfigurations { |
||||||
|
const QuillConfigurations({ |
||||||
|
required this.controller, |
||||||
|
this.editorConfigurations = const QuillEditorConfigurations(), |
||||||
|
this.toolbarConfigurations = const QuillToolbarConfigurations(), |
||||||
|
this.sharedConfigurations = const QuillSharedConfigurations(), |
||||||
|
}); |
||||||
|
|
||||||
|
/// Controller object which establishes a link between a rich text document |
||||||
|
/// and this editor. |
||||||
|
/// |
||||||
|
/// The controller is shared between [QuillEditorConfigurations] and |
||||||
|
/// [QuillToolbarConfigurations] but to simplify things we will defined it |
||||||
|
/// here, it should not be null |
||||||
|
final QuillController controller; |
||||||
|
|
||||||
|
final QuillEditorConfigurations editorConfigurations; |
||||||
|
|
||||||
|
final QuillToolbarConfigurations toolbarConfigurations; |
||||||
|
|
||||||
|
final QuillSharedConfigurations sharedConfigurations; |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
import 'package:flutter/widgets.dart' show BuildContext; |
||||||
|
|
||||||
|
import '../../../flutter_quill.dart'; |
||||||
|
|
||||||
|
extension BuildContextExt on BuildContext { |
||||||
|
QuillProvider get requireQuillProvider { |
||||||
|
return QuillProvider.ofNotNull(this); |
||||||
|
} |
||||||
|
|
||||||
|
QuillProvider? get quillProvider { |
||||||
|
return QuillProvider.of(this); |
||||||
|
} |
||||||
|
|
||||||
|
QuillController? get quilController { |
||||||
|
return quillProvider?.configurations.controller; |
||||||
|
} |
||||||
|
|
||||||
|
QuillController get requireQuillController { |
||||||
|
return requireQuillProvider.configurations.controller; |
||||||
|
} |
||||||
|
|
||||||
|
QuillConfigurations get requireQuillConfigurations { |
||||||
|
return requireQuillProvider.configurations; |
||||||
|
} |
||||||
|
|
||||||
|
QuillConfigurations? get quillConfigurations { |
||||||
|
return quillProvider?.configurations; |
||||||
|
} |
||||||
|
|
||||||
|
QuillSharedConfigurations? get sharedQuillConfigurations { |
||||||
|
return quillConfigurations?.sharedConfigurations; |
||||||
|
} |
||||||
|
|
||||||
|
QuillSharedConfigurations get requireSharedQuillConfigurations { |
||||||
|
return requireQuillConfigurations.sharedConfigurations; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
import 'package:flutter/foundation.dart' show debugPrint, kDebugMode; |
||||||
|
import 'package:flutter/widgets.dart' show InheritedWidget, BuildContext; |
||||||
|
|
||||||
|
import '../../core/quill_configurations.dart'; |
||||||
|
|
||||||
|
class QuillProvider extends InheritedWidget { |
||||||
|
const QuillProvider({ |
||||||
|
required this.configurations, |
||||||
|
required super.child, |
||||||
|
}); |
||||||
|
|
||||||
|
/// Controller object which establishes a link between a rich text document |
||||||
|
/// and this editor. |
||||||
|
/// |
||||||
|
/// Must not be null. |
||||||
|
final QuillConfigurations configurations; |
||||||
|
|
||||||
|
@override |
||||||
|
bool updateShouldNotify(covariant InheritedWidget oldWidget) { |
||||||
|
throw false; |
||||||
|
} |
||||||
|
|
||||||
|
static QuillProvider? of(BuildContext context) { |
||||||
|
return context.dependOnInheritedWidgetOfExactType<QuillProvider>(); |
||||||
|
} |
||||||
|
|
||||||
|
static QuillProvider ofNotNull(BuildContext context) { |
||||||
|
final provider = of(context); |
||||||
|
if (provider == null) { |
||||||
|
if (kDebugMode) { |
||||||
|
debugPrint( |
||||||
|
'The quill provider must be provided in the widget tree.', |
||||||
|
); |
||||||
|
} |
||||||
|
throw ArgumentError.checkNotNull( |
||||||
|
'You are using a widget in the Flutter quill library that require ' |
||||||
|
'The Quill provider widget to be in the parent widget tree ' |
||||||
|
'because ' |
||||||
|
'The provider is $provider. Please make sure to wrap this widget' |
||||||
|
' with' |
||||||
|
' QuillProvider widget. ' |
||||||
|
'You might using QuillEditor and QuillToolbar so make sure to' |
||||||
|
' wrap them with the quill provider widget and setup the required ' |
||||||
|
'configurations', |
||||||
|
'QuillProvider', |
||||||
|
); |
||||||
|
} |
||||||
|
return provider; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue