fleather-editor / fleather

Soft and gentle rich text editing for Flutter applications.
https://fleather-editor.github.io
Other
192 stars 34 forks source link

Editor Freezes and Throws Exceptions After Anchor Point Selection Expansion #406

Closed guoz2013 closed 1 week ago

guoz2013 commented 1 month ago

Steps to Reproduce

After dragging the editor to select the anchor point and expanding the selection, clicking on the selection or on the blank area outside the selection causes the editor to freeze and generates an exception in the console. I need to restart the editor. This issue does not occur every time, but it happens very frequently in my App.

At the end of video, the editor has frozen . Perhaps you need to perform multiple operations to reproduce this issue.

https://github.com/user-attachments/assets/8e4e6a4c-9726-458b-9496-900a70743dc7

Example Code

import 'package:fleather/fleather.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() async {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final controller = FleatherController(document: ParchmentDocument(), );
  void _incrementCounter() {
    showModalBottomSheet(context: context, builder: (context)=>const EditorPage(),  isScrollControlled: true, );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      // body:EditorPage(),
      body:  Column(
        children: [
          FleatherToolbar.basic(controller: controller),
          const SizedBox(height: 36),
          Expanded(child: FleatherEditor(controller: controller,spellCheckConfiguration:null ,
              padding: const EdgeInsets.all(16.0))),
        ],
      ),
    // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Environment

Error Logs


======== Exception caught by gesture library =======================================================
The following assertion was thrown while dispatching a pointer event:
'package:flutter/src/gestures/tap_and_drag.dart': Failed assertion: line 1017 pos 14: '_dragState == _DragState.possible': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack: 
#2      BaseTapAndDragGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap_and_drag.dart:1017:14)
#3      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:169:27)
#4      GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:505:20)
#5      GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:481:22)
#6      RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:450:11)
#7      GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:426:7)
#8      GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:389:5)
#9      GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:336:7)
#10     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:305:9)
#11     _invoke1 (dart:ui/hooks.dart:328:13)
#12     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:442:7)
#13     _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31)
(elided 2 frames from class _AssertionError)
Event: PointerUpEvent#aa5c8(position: Offset(47.3, 277.3))
  position: Offset(47.3, 277.3)
Target: <WidgetsFlutterBinding>
====================================================================================================
amantoux commented 4 weeks ago

@guoz2013 I tried at least 30 times to reproduce this behavior I've tried Fleather 1.17.0 + Flutter 3.24 and Fleather @head + Flutter 3.24 Note that Fleather 1.17.0 has been validated against Flutter 3.22 but It doesn't seem to make any difference.

Could you please provide a reproducible pattern?

amantoux commented 1 week ago

Closing this since stale for 3 weeks now Feel free to re-open @guoz2013 if you have a reproducible test case