Codelessly / ResponsiveFramework

Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple. Demo: https://gallery.codelessly.com/flutterwebsites/minimal/
https://codelessly.com
MIT License
1.25k stars 150 forks source link

nonexistent breakpoint on migration from 0.2.0 -> 1.1.1 #156

Closed SirBarksALot closed 11 months ago

SirBarksALot commented 11 months ago

Error:

A conditional value was caught referencing a nonexistent breakpoint.

ResponsiveValue requires a parent ResponsiveBreakpoint to reference breakpoints. Add a ResponsiveBreakpoint or remove breakpoint references.

I'm trying to migrate to 1.1.1, I just want to scale from 0 to 450 and resize when above 450, it worked perfectly on 0.2.0, but I cannot get it to work on 1.1.1 despite following the migration guide.

0.2.0 code:

Widget responsiveness(BuildContext context, Widget child) {
  return ResponsiveWrapper.builder(
    child,
    defaultScale: true,
    minWidth: 450,
    breakpoints: [
      const ResponsiveBreakpoint.resize(450, name: MOBILE),
    ],
  );
}

1.1.1 code:

Widget responsiveness(BuildContext context, Widget child) {
  return ResponsiveBreakpoints.builder(
    useShortestSide: true,
    breakpoints: [
      const Breakpoint(
        start: 0,
        end: 450,
        name: MOBILE,
      ),
      const Breakpoint(
        start: 450.1,
        end: double.infinity,
        name: 'rest',
      ),
    ],
    child: ResponsiveScaledBox(
      width: ResponsiveValue<double>(
        context,
        conditionalValues: [
          Condition.equals(name: MOBILE, value: 450),
        ],
      ).value,
      child: child,
    ),
  );
}
SirBarksALot commented 11 months ago

For anyone with the same issue. ResponsiveBreakpoints.builder and any ResponsiveFramework widget cannot be in the same build method. They have to be separated. The solution was to take

ResponsiveScaledBox(
      width: ResponsiveValue<double>(
        context,
        conditionalValues: [
          Condition.equals(name: MOBILE, value: 450),
        ],
      ).value,
      child: child,
    )

To a separate widget/function.