Flutter Theme主題系列之ButtonBarTheme

簡介

繼承關(guān)系
Object> DiagnosticableTree> Widget> ProxyWidget> InheritedWidget> ButtonBarTheme
ButtonBarTheme通常用于ButtonBar的主題使用,它有一套默認主題,在你沒有做變更的前提下,作為ThemeData構(gòu)造函數(shù)的參數(shù),你可以輕松做到全局改主題樣式。簡單用法如下:

///全局配置
ThemeData(
        buttonBarTheme: ButtonBarThemeData(
            buttonTextTheme:ButtonTextTheme.normal
        )
)
///全局用法
ButtonBar(
        children: <Widget>[
          RaisedButton(child: Text('老孟'),onPressed: (){

          },),
          FlatButton(child: Text('專注flutter分享'),onPressed: (){

          },)
        ],
      )
///局部用法
ButtonBarTheme(
            data: ButtonBarThemeData(buttonTextTheme: ButtonTextTheme.accent),
            child: ButtonBar(
              children: <Widget>[
                FlatButton(
                  onPressed: () {},
                  child: Text("局部用法測試"),
                )
              ],
            ),
          )

圖示:

構(gòu)造函數(shù)

const ButtonBarTheme({
  Key key,
  @required this.data,
  Widget child,
}) : assert(data != null), super(key: key, child: child);
  • key 組件的唯一標示。
  • data 主題的數(shù)據(jù)來源ButtonBarThemeData,詳細的配置信息。
  • child 通常ButtonBar組件,默認繼承ButtonBarThemeData的配置,設(shè)置局部主題時使用。

總結(jié)

ButtonBarTheme 是一個InheritedWidget組件,它可以高效的將數(shù)據(jù)在Widget樹中向下傳遞、共享,所有才有了全局主題和局部主題的用法。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容