0
I have a doubt that I believe to be simple but as I have never done so I am struggling. I want to pass the data of a contact to another screen of the app.
Where I call an Actionsheet that appears the option to edit the comment of the contact (which redirects to the other screen). I believe the error is to pass the necessary contact parameters through the button, but as ?
Canvas of the Actionsheet:
CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(
CupertinoIcons.pen,
semanticLabel: 'Editar',
),
onPressed: () {
showCupertinoModalPopup(
context: context,
builder: (context) {
//É necessário retornar aqui o actionsheet para pegar os
//dados do contato
return CupertinoActionSheet(
title: Text(model.contactsList[index]["fullname"]),
message:
Text(model.contactsList[index]["comentario"]),
cancelButton: CupertinoActionSheetAction(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Sair"),
),
//Itens do action sheet
actions: <Widget>[
CupertinoActionSheetAction(
onPressed: () {
},
child: CupertinoButton(
child: Text("Editar comentario"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
UpdateComent()));
},
),
),
],
);
});
},
),
Here is my screen where I intend to update, however, accuses the error of being receiving null
The getter 'contactsList' was called on null.
Receiver: null
Tried calling: contactsList
User-created ancestor of the error-causing widget was:
Container file:///home/marcelo/%C3%81rea%20de%20Trabalho/vp%20App/aplicativo-vpeventos/lib/update.dart:48:19`
And when you click this "link" points to the Container(child: CommentStyle();)
In the second block.
class UpdateComent extends StatefulWidget {
@override
_UpdateComentState createState() => _UpdateComentState();
}
class _UpdateComentState extends State<UpdateComent> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CupertinoNavigationBar(
transitionBetweenRoutes: false,
trailing: ScopedModel<UserModel>(
model: UserModel(),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Padding(padding: EdgeInsets.only(left: 8.0)),
CupertinoButton(
padding: EdgeInsets.zero,
child: const Tooltip(
message: 'Back',
child: Text('Salvar comentario'),
excludeFromSemantics: true,
),
onPressed: () {
}),
],
)),
),
//Corpo da tela
body: ScopedModelDescendant<UserModel>(builder: (context, child, model){
return SingleChildScrollView(
child:
Container(
child: CommentStyle(
),
),
);
}));
}
}
//Aqui monto o corpo da tela
class CommentStyle extends StatelessWidget {
const CommentStyle({this.index, this.model});
final int index;
final UserModel model;
@override
Widget build(BuildContext context) {
//printei o index e ele retorna null
print("print aqui");
print(index);
return SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(15.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
StyleText("Nome:"),
Text(model.contactsList[index]["fullname"]),
],
),
Row(
children: <Widget>[
StyleText("Email:"),
Text(model.contactsList[index]["email"]),
],
),
StyleText("Edite o comentario do usuario no campo abaixo"),
CupertinoTextField(
controller: _controllerComent,
maxLines: 7,
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey
),
borderRadius: BorderRadius.circular(15)
),
placeholder: model.contactsList[index]["comentario"],
),
],
)
),
],
),
);
}
}
What error occurs? At what point does the error appear? Tell us the complete error, say that "is receiving NULL is very generic"
– Matheus Ribeiro
I edited the question, I believe that this way it becomes more clear
– Marcelo L
Yes, it was more detailed, check my reply that I explain to you how to solve.
– Matheus Ribeiro