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

Issue with current state and persistence #73

Open
Sesa1988 opened this issue Nov 14, 2024 · 1 comment
Open

Issue with current state and persistence #73

Sesa1988 opened this issue Nov 14, 2024 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Sesa1988
Copy link

Sesa1988 commented Nov 14, 2024

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 Sesa1988 added the bug Something isn't working label Nov 14, 2024
@timcreatedit
Copy link
Owner

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

@timcreatedit timcreatedit added the help wanted Extra attention is needed label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants