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

A conditional value was caught referencing a nonexistent breakpoint. #138

Closed shafquat1 closed 1 year ago

shafquat1 commented 1 year ago

I don't understand how can we replicate the example app in our own code, I am getting this error when trying to do the same. I was previously using 0.2.0 but when I migrated to 1.0.0 I am having these issues. Can anyone help?

Screenshot from 2023-05-08 14-34-50

This is my debug log: ======== Exception caught by widgets library ======================================================= The following assertion was thrown building Builder(dirty): A conditional value was caught referencing a nonexistent breakpoint. ResponsiveValue requires a parent ResponsiveWrapper to reference breakpoints. Add a ResponsiveWrapper or remove breakpoint references. The relevant error-causing widget was: MaterialApp MaterialApp:file:///home/lenovo/Aeologic/projects/omgiva/lib/main.dart:141:16 When the exception was thrown, this was the stack: dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 266:49 throw packages/responsive_framework/responsive_value.dart 34:9 new packages/omgiva/main.dart 169:26 packages/flutter_easyloading/src/easy_loading.dart 241:23 packages/flutter/src/material/app.dart 957:33 packages/flutter/src/widgets/basic.dart 7448:48 build packages/flutter/src/widgets/framework.dart 5038:22 build packages/flutter/src/widgets/framework.dart 4968:15 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/framework.dart 4950:5 [_firstBuild] packages/flutter/src/widgets/framework.dart 4944:5 mount packages/flutter/src/widgets/framework.dart 3953:15 inflateWidget packages/flutter/src/widgets/framework.dart 3682:18 updateChild packages/flutter/src/widgets/framework.dart 4993:16 performRebuild packages/flutter/src/widgets/framework.dart 4690:5 rebuild packages/flutter/src/widgets/binding.dart 1092:16 packages/flutter/src/widgets/framework.dart 2682:19 buildScope packages/flutter/src/widgets/binding.dart 1091:12 attachToRenderTree packages/flutter/src/widgets/binding.dart 925:24 attachRootWidget packages/flutter/src/widgets/binding.dart 906:7 dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19 internalCallback

This is my main.dart file:

ResponsiveBreakpoints.builder(
                  breakpoints: [
                    Breakpoint(start: 0, end: 480, name: MOBILE),
                    Breakpoint(start: 481, end: 1200, name: TABLET),
                    Breakpoint(start: 1201, end: 1600, name: DESKTOP),
                  ],
                  child: MaxWidthBox(
                    // A widget that limits the maximum width.
                    // This is used to create a gutter area on either side of the content.
                    maxWidth: 922,
                    background: Container(color: ColorConstants.lightGrey),
                    child: ResponsiveScaledBox(
                      width:
                          ResponsiveValue<double>(context, conditionalValues: [
                        Condition.equals(name: MOBILE, value: 480),
                        Condition.between(start: 0, end: 481),
                        Condition.equals(name: TABLET, value: 1200),
                        Condition.between(start: 481, end: 922),
                        // There are no conditions for width over 922
                        // because the `maxWidth` is set to 922 via the MaxWidthBox.
                      ]).value,
                      child: _streamChatWidget(child),
                    ),
                  ),
                );
lpdevit commented 1 year ago

Same issue here, I think 1.0.0 needs some more work

mag1c-dev commented 1 year ago

Hello, this error cause by you are using context do not contain ResponsiveWrapper or ResponsiveBreakpoints. Wrap with Builder will be solve.

ResponsiveBreakpoints.builder(
      breakpoints: [
        Breakpoint(start: 0, end: 480, name: MOBILE),
        Breakpoint(start: 481, end: 1200, name: TABLET),
        Breakpoint(start: 1201, end: 1600, name: DESKTOP),
      ],
      child: MaxWidthBox(
        // A widget that limits the maximum width.
        // This is used to create a gutter area on either side of the content.
        maxWidth: 922,
        background: Container(color: ColorConstants.lightGrey),
        child: Builder(
          builder: (context) {
            return ResponsiveScaledBox(
              width:
              ResponsiveValue<double>(context, conditionalValues: [
                Condition.equals(name: MOBILE, value: 480),
                Condition.between(start: 0, end: 481),
                Condition.equals(name: TABLET, value: 1200),
                Condition.between(start: 481, end: 922),
                // There are no conditions for width over 922
                // because the `maxWidth` is set to 922 via the MaxWidthBox.
              ]).value,
              child: _streamChatWidget(child),
            );
          }
        ),
      ),
    );
shafquat1 commented 1 year ago

Thanks @zhgwu this seems to have solved the error above.