0

这是我的平面按钮。如何使用 textButton 或提升按钮解决它?

Center(
  child: FlatButton(
    onPressed: () {  },
    child: Container(
      margin:EdgeInsets.only(top: 25),
      child: image != null 
        ? Image.file(image,width:140,height:192,fit:BoxFit.fill) 
        : Container(
          width: 240, 
          height: 200, 
          child: Icon(Icons.camera_front, size: 100, color:Colors.grey,)
        ),
      ),
    ),
),
4

3 回答 3

0

将 FlatButton 更改为 TextButton。

Center(
  child: TextButton(
    onPressed: () {  },
    child: Container(
      margin:EdgeInsets.only(top: 25),
      child: image != null 
        ? Image.file(image,width:140,height:192,fit:BoxFit.fill) 
        : Container(
          width: 240, 
          height: 200, 
          child: Icon(Icons.camera_front, size: 100, color:Colors.grey,)
        ),
      ),
    ),
),

对于使用 TextButton 的样式,

            TextButton(
              style: TextButton.styleFrom(
                padding: const EdgeInsets.all(16.0),
                primary: Colors.white,
                textStyle: const TextStyle(fontSize: 20),
              ),
              onPressed: () {},
              child: const Text('Gradient'),
            ),
于 2021-08-22T18:05:19.800 回答
0

只需更改FlatButtonTextButtonElevatedButton

于 2021-08-22T17:55:49.550 回答
0

FlatButton 被 TextButton 取代, RaisedButton 被 ElevatedButton 取代。

这是带有样式的 TextButton 的代码

TextButton(
    onPressed: () {  },
    style: ButtonStyle(
      backgroundColor: MaterialStateProperty.all(Colors.deepPurple)
    ),
    child: Container(
      margin:EdgeInsets.only(top: 25),
      child: image != null
          ? Image.file(image,width:140,height:192,fit:BoxFit.fill)
          : Container(
          width: 240,
          height: 200,
          child: Icon(Icons.camera_front, size: 100, color:Colors.grey,)
      ),
    ),
  ),
于 2021-08-23T03:36:05.330 回答