[英]How to navigate page using function in flutter?
How to navigate to different page for each _buildcard function?如何导航到每个 _buildcard function 的不同页面? Below are my code.
下面是我的代码。 I want to navigate to different page using _buildcard function but still get error since it is function and not class.
我想使用 _buildcard function 导航到不同的页面,但仍然出现错误,因为它是 function 而不是 class。 Is there any way to do?
有什么办法吗?
_buildCard(3, "Azzahra\nVilla", 1400),
_buildCard(4, "Afsana\nVilla", 1300)
var rating = 0.0;
_buildCard(img, text, price)
{
return Card(
child: Row(children: <Widget>[
Container(
margin: EdgeInsets.all(8.0),
width: 120.0,
height: 180.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/$img.jpeg"), fit: BoxFit.cover),
borderRadius: BorderRadius.circular(10.0)),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"$text",
maxLines: 2,
textAlign: TextAlign.justify,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 22.0),
),
SizedBox(height: 5.0),
Text(
"Janda Baik",
style:
TextStyle(fontSize: 11.0, color: Colors.grey),
),
SizedBox(height: 5.0),
SmoothStarRating(
rating: rating,
isReadOnly: false,
size: 14,
filledIconData: Icons.star,
halfFilledIconData: Icons.star_half,
defaultIconData: Icons.star_border,
color: Colors.yellow,
starCount: 5,
allowHalfRating: true,
spacing: 2.0,
onRated: (value) {
print("rating value -> $value");
// print("rating value dd -> ${value.truncate()}");
},
),
]),
Column(children: <Widget>[
Text(
"\RM$price",
style: TextStyle(
fontSize: 22.0, fontWeight: FontWeight.bold),
),
Text(
"per night",
style: TextStyle(fontSize: 11.0, color: Colors.grey),
)
Try this code试试这个代码
return InkWell(
onTap: () {
text=='Azzahra\nVilla'?
Navigator.push(context, MaterialPageRoute(builder: (context)=> AzzahraClassName())):
Navigator.push(context, MaterialPageRoute(builder: (context)=> AfsanaClassName()));
},
child: Card(child:....))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.