Я пытаюсь передать список конструктору виджета Stateful, но при добавлении виджета внутри main.dart он не требует никаких параметров.
class Appointments extends StatefulWidget {
List clients;
Appointments({Key key, this.clients}): super(key: key);
@override
State<StatefulWidget> createState() {
return AppointmentState();
}
}
class AppointmentState extends State<Appointments> {
@override
Widget build (BuildContext context) {
return Container(
child: Expanded(
child: ListView.builder(
itemCount: widget.clients.length,
itemBuilder: (context, index) {...
Добавление встреч() внутри main.dart
class MyAppState extends State<MyApp> {
List _clients = ["James Doe", "Beth Oliver", "Martha Dixon", "Peter Kay"];
@override
Widget build (BuildContext context) {
return MaterialApp(
title: "MyApp",
home: Scaffold (
appBar: AppBar(
title: Text("Your Appointments")
),
body: Column(
children: [
Align(
alignment: AlignmentDirectional.center,
child: Text("Your Appointments"),
),
Appointments()...





Если вашему виджету Appointments требуется ненулевой список клиентов, сделайте его обязательным параметром в конструкторе:
Appointments({Key key, @required this.clients}): super(key: key);
Затем назовите это так в main.dart:
Appointments(clients: _clients),
Идеально! Спасибо!