flutter-quill icon indicating copy to clipboard operation
flutter-quill copied to clipboard

Cant scroll when not in focus (keyboard closed)

Open Sesa1988 opened this issue 9 months ago • 2 comments

Is there an existing issue for this?

Flutter Quill version

9.3.1

Steps to reproduce

  1. Save long note anywhere
  2. Open new child route with editor without focus and long note text

Expected results

Long text is displayed and can be scrolled without clicking into it and have to open the keyboard

Actual results

Long text is displayed but cant be scrolled and somehow lags. When you click in, it scrolls around to the position where you would except you should be.

Code sample

Code sample
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter_quill/quill_delta.dart';
import 'package:foxynotes/app_localizations.dart';
import 'package:foxynotes/blocs/settings/settings_bloc.dart';
import 'package:foxynotes/screens/note_details/bloc/note_details_bloc.dart';

class NoteEditor extends StatefulWidget {
  final String _content;
  final FocusNode _focusNode;
  final bool _shouldFocus;

  const NoteEditor(this._content, this._focusNode, this._shouldFocus,
      {super.key});

  @override
  State<NoteEditor> createState() => _NoteEditor();
}

class _NoteEditor extends State<NoteEditor> {
  final QuillController _controller = QuillController.basic();

  @override
  void initState() {
    var document = _loadDocument(widget._content);
    _controller.document = document;

    _initNotusController();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    var showBigToolbar =
        context.select<SettingsBloc, bool>((x) => x.isBigNotesToolbarEnabled);

    return Column(
      children: [
        Expanded(
          child: QuillEditor.basic(
            configurations: QuillEditorConfigurations(
              controller: _controller,
              placeholder: AppLocalizations.of(context).translate('note'),
              readOnly: false,
              scrollable: true,
              expands: true,
              autoFocus: widget._shouldFocus,
              padding: const EdgeInsets.only(left: 18, right: 18),
              sharedConfigurations: const QuillSharedConfigurations(
                locale: Locale('en'),
              ),
            ),
            focusNode: widget._focusNode,
            scrollController: ScrollController(),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(bottom: 8),
          child: QuillToolbar.simple(
            configurations: QuillSimpleToolbarConfigurations(
              controller: _controller,
              showFontFamily: false,
              showFontSize: false,
              showSubscript: false,
              showSuperscript: false,
              multiRowsDisplay: showBigToolbar,
              showRedo: true,
              showUndo: true,
              buttonOptions: QuillSimpleToolbarButtonOptions(
                base: QuillToolbarBaseButtonOptions(
                  iconSize: showBigToolbar ? 14 : 16,
                ),
              ),
              sectionDividerSpace: showBigToolbar ? 0 : 16,
              toolbarSectionSpacing: showBigToolbar ? 0 : 4,
              headerStyleType: HeaderStyleType.original,
              sharedConfigurations: const QuillSharedConfigurations(
                locale: Locale('en'),
              ),
            ),
          ),
        ),
      ],
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  Document _loadDocument(String jsonString) {
    if (jsonString == '') {
      final Delta delta = Delta()..insert('\n');
      return Document.fromDelta(delta);
    }

    final document = Document.fromJson(jsonDecode(jsonString));
    return document;
  }

  _initNotusController() {
    _controller.addListener(() {
      final previewText = _controller.document.toPlainText().trim();
      context.read<NoteDetailsBloc>().add(
            UpdateNoteContent(
              jsonEncode(_controller.document.toDelta().toJson()),
              previewText,
            ),
          );
    });
  }
}

Sesa1988 avatar Apr 29 '24 20:04 Sesa1988

Hi @Sesa1988 ! I believe I'm running into a similar issue. Have you found any workaround?

putnokiabel avatar Jun 10 '24 10:06 putnokiabel

Hi @Sesa1988 ! I believe I'm running into a similar issue. Have you found any workaround?

No I have not found any workaround.

Sesa1988 avatar Jun 10 '24 11:06 Sesa1988

I am currently working on issue 1907 which referenced your issue.

Can you tell me more about how you are creating your editor instances. For example, are you switching between tabs or creating new editor instances.

Open new child route with editor without focus and long note text

What is 'route'? Issue 1907 selects the editor instance in the second tab. The content cannot be scrolled until something is selected in that window.

Is your issue similar or different???

AtlasAutocode avatar Aug 25 '24 21:08 AtlasAutocode

I am currently working on issue 1907 which referenced your issue.

Can you tell me more about how you are creating your editor instances. For example, are you switching between tabs or creating new editor instances.

Open new child route with editor without focus and long note text

What is 'route'? Issue 1907 selects the editor instance in the second tab. The content cannot be scrolled until something is selected in that window.

Is your issue similar or different???

Yes, it sounds like my issue.

I push a new view via pushNamed and pass the content via initState.

I cannot scroll until I click in the editor. When I try to scroll without click into it and click later it will jump down like I scrolled.

Sesa1988 avatar Aug 25 '24 21:08 Sesa1988

I am currently working on issue 1907 which referenced your issue.

Can you tell me more about how you are creating your editor instances. For example, are you switching between tabs or creating new editor instances.

Open new child route with editor without focus and long note text

What is 'route'? Issue 1907 selects the editor instance in the second tab. The content cannot be scrolled until something is selected in that window.

Is your issue similar or different???

I can confirm that it also fixed my issue.

Sesa1988 avatar Aug 29 '24 11:08 Sesa1988