Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The argument type String? can't be assigned to the parameter type String

The argument type ‘String?’ can’t be assigned to the parameter type ‘String

code is here.kindly please solve my problem sir

 class IconContent extends StatelessWidget {
      IconContent({this.icon,this.label});
      final IconData? icon;
       final String? label;
      @override
      Widget build(BuildContext context) {
        return Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(
              icon,
              size: 80.0,
            ),
            SizedBox(
             height: 15.0,
            ),
            Text(
              label,
              style: TextStyle(
                fontSize: 18.0,
                color: Color(0xFFB2B58E),
              ),
            )
          ],
        );
      }
    }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

String? is a nullable String which is not equal to String

More about null-safety: https://dart.dev/null-safety

Change,

IconContent({this.icon,this.label});
      final IconData? icon;
       final String? label;

To,

IconContent({this.icon, required this.label});
      final IconData? icon;
       final String label;

Or,

Change,

Text(
              label,
              style: TextStyle(
                fontSize: 18.0,
                color: Color(0xFFB2B58E),
              ),
            )

To,

if(label != null)
    Text(
        label!,
        style: TextStyle(
            fontSize: 18.0,
            color: Color(0xFFB2B58E),
        ),
    )

! indicates the label is not null. Make sure the label is never null if you use !

Or,

Text(
              label ?? 'default label incase label is null',
              style: TextStyle(
                fontSize: 18.0,
                color: Color(0xFFB2B58E),
              ),
            )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading