so, i've been working on a CRUD on flutter, and this error got me pretty bad I'm totally new to dart.. The argument type 'String?' can't be assigned to the parameter type 'String'.
class UserForm extends StatelessWidget {
final _form = GlobalKey<FormState>();
final Map<String, String> _formData = {};
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Formulário de Usuário"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.save),
onPressed: () {
final isValid = _form.currentState!.validate();
if(isValid) {
_form.currentState!.save();
Provider.of<Users>(context, listen: false).put(User(
id: _formData['id'],
nome: _formData['nome'],
email: _formData['email'],
avatarUrl: _formData['avatarUrl'],
The error occurs on this last bit of the code. I deleted some parts of the code that I thought It doesn't have nothing to do with it.
CodePudding user response:
Try using this
ex)
_formData['id'] ?? ''
CodePudding user response:
Try using these
a)
_formData['id']!
!
operator forces null value.
b)
_formData['id'] ?? ""
??
is the shortcut for
_formData['id'] != null ? _formData['id'] : ""