Flutter: Null check operator used on a null value only when running in release mode, not debug

When I run this demo code (TabBarView) in debug mode, everything works fine. But when I run the demo into release mode “Flutter run –release”, i get Null check operator used on a null value. I tried ‘flutter pub cache repair’, but it didnt work. After I tap on the different bars it starts working.

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Tab Bar',
      home: MyTabBar(),
    );
  }
}

class MyTabBar extends StatefulWidget {
  const MyTabBar({Key? key}) : super(key: key);

  @override
  State<MyTabBar> createState() => _MyTabBarState();
}

class _MyTabBarState extends State<MyTabBar> with TickerProviderStateMixin {
  late TabController _controller;

  @override
  void initState() {
    _controller = TabController(length: 3, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Tab Bar'),
        bottom: TabBar(
          controller: _controller,
          tabs: const [
            Tab(text: 'Me', icon: Icon(Icons.menu_book_outlined)),
            Tab(text: 'What', icon: Icon(Icons.hourglass_bottom_rounded)),
            Tab(text: 'To', icon: Icon(Icons.room)),
          ],
        ),
      ),
      body: TabBarView(
        controller: _controller,
        children: const [
          Center(
            child: Text('Hello'),
          ),
          Center(
            child: Text('me'),
          ),
          Center(
            child: Text('again'),
          ),
        ],
      ),
    );
  }
}

Here is what i get on the console. I/flutter ( 7521): Null check operator used on a null value I/flutter ( 7521): #0 _PagePosition.applyViewportDimension (package:flutter/src/widgets/page_view.dart:455) I/flutter (7521): # 1 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1456) I/flutter ( 7521): #2 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #3 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #5 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #6 RenderObject.layout (package:flutter/src/rendering/object. dart:1915) I/flutter ( 7521): #7 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #8 RenderObject.layout (package:flutter/src/ rendering/object.dart:1915) I/flutter ( 7521): #9 RenderProxyBoxMixin.per formLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #11 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #13 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) ) I/flutter ( 7521): #15 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #16 RenderObject.layout (package:flutter/src/rendering/object .dart:1915) I/flutter ( 7521): #17 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #18 RenderCustomPaint.performLayout (package:flutter/src) /rendering/custom_paint.dart:545) I/flutter ( 7521): #19 Render Object.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #20 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521 ): #21 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #22 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171) I /flutter ( 7521): #23 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:1003) I/flutter ( 7521): #24 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart) :240) I/flutter ( 7521): #25 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:403) I/flutter ( 7521): #26 RenderObject.layout (package:flutter/src/rendering /object.dart:1915) I/flutter ( 7521): #27 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #28 RenderObject.layout (package:flutter) /src/rendering /object.dart:1915) I/flutter ( 7521): #29 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #30 _RenderCustomClip.performLayout (package:flutter) /src/rendering/proxy_box.dart:1376) I/flutter ( 7521): #31 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #32 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #33 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): # 34 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #35 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #36 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #37 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #38 RenderProxyBoxMixin.performLayout (package:flutter/ src/rendering/proxy_box.dart:116) I/flutter ( 7521): #39 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #40 RenderProxyBoxMixin.performLayout ( package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #41 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #42 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #43 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521 ): #44 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #45 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I /flutter ( 7521): #46 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #47 RenderObject.layout (package:flutter/src/rendering/object.dart) :1915) I/flutter (7521): #48 RenderProxyBoxMixin.performLayout (package:flutter/): src/rendering/proxy_box.dart:116) I/flutter ( 7521): #49 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #50 RenderProxyBoxMixin.performLayout ( package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #51 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #52 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #53 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521 ): #54 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #55 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I /flutter ( 7521): #56 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #57 RenderObject.layout (package:flutter/src/rendering/object.dart :1915) I/flutter (7521): #58 RenderProxyBoxMixin.performLayout (package:flutter/ src/rendering/proxy_box.dart:116) I/flutter ( 7521): #59 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #60 RenderProxyBoxMixin.performLayout ( package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #61 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #62 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #63 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521 ): #64 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #65 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3462) I /flutter ( 7521): #66 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #67 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart :116) I/flutter (7521): #68 RenderObject.layout (package:flutter/sr) c/rendering/object.dart:1915) I/flutter ( 7521): #69 _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:749) I/flutter ( 7521): #70 RenderObject.layout ( package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #71 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #72 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #73 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521 ): #74 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #75 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I /flutter ( 7521): #76 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #77 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart :116) I/flutter (7521): #78 RenderObject.layout (package:flutter/src/renderi) ng/object.dart:1915) I/flutter ( 7521): #79 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #80 RenderObject.layout (package: flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #81 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #82 RenderObject. layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #83 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116) I/flutter ( 7521): #84 RenderObject.layout (package:flutter/src/rendering/object.dart:1915) I/flutter ( 7521): #85 RenderView.performLayout (package:flutter/src/rendering/view.dart:165) I/flutter ( 7521): #86 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1757) I/flutter ( 7521): #87 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:887) I/flutter ( 7521): #88 RendererBinding.drawFrame (package:flutter/src/rendering/bi nding.dart:504) I/flutter ( 7521): #89 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:892) I/flutter ( 7521): #90 RendererBinding._handlePersistentFrameCallback (package:flutter/ src/rendering/binding.dart:370) I/flutter (7521): #91 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146) I/flutter (7521): #92 SchedulerBinding.handleDrawFrame ( package:flutter/src/scheduler/binding.dart:1083) I/flutter ( 7521): #93 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:997) I/flutter ( 7521): #97 _invoke (dart:ui/hooks.dart:151) I/flutter (7521): #98 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308) I/flutter (7521): #99 _drawFrame (dart:ui/ hooks.dart:115) I/flutter (7521): (elided 3 frames from dart:async)

Leave a Comment