0

I' am new to flutter. I am using ListView.builder inside a NestedScrollView to hide my top AppBar and floating action button. AppBar and floating action button hides as required. I want to use InAppWebView to display web content. However, there is a problem with the InAppWebView widget, and I can't seem to get it work. In the following code, when I run my app, I get the error "Null check operator used on a null value".

NestedScrollView(
            floatHeaderSlivers: true,
            controller: _scrollController,
            headerSliverBuilder: (context, innerBoxIsScrolled) {
              return <Widget>[
                SliverOverlapAbsorber(
                  handle:
                      NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                  sliver: SliverSafeArea(
                    sliver: SliverAppBar(
                      title: Text(widget.title),
                      floating: true,
                      snap: false,
                    ),
                  ),
                )
              ];
            },
            body: NotificationListener<UserScrollNotification>(
              onNotification: (notification) {
                final ScrollDirection direction = notification.direction;
                setState(() {
                  if (direction == ScrollDirection.reverse) {
                    _isVisible = false;
                  } else if (direction == ScrollDirection.forward) {
                    _isVisible = true;
                  }
                });
                return true;
              },
              child: ListView.builder(
                itemCount: 1,
                itemBuilder: (context, index) => Column(
                  children: [
                    Expanded(
                      child: InAppWebView(
                        initialUrlRequest: URLRequest(
                          url: Uri.https('google.com', widget.path),
                        ),
                      ),
                    )
                  ],
                ),
              ),
            ),
          ),

When I remove the "Expanded" function that is wrapping my InAppWebView widget, the app just crashes. Can someone please help me be able to display my web content using the InAppWebView? All suggestions are appreciated. Thanks!

Bond007
  • 19
  • 2

1 Answers1

0

There is no issue with the widget.

This error occurs when you add (!) Null check operator on Null value

final String? message;
//nullable
print(message!);
//Error: Null check operator used on a null value 

! it's called can't be null but message null.

solution

if(message != null){
    print(message);
}else{
    //return if message is null
}
LOODAN
  • 7
  • 4
  • Thank you for your response La Pyae and LOODAN, however widget.path is never equal to null. The ListView.builder just seems to have problems with both the Expanded function, and the InAppWebView widget. – Bond007 Mar 23 '23 at 11:10