TF-1033: replace hard code position by scrollController.position.pixels

This commit is contained in:
ManhNTX
2022-10-07 06:47:02 +07:00
committed by Dat H. Pham
parent a7c1d002d3
commit faa22be837
6 changed files with 48 additions and 35 deletions
@@ -66,7 +66,7 @@ class IdentityCreatorController extends BaseController {
String? _contentHtmlEditor;
final ScrollController scrollController = ScrollController();
double currentPositionYHTMLEditor = 250;
final GlobalKey htmlKey = GlobalKey();
void updateNameIdentity(BuildContext context, String? value) {
_nameIdentity = value;
@@ -405,19 +405,24 @@ class IdentityCreatorController extends BaseController {
}
}
void onFocusHTMLEditor() {
scrollController.animateTo(
currentPositionYHTMLEditor,
duration: const Duration(milliseconds: 300),
curve: Curves.linear,
);
void onFocusHTMLEditor() async {
await Scrollable.ensureVisible(htmlKey.currentContext!);
await Future.delayed(const Duration(milliseconds: 500), () {
scrollController.animateTo(
scrollController.position.pixels + defaultKeyboardToolbarHeight,
duration: const Duration(milliseconds: 1),
curve: Curves.linear,
);
});
}
void onEnterKeyDown() {
scrollController.animateTo(
currentPositionYHTMLEditor - keyboardRichTextController.currentLine * 20,
duration: const Duration(milliseconds: 300),
curve: Curves.linear,
);
if(scrollController.position.pixels < scrollController.position.maxScrollExtent) {
scrollController.animateTo(
scrollController.position.pixels + 20,
duration: const Duration(milliseconds: 1),
curve: Curves.linear,
);
}
}
}
@@ -285,7 +285,6 @@ class IdentityCreatorView extends GetWidget<IdentityCreatorController> {
child: SingleChildScrollView(
controller: controller.scrollController,
physics: const ClampingScrollPhysics(),
reverse: true,
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(children: [
@@ -510,7 +509,7 @@ class IdentityCreatorView extends GetWidget<IdentityCreatorController> {
);
} else {
return html_editor_mobile.HtmlEditor(
key:const Key('html_editor_mobile'),
key: controller.htmlKey,
minHeight: 230,
onCreated: (htmlEditorController) {
controller.keyboardRichTextController.onCreateHTMLEditor(