美文网首页
flutter 去除RaisedButton、FlatButto

flutter 去除RaisedButton、FlatButto

作者: 壹点微尘 | 来源:发表于2021-02-01 14:50 被阅读0次

    之前一直忙于开发, 也没有去读源码,这些按钮内置padding怎么也去除不掉,今儿读了下源码, so easy


    按钮默认内置padding
                 RaisedButton(
                    child: Text('RaisedButton'),
                    onPressed: () {},
                  ),
                  FlatButton(
                    child: Text('Button', style: TextStyle(color: Colors.white)),
                    color: Colors.pink,
                    onPressed: () {},
                  ),
                  OutlineButton(
                    child: Text('OutlineButton'),
                    onPressed: () {},
                  ),
    

    那么怎么去除这写内置padding呢?只需要在main.dart文件中设置buttonTheme即可:

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Study',
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
            buttonTheme: ButtonThemeData(
              minWidth: 0,
              height: 0,
              padding: EdgeInsets.zero, // 可以设置为zero,
              // padding: EdgeInsets.symmetric(
              //   // 也可以根据自己需要设置padding
              //   horizontal: 15,
              //   vertical: 8,
              // ),
            ),
          ),
          home: CYRoot(),
        );
      }
    }
    
    
    去除了内置padding
    也可在代码中手动设置padding
     RaisedButton(
                    padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
                    child: Text('RaisedButton'),
                    onPressed: () {},
                  ),
    
    手动设置padding

    相关文章

      网友评论

          本文标题:flutter 去除RaisedButton、FlatButto

          本文链接:https://www.haomeiwen.com/subject/vkoyfhtx.html