AOSSIE-Org / Resonate

Clubhouse, but Open Source. A social voice platform.
GNU General Public License v3.0
187 stars 132 forks source link

BUG: _TypeError (Null check operator used on a null value) #288

Closed bhawesh2002 closed 6 months ago

bhawesh2002 commented 7 months ago

πŸ› Describe the bug

The following exception was thrown when launching the app on device using API 34: _TypeError (Null check operator used on a null value)

═══════ Exception caught by widgets library ═══════════════════════════════════
The following _TypeError was thrown building MyApp(dirty):
Null check operator used on a null value

The relevant error-causing widget was:
    MyApp MyApp:file:///E:/FlutterProjects/Resonate/lib/main.dart:33:16

When the exception was thrown, this was the stack:
#0      GetNavigation.window (package:get/get_navigation/src/extension_navigation.dart:1169:44)
extension_navigation.dart:1169
#1      GetNavigation.size (package:get/get_navigation/src/extension_navigation.dart:1176:20)
extension_navigation.dart:1176
#2      GetNavigation.width (package:get/get_navigation/src/extension_navigation.dart:1179:23)
extension_navigation.dart:1179
#3      UiSizes.size_56 (package:resonate/utils/ui_sizes.dart:119:39)
ui_sizes.dart:119
#4      UiSizes.size_56 (package:resonate/utils/ui_sizes.dart)
#5      Themes.lightTheme (package:resonate/themes/themes.dart:25:30)
themes.dart:25
#6      Themes.lightTheme (package:resonate/themes/themes.dart)
#7      MyApp.build (package:resonate/main.dart:51:21)
main.dart:51
#8      StatelessElement.build (package:flutter/src/widgets/framework.dart:5550:49)
framework.dart:5550
#9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5480:15)
framework.dart:5480
#10     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
framework.dart:5196
#11     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5462:5)
framework.dart:5462
#12     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5456:5)
framework.dart:5456
...     Normal element mounting (27 frames)
#39     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16)
framework.dart:4335
#40     Element.updateChild (package:flutter/src/widgets/framework.dart:3846:18)
framework.dart:3846
#41     _RawViewElement._updateChild (package:flutter/src/widgets/view.dart:291:16)
view.dart:291
#42     _RawViewElement.mount (package:flutter/src/widgets/view.dart:314:5)
view.dart:314
...     Normal element mounting (7 frames)
#49     Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16)
framework.dart:4335
#50     Element.updateChild (package:flutter/src/widgets/framework.dart:3846:18)
framework.dart:3846
#51     RootElement._rebuild (package:flutter/src/widgets/binding.dart:1354:16)
binding.dart:1354
#52     RootElement.mount (package:flutter/src/widgets/binding.dart:1323:5)
binding.dart:1323
#53     RootWidget.attach.<anonymous closure> (package:flutter/src/widgets/binding.dart:1276:18)
binding.dart:1276
#54     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2844:19)
framework.dart:2844
#55     RootWidget.attach (package:flutter/src/widgets/binding.dart:1275:13)
binding.dart:1275
#56     WidgetsBinding.attachToBuildOwner (package:flutter/src/widgets/binding.dart:1088:27)
binding.dart:1088
#57     WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:1070:5)
binding.dart:1070
#58     WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:1056:7)
binding.dart:1056
#62     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
(elided 3 frames from class _Timer and dart:async-patch)

Here is the screenshot:

image

AyaNady17 commented 7 months ago

I'm facing the same problem. could you find a solution? @bhawesh2002

bhawesh2002 commented 7 months ago

The exception is throwned becaues context is not available to Get package when Get.width is encountered. Some of my other flutter apps face the same issue when Get is used before the context is completely available. We use Themes.lightTheme as ThemeData for themeproperty of GetMaterialApp. This is when Get is first used. Themes.lightTheme has the toolbarHeightproperty of the appBarTheme which uses UiSizes.size_56. So when static double size_56 = 0.068 * Get.width + 0.034 * Get.height; is encountered the contextis not fully available and _TypeError (Null check operator used on a null value) exception is throwned.

bhawesh2002 commented 7 months ago

Another thing to note here is that if we just comment out the properties of themeand darkThemeof GetMaterialApp which after making changes should look like this:

GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Resonate',
      //theme: Themes.lightTheme,
      //darkTheme: Themes.darkTheme,
      themeMode: themeController.theme,
      initialRoute: AppRoutes.splash,
      getPages: AppPages.pages,
    );

The _TypeError (Null check operator used on a null value) is not throwned and everything works fine.

This implies that there is some issue faced by Getpackage to obtain values of width,height etc. when Themes.lightTheme is used as ThemeData for the property theme as any other codefiles using Getpackage for width,height etc work completely fine.

bhawesh2002 commented 7 months ago

@chandansgowda @Aarush-Acharya Is there any way we could deal with this.

Another thing to note here is that if we just comment out the properties of themeand darkThemeof GetMaterialApp which after making changes should look like this:

GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Resonate',
      //theme: Themes.lightTheme,
      //darkTheme: Themes.darkTheme,
      themeMode: themeController.theme,
      initialRoute: AppRoutes.splash,
      getPages: AppPages.pages,
    );

The _TypeError (Null check operator used on a null value) is not throwned and everything works fine.

This implies that there is some issue faced by Getpackage to obtain values of width,height etc. when Themes.lightTheme is used as ThemeData for the property theme as any other codefiles using Getpackage for width,height etc work completely fine.