ResponsiveFramework icon indicating copy to clipboard operation
ResponsiveFramework copied to clipboard

type 'Null' is not a subtype of type 'double' in type cast

Open offical-waqas-khurshid opened this issue 11 months ago • 5 comments

The following _TypeError was thrown building ConditionalRouteWidget(dirty, dependencies: [InheritedResponsiveBreakpoints, _ModalScopeStatus]): type 'Null' is not a subtype of type 'double' in type cast

The relevant error-causing widget was: ConditionalRouteWidget ConditionalRouteWidget:file:///C:/Users/waqas.khursheed/Desktop/FlutterMinimalWebsite/lib/main_advanced.dart:41:18 When the exception was thrown, this was the stack: #0 new ResponsiveValue (package:responsive_framework/src/responsive_value.dart:47:61) #1 MyApp.build... (package:minimal/main_advanced.dart:53:32) #2 ConditionalRouteWidget.build (package:minimal/utils/conditional_route_widget.dart:26:21) #3 StatelessElement.build (package:flutter/src/widgets/framework.dart:5550:49) #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5480:15) #5 Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7) #6 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5462:5) #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5456:5) ... Normal element mounting (182 frames) #189 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16) #190 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6893:36) #191 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6905:32) ... Normal element mounting (492 frames) #683 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16) #684 Element.updateChild (package:flutter/src/widgets/framework.dart:3846:18) #685 _RawViewElement._updateChild (package:flutter/src/widgets/view.dart:291:16) #686 _RawViewElement.mount (package:flutter/src/widgets/view.dart:314:5) ... Normal element mounting (7 frames) #693 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16) #694 Element.updateChild (package:flutter/src/widgets/framework.dart:3846:18) #695 RootElement._rebuild (package:flutter/src/widgets/binding.dart:1354:16) #696 RootElement.mount (package:flutter/src/widgets/binding.dart:1323:5) #697 RootWidget.attach. (package:flutter/src/widgets/binding.dart:1276:18) #698 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2844:19) #699 RootWidget.attach (package:flutter/src/widgets/binding.dart:1275:13) #700 WidgetsBinding.attachToBuildOwner (package:flutter/src/widgets/binding.dart:1088:27) #701 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:1070:5) #702 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:1056:7) #706 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12) (elided 3 frames from class _Timer and dart:async-patch)

offical-waqas-khurshid avatar Mar 11 '24 06:03 offical-waqas-khurshid

Yes facing the same issue Right now i am using 1.1.1. Just to hide the error

EkjyotSandhu12 avatar Mar 20 '24 10:03 EkjyotSandhu12

To ensure all scenarios are accounted for, including the one in the example where 'mobile' is specified along with two values, it would be necessary to set a default value. This adjustment will help cover cases that the current condition in your case misses.

pstemporowski avatar Apr 19 '24 05:04 pstemporowski

    return ResponsiveScaledBox(
      width: ResponsiveValue<double>(
        context,
        conditionalValues: [
          //Scale:- the application will scale and maintain ratio of designScreenWidth pixels in any resolution by scaling.
          Condition.largerThan(
            breakpoint: 0,
            value: ThemeConstants.designScreenWidth,
          ),
        ],
        defaultValue: 0,  // <-- ADD THIS
      ).value,
      child: ClampingScrollWrapper.builder(
        dragWithMouse: true,
        context,
        child,
      ),
    );

EkjyotSandhu12 avatar Jun 03 '24 07:06 EkjyotSandhu12

This was a tough call with a long history and limitations of Dart's type capabilities. Making it non-nullable broke usages that require nullable values.

What's remaining is the confusion between typed null / <double?> non-nullable and the value's nullability. Any suggestions?

rayliverified avatar Aug 31 '24 23:08 rayliverified

This was a tough call with a long history and limitations of Dart's type capabilities.

Making it non-nullable broke usages that require nullable values.

What's remaining is the confusion between typed null / <double?> non-nullable and the value's nullability.

Any suggestions?

Hi, same problem here, any suggestions? Thank you for your great job!

lpdevit avatar Sep 02 '24 15:09 lpdevit