Skip to content

Hot reload with SignalProvider causes create to rerun again #365

@SPiercer

Description

@SPiercer

to reproduce use any example use of SignalProvider
i.e https://dartsignals.dev/flutter/signal-provider/

as the title says it's so self explainatory

however in this example

class Counter extends FlutterSignal<int> {
  Counter([super.value = 0]);

  void increment() => value++;
}

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

  @override
  Widget build(BuildContext context) {
    return SignalProvider<Counter>(
      create: () => Counter(),
      child: Scaffold(...)
    );
}

the create function always creates a new instance of the Counter object causing a new signal to be created every time !
after long trials the only thing i managed to do is to store it in a variable

class Counter extends FlutterSignal<int> {
  Counter([super.value = 0]);

  void increment() => value++;
}

final counter = Counter();

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

  @override
  Widget build(BuildContext context) {
    return SignalProvider<Counter>(
      create: () => counter, 
      child: Scaffold(...)
    );
}

this prevents the behavior but trials to be done to find other unexpected behaviours for the lifecycle

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions