【问题标题】:How to navigate page using function in flutter?如何使用颤振中的功能导航页面?
【发布时间】:2021-05-21 05:16:40
【问题描述】:

如何为每个 _buildcard 函数导航到不同的页面?下面是我的代码。我想使用 _buildcard 函数导航到不同的页面,但仍然会出错,因为它是函数而不是类。有什么办法吗?

        _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),
                      )
                

【问题讨论】:

    标签: flutter navigation flutter-navigation


    【解决方案1】:

    试试这个代码

         return  InkWell(
        onTap: () {
    text=='Azzahra\nVilla'?
        Navigator.push(context, MaterialPageRoute(builder: (context)=> AzzahraClassName())):
    Navigator.push(context, MaterialPageRoute(builder: (context)=> AfsanaClassName())); 
        },
        child: Card(child:....))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 2021-12-27
      相关资源
      最近更新 更多