Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant scroll when not in focus (keyboard closed) #1841

Open
1 task done
Sesa1988 opened this issue Apr 29, 2024 · 0 comments
Open
1 task done

Cant scroll when not in focus (keyboard closed) #1841

Sesa1988 opened this issue Apr 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Sesa1988
Copy link

Sesa1988 commented Apr 29, 2024

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 Sesa1988 added the bug Something isn't working label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant