Home > Software design >  Flutter The body might complete normally, causing 'null' to be returned, but the return ty
Flutter The body might complete normally, causing 'null' to be returned, but the return ty

Time:10-17

I just put my bottom sheet in Widget function like this

  Widget earnPoints() {
    double width = MediaQuery.of(context).size.width;
    double height = MediaQuery.of(context).size.height;

    showCupertinoModalBottomSheet(
        context: context,
        builder: (context) {
          return StatefulBuilder(
              builder: (BuildContext context, StateSetter setStatee) {
            return Material(
              child: Container(
                  height: height * 0.9,
                  child: SingleChildScrollView(
                    child: Column(children: []),
                  )),
            );
          });
        });
  }

And its showing error that

The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type.

I am using return also

CodePudding user response:

also add return before showCupertinoModalBottomSheet()

CodePudding user response:

I believe it's because you aren't returning showCupertinoModelBottomSheet(),

Future<Widget> earnPoints() async{
  double width = MediaQuery.of(context).size.width;
  double height = MediaQuery.of(context).size.height;
  
  return showCupertinoModalBottomSheet(  /// add return here
    context: context,
    builder: (context) {
      return StatefulBuilder(
        builder: (BuildContext context, StateSetter setStatee) {
          return Material(
            child: Container(
              height: height * 0.9,
              child: SingleChildScrollView(
                child: Column(children: []),
              ),
            ),
          );
        }
      );
    }
  );
}
  • Related