我的屏幕没有按要求跳到下一屏幕

时间:2019-07-12 11:35:37

标签: flutter dart

我正在使用RawMaterialButton,并且在按下按钮时需要切换屏幕,但是没有切换吗?

这是我的代码-第一个屏幕:

Widget _buildListItem(String picture) {
  return Row(
    children: <Widget>[
      Row(
        children: <Widget>[
          Container(
            height: 100.0,
            width: 130.0,
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(picture),
                    fit: BoxFit.cover
                ),
                borderRadius: BorderRadius.only(topRight: Radius.circular(10.0), bottomRight: Radius.circular(10.0))),
          ),
          SizedBox(width: 10.0),
          Container(
            height: 120.0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text('Maple Mustard Tempeh',
                  style: TextStyle(
                      fontSize: 15.0,
                      fontFamily: 'Montserrat',
                      fontWeight: FontWeight.bold
                  ),
                ),
                SizedBox(height: 5.0),
                Text('Marinated kale, onion, tomato and roasted',
                  style: TextStyle(
                      fontSize: 11.0,
                      fontFamily: 'Montserrat',
                       fontWeight: FontWeight.bold,
                      color: Colors.grey
                  ),
                ),
                Text('garlic aioli on grilled spelt bread',
                  style: TextStyle(
                      fontSize: 11.0,
                      fontFamily: 'Montserrat',
                      fontWeight: FontWeight.bold,
                      color: Colors.grey
                    ),
                  ),
                    SizedBox(height: 10.0),

                       Row(
                        children: <Widget>[
                          Text('\u20B9 11.25',
                            style: TextStyle(
                                fontSize: 20.0,
                                fontFamily: 'Montserrat',
                                fontWeight: FontWeight.bold,
                                color: Colors.grey
                            ),
                          ),
                          SizedBox(width: 60.0,),
                          Cbutton(onPressed: ()=> item_details()),

                        ],
                      ),


              ],
            ),
          ),

        ],

      ),
    ],
  );
}

RawMaterialButton

return new RawMaterialButton(
  fillColor: Colors.green,
  splashColor: Colors.greenAccent,
  child: Padding(
    padding: const EdgeInsets.symmetric(
        horizontal: 20.0,
        vertical: 8.0),
    child: Row(
      mainAxisSize: MainAxisSize.min,
      children: const <Widget>[
         Icon(
            Icons.add,
            color: Colors.white,),
         SizedBox(width: 8.0,),
         Text("Add", style: TextStyle(
          color: Colors.white
        ),),
      ],
    ),
  ),
  onPressed: onPressed,
  shape: StadiumBorder(),
);

} }

1 个答案:

答案 0 :(得分:0)

如果要更改屏幕,可以使用Navigator

onPressed: () {  
      Navigator.push( context, MaterialPageRoute(
              builder: (context) => SecondScreen()
        ));
}