Reputation: 359
I am stuck at passing my data list through pages. I have a list of data which i am showing by ListViewbuilder and i need to pass the data of a list in next page. But its showing error of <String, dynamic> is not a subtype of 'List<dynamic>
I know error is because the second page expect a list or something but i am passing a list so why its showing ? or i need to map or something ?
My code
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),))
)
],
),
)
],
),
);
}
}
Second page code where i am trying to get data
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();
}
I need help to print the list in second page.
Upvotes: 0
Views: 228
Reputation: 953
You should set the generic type of the List in the receiving widget.
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();
}
Upvotes: 0