Home > Software design >  Flutter code gives error when using "!" or "?"
Flutter code gives error when using "!" or "?"

Time:09-29

I'm using the following code

import 'package:flutter/material.dart';
import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart';

class MenuWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) => IconButton(
        icon: Icon(Icons.menu),
        onPressed: () => ZoomDrawer.of(context)!.toggle(),
      );
}

However, the editor reports error when I use the "!" symbol. Does anyone have any idea how to resolve this error?

Thanks

CodePudding user response:

Make sure you have this line of code in your pubspec.yaml file:

environment:
  sdk: ">=2.12.0 <3.0.0"

This ensures that you are using the dart SDK with a null safety-enabled version.

CodePudding user response:

Update your Flutter SDK by running 'flutter upgrade' command in terminal.

  • Related