scribble icon indicating copy to clipboard operation
scribble copied to clipboard

Issue with current state and persistence

Open Sesa1988 opened this issue 1 year ago • 1 comments

Hi,

I want to build an auto save feature for my app so every change should be saved instantly.

Until now I saved with an user event button click and had a dirty workarond to make it work:

  • I sent an event every x miliseconds to check the notifier state iny my Bloc and update the Bloc state like this.

Is there a way to listen to path updates like notifier.OnDrawingUpdated or something like that? I cannot see a way to handle state properly.

class _ScribbleEditorState extends State<ScribbleEditor> {
  Timer? timer;

  @override
  void initState() {
    super.initState();

// In the auto save mode it would even need to check for dirty state and persist in my bloc.
    timer = Timer.periodic(
      const Duration(milliseconds: 100),
      (Timer t) =>
          context.read<ScribbleDetailsBloc>().add(UpdateState()),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 12),
      child: Scribble(
        notifier: widget._notifier,
        drawPen: true,
        drawEraser: true,
      ),
    );
  }

  @override
  void dispose() {
    timer?.cancel();
    super.dispose();
  }

You can see the hack here.

I need something like:

notifier.onDrawingUpdated(event) {
      canUndo = notifier.canUndo;
      canRedo = notifier.canRedo;
      _persistState();
    });

what should be fired when the user stops drawing the line.

Also its pretty hard to listen to changes in general like canUndo or Redo because of the same reason.

I have to manage all state in my bloc, scribble drawings but also a lot of other things.

Sesa1988 avatar Nov 14 '24 00:11 Sesa1988

Why can't you listen to ScribbleNotifier using addListener? You can always compare whatever comes in there to what you had before

timcreatedit avatar Jan 08 '25 11:01 timcreatedit

Hi @Sesa1988, I'm gonna close this issue for now. Let me know if I'm missing something and I will reopen it :)

timcreatedit avatar Jun 02 '25 14:06 timcreatedit