0

I know this is how the framework should work but I am looking for a workaround.

class Toy extends StatelessWidget {
  final WidgetBuilder childBuilder;
  final String variation;
  final bool disableAppBar;
  final bool resizable;

  const Toy(
      {@required this.childBuilder,
      @required this.variation,
      this.disableAppBar = false,
      this.resizable = false});

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(variation),
      onTap: () => Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => Scaffold(
                appBar: disableAppBar
                    ? null
                    : AppBar(
                        title: Text(variation),
                      ),
                body: resizable
                    ? ResizableToy(
                        builder: childBuilder,
                      )
                    : childBuilder(context),
              ))),
    );
  }
}

In this code I get hot reload in the childBuilder content. But If I change disableAppBar, this doesn't get rebuilt.

I tried to extract the whole widget, but to no avail

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(variation),
      onTap: () => Navigator.of(context).push(MaterialPageRoute(
          builder: (context) =>
              ToyBuilder(disableAppBar, variation, resizable, childBuilder))),
    );
  }
}

class ToyBuilder extends StatelessWidget {
  final disableAppBar;
  final variation;
  final resizable;
  final childBuilder;

  ToyBuilder(
      this.disableAppBar, this.variation, this.resizable, this.childBuilder);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: disableAppBar
          ? null
          : AppBar(
              title: Text(variation),
            ),
      body: resizable
          ? ResizableToy(
              builder: childBuilder,
            )
          : childBuilder(context),
    );
  }
}

any tips on how to make this work?

Tree
  • 29,135
  • 24
  • 78
  • 98

0 Answers0