Search code examples
fluttersdkcameraversionrequired

Is that Flutter need required and late for null safety in sdk version up to 2.7.0?


In the below code, this code occurs error that late and required are not available in the flutter version 2.7.0.

  late CameraController _controller;
  late Future<void> _initializeControllerFuture;  

...

  const DisplayPictureScreen({Key? key, required this.imagePath})
      : super(key: key);

So, I change the flutter version up to 2.1.2 like this, and solved this problem right away.

environment:
  sdk: ">=2.12.0 <3.0.0"

Is that Flutter need other definition instead of required and late for null safety in sdk version up to 2.7.0?

If yes, how I changes definition required and late in sdk version up to 2.7.0?


Solution

  • change your code to:

      final CameraController _controller;
      final Future<void> _initializeControllerFuture;  
    
    ...
    
      const DisplayPictureScreen({Key key, @required this.imagePath})
          : super(key: key);