我一直无法通过页面传递数据列表。我有一个由ListViewbuilder显示的数据列表,我需要在下一页中传递列表的数据。但是它显示的错误<String, dynamic> is not a subtype of 'List<dynamic>
我知道是因为第二页需要一个列表或其他东西,但是我正在传递一个列表,所以为什么显示呢?还是我需要地图或其他东西?
我的代码
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class OrderDetails extends StatefulWidget {
final List text;
// receive data from the FirstScreen as a parameter
OrderDetails({Key key, @required this.text}) : super(key: key);
@override
_OrderDetailsState createState() => _OrderDetailsState();
}
class _OrderDetailsState extends State<OrderDetails> {
@override
Widget build(BuildContext context) {
print(widget.text);
double stackWidth = MediaQuery.of(context).size.width;
double stackHeight = MediaQuery.of(context).size.height;
return Scaffold(
appBar: AppBar( centerTitle: true,backgroundColor: Colors.white, leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
), title: Text('Order#314313', style: TextStyle(color: Colors.black),),),
body: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Custom Information', style: TextStyle(fontFamily: 'SFPROBOLD', fontWeight: FontWeight.bold, fontSize: 15),),
Text('Delivery', style: TextStyle(fontFamily: 'SFPROBOLD', fontSize: 14, color: Color(0xffea6c7b), fontWeight: FontWeight.bold),)
],
),
),
Container(
width: double.infinity,
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Mohammad Bilal', style: TextStyle(fontFamily: 'SFPROBOLD', fontWeight: FontWeight.bold, fontSize: 17),),
SizedBox(height: stackHeight * 0.004,),
Text('+966 59 11111', style: TextStyle( fontSize: 14, color: Colors.grey),),
SizedBox(height: stackHeight * 0.01,),
Container(
height: stackHeight * 0.001,
color: Color(0xffeaeaea),
),
SizedBox(height: stackHeight * 0.01,),
Text('Home | Eastern Ring Road', style: TextStyle(fontFamily: 'SFPROBOLD', fontWeight: FontWeight.bold, fontSize: 17),),
SizedBox(height: stackHeight * 0.004,),
Text('6, Building 9, Second floor, Lulu', style: TextStyle( fontSize: 14, color: Colors.grey),),
],
),
),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Items Ordered', style: TextStyle( fontSize: 15),),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: stackWidth * 0.1,
decoration: BoxDecoration(
color: Color(0xff008ac7),
borderRadius: BorderRadius.all(Radius.circular(5))
),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Center(child: Text('PAID', style: TextStyle(color: Colors.white, fontSize: 9),)),
),
),
) ],
),
),
Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Text('2x', style: TextStyle(color: Color(0xff17b39e), fontSize: 15, fontWeight: FontWeight.bold),),
SizedBox(width: stackWidth * 0.04,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Chicken biryani', style: TextStyle(fontFamily: 'SFPROBOLD', fontWeight: FontWeight.bold, fontSize: 17),),
Text('Leg peice', style: TextStyle( fontSize: 14, color: Colors.grey),),
],
),
],
),
Text('450 SAR', style: TextStyle(fontFamily: 'SFPROBOLD', fontWeight: FontWeight.bold, fontSize: 17),),
],
),
),
),
Container(
height: stackHeight * 0.001,
color: Color(0xffeaeaea),
),
Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Text('2x', style: TextStyle(color: Color(0xff17b39e), fontSize: 15, fontWeight: FontWeight.bold),),
SizedBox(width: stackWidth * 0.04,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Chicken karahi', style: TextStyle(fontFamily: 'SFPROBOLD', fontWeight: FontWeight.bold, fontSize: 17),),
Text('Extra spicy', style: TextStyle( fontSize: 14, color: Colors.grey),),
],
),
],
),
Text('450 SAR', style: TextStyle(fontFamily: 'SFPROBOLD', fontWeight: FontWeight.bold, fontSize: 17),),
],
),
),
),
Container(
height: stackHeight * 0.001,
color: Color(0xffeaeaea),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Total (incl, Tax)', style: TextStyle(fontSize: 15,),),
Text('65 SR', style: TextStyle(fontFamily: 'SFPROBOLD', fontSize: 15, fontWeight: FontWeight.bold),)
],
),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly ,
children: <Widget>[
Container(
width: stackWidth * 0.35,
height: stackHeight * 0.07,
decoration: BoxDecoration(
color: Color(0xff17b39e),
borderRadius: BorderRadius.all(Radius.circular(5))
),
child: Center(child: Text('Accept', style: TextStyle(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold),))
),
Container(
width: stackWidth * 0.35,
height: stackHeight * 0.07,
decoration: BoxDecoration(
color: Color(0xfffe6c6c),
borderRadius: BorderRadius.all(Radius.circular(5))
),
child: Center(child: Text('Cancel', style: TextStyle(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold),))
)
],
),
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly ,
children: <Widget>[
Container(
width: stackWidth * 0.35,
height: stackHeight * 0.07,
decoration: BoxDecoration(
color: Color(0xff7d5f93),
borderRadius: BorderRadius.all(Radius.circular(5))
),
child: Center(child: Text('Ready', style: TextStyle(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold),))
),
Container(
width: stackWidth * 0.35,
height: stackHeight * 0.07,
decoration: BoxDecoration(
color: Color(0xfffe6c6c),
borderRadius: BorderRadius.all(Radius.circular(5))
),
child: Center(child: Text('Cancel', style: TextStyle(fontSize: 18, color: Colors.white, fontWeight: FontWeight.bold),))
)
],
),
)
],
),
);
}
}
我试图获取数据的第二页代码
class OrderDetails extends StatefulWidget {
final List text;
// receive data from the FirstScreen as a parameter
OrderDetails({Key key, @required this.text}) : super(key: key);
@override
_OrderDetailsState createState() => _OrderDetailsState();
}
我需要帮助才能在第二页中打印列表。
答案 0 :(得分:0)
您应该在接收小部件中设置列表的通用类型。
class OrderDetails extends StatefulWidget {
final List<String, dynamic> text;
// receive data from the FirstScreen as a parameter
OrderDetails({Key key, @required this.text}) : super(key: key);
@override
_OrderDetailsState createState() => _OrderDetailsState();
}