TF-2427: Update height of body composer when changing screen size

This commit is contained in:
HuyNguyen
2024-01-26 17:35:25 +07:00
committed by Dat Vu
parent a754741218
commit 5ad800a2b0
@@ -55,17 +55,21 @@ class _WebEditorState extends State<WebEditorWidget> {
static const double _offsetHeight = 50;
static const double _offsetWidth = 90;
static const double _defaultHtmlEditorHeight = 550;
late HtmlEditorController _editorController;
double? dropZoneWidth;
double? dropZoneHeight;
final ValueNotifier<double> _htmlEditorHeight = ValueNotifier(_defaultHtmlEditorHeight);
@override
void initState() {
super.initState();
_editorController = widget.editorController;
log('_WebEditorState::initState:height: ${widget.height} | width: ${widget.width}');
if (widget.height != null) {
dropZoneHeight = widget.height! - _offsetHeight;
_htmlEditorHeight.value = widget.height ?? _defaultHtmlEditorHeight;
}
if (widget.width != null) {
dropZoneWidth = widget.width! - _offsetWidth;
@@ -79,13 +83,28 @@ class _WebEditorState extends State<WebEditorWidget> {
if (oldWidget.direction != widget.direction) {
_editorController.updateBodyDirection(widget.direction.name);
}
log('_EmailEditorState::didUpdateWidget():Old: ${oldWidget.height} | current: ${widget.height}');
if (oldWidget.height != widget.height) {
_htmlEditorHeight.value = widget.height ?? _defaultHtmlEditorHeight;
}
super.didUpdateWidget(oldWidget);
}
@override
void dispose() {
_htmlEditorHeight.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: _htmlEditorHeight,
builder: (context, height, _) {
return HtmlEditor(
key: const Key('web_editor'),
key: Key('web_editor_$height'),
controller: _editorController,
htmlEditorOptions: HtmlEditorOptions(
shouldEnsureVisible: true,
@@ -100,7 +119,7 @@ class _WebEditorState extends State<WebEditorWidget> {
defaultToolbarButtons: [],
),
otherOptions: OtherOptions(
height: 550,
height: height,
dropZoneWidth: dropZoneWidth,
dropZoneHeight: dropZoneHeight,
),
@@ -119,4 +138,6 @@ class _WebEditorState extends State<WebEditorWidget> {
),
);
}
);
}
}