Я бы добавил параметр List<Problem>
в наш класс ProblemList
.
Затем мы можем перейти в этот список при переходе на нашу страницу ProblemList и получить к нему следующий доступ:
class ProblemList extends StatefulWidget {
final List<Problem> pList;
const ProblemList({this.pList});
@override
ProblemListState createState() => ProblemListState();
}
class ProblemListState extends State<ProblemList> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("My Problems"),
leading: Icon(Icons.list),
),
body: Text(widget.pList[0].desc), //<-------- This is where you access the list
),
);
}
}
Строка 142 становится:
onPressed: () {
Problem problem = new Problem(problemDescription.text, problemDetails.text);
problems.add(problem);
print(problems[0].desc);
Navigator.push(context,
MaterialPageRoute(builder: (context) =>
ProblemList(pList: problems))); //<----- Passing the list to the class
},