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 error I get while saving the information entered in the Dart Flutter text input field

When watching the trainer’s video, she doesn’t get such an error, but while I’m typing.

Instructor:

enter image description here

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


My Code:

enter image description here

What is the problem?

My Related code:

userAdd.dart:

import 'dart:io';


import 'package:denemeleruygulamasi/personel.dart';
import 'package:flutter/material.dart';

class personelEkle extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return personelEkleState();
  }
}

class personelEkleState extends State{
  var personel = personelBilgileri.bilgileri();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Personel Ekle"),
      ),

      body: Container(
        margin: EdgeInsets.all(15),
        child: Form(
          child: Column(
            children: <Widget>[
              TextFormField(
                decoration: InputDecoration(
                  labelText: "Personel adı",
                  hintText: "Ad - soyad",
                ),
                onSaved: (String? value) {
                  personel.ad = value;
                },
              ),

              TextFormField(
                decoration: InputDecoration(
                  labelText: "Personel soyadı",
                  hintText: "Ad - soyad",
                ),
              ),

              TextFormField(
                decoration: InputDecoration(
                  labelText: "Personel kıdem yılı",
                  hintText: "Ad - soyad",
                ),
              ),

            ],
          ),
        ),
      ),
    );

  }
}

personel.dart:

class personelBilgileri{
  late int? id;
  late String ad;
  late String soyad;
  late int kidem;
  late String unvan;

  personelBilgileri.withId(this.id, this.ad, this.soyad, this.kidem, this.unvan);

  personelBilgileri(this.ad, this.soyad, this.kidem, this.unvan);

  personelBilgileri.bilgileri();
  
String get unvanGet{
  String mesaj = "";
  if (this.kidem <= 3){
      mesaj = "Pro";
  }

  else if (this.kidem <= 5) {
    mesaj = "Expert";
  } 

  else {
    mesaj = "Expert Pro";
  }

  return mesaj;
}
}

personel = staff.

Error:

String? value
A value of type 'String?' can't be assigned to a variable of type 'String'.
Try changing the type of the variable, or casting the right-hand type to 'String'.dartinvalid_assignment

I’m trying to make a staff application. I’m currently having a problem with adding staff. I created a separate dart file to add staff.

>Solution :

I guess you are using null safety and the video is old enough that it doesn’t use it, please try the following:

onSaved: (String? value) {
  personel.ad = value;
},
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