How to apply theme on MaterialButton or RaisedButton?

前端 未结 4 1286
广开言路
广开言路 2021-02-19 15:08

Can someone help to point how do we define base theme for button and use it on every button? Everywhere I look only found textTheme but not buttonTheme

4条回答
  •  [愿得一人]
    2021-02-19 15:43

    You can define theme on material widget like

    Inside MaterialApp Widget

        theme: ThemeData(     
          elevatedButtonTheme: ElevatedButtonThemeData(
              style: TextButton.styleFrom(
                  backgroundColor: Colors.black,
                  padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
                  side: BorderSide(color: Colors.red, width: 2),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10)),
                  textStyle: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                      wordSpacing: 2,
                      letterSpacing: 2))),
    

    Use

      ElevatedButton(
              onPressed: () => print('okay'),
              child: Text('Elevated Button'),
            ),
    

提交回复
热议问题