你知道吗,Flutter内置了10多种Button控件

移动开发 作者: 2024-08-25 01:35:01
注意:无特殊说明,Flutter版本及Dart版本如下: Flutter版本: 1.12.13+hotfix.5 Dart版本: 2.7.0 Flutter内置了10多种Button(按钮)类控件供我
RaisedButton(
  child: Text('Button'),onPressed: (){
  },)
RaisedButton(
  onHighlightChanged: (high){
  },...
)
属性 说明
textColor 字体颜色
disabledTextColor 禁用状态下字体颜色
color 背景颜色
disabledColor 禁用状态下背景颜色
highlightColor 高亮颜色,按下时的颜色
splashColor 水波纹颜色,按下松开会有水波纹效果
RaisedButton(
  textColor: Colors.red,...
)
RaisedButton(
  textTheme: ButtonTextTheme.primary,...
)
  • normal:黑色或者白色字体,依赖于ThemeData.brightness
  • accent:字体颜色依赖于ThemeData.accentColor
  • primary :字体颜色依赖于ThemeData.primaryColor
MaterialApp(
  title: 'Flutter Demo',theme: ThemeData(
    primaryColor: Color(0xFF42A5F5),accentColor: Colors.yellow,brightness: Brightness.light
  ),...
)
RaisedButton(
  elevation: 5.0,highlightElevation: 5.0,disabledElevation: 5.0,...
)
RaisedButton(
  shape: CircleBorder(),...
)
FlatButton(
  child: Text('Button'),color: Colors.blue,onPressed: () {},)
OutlineButton(
  child: Text('Button'),)
OutlineButton(
  borderSide: BorderSide(color: Colors.blue,width: 2),disabledBorderColor: Colors.black,highlightedBorderColor: Colors.red,child: Text('Button'),)
var _dropValue = '语文';

_buildButton() {
  return DropdownButton(
    value: _dropValue,items: [
      DropdownMenuItem(child: Text('语文'),value: '语文',),DropdownMenuItem(child: Text('数学'),value: '数学'),DropdownMenuItem(child: Text('英语'),value: '英语'),],onChanged: (value){
      setState(() {
        _dropValue = value;
      });
    },);
}
DropdownButton(
  selectedItemBuilder: (context){
    return [
      Text('语文',style: TextStyle(color: Colors.red),Text('数学',Text('英语',)
    ];
  },...
)
DropdownButton(
  hint: Text('请选择'),value: null,...
)
DropdownButton(
  icon: Icon(Icons.add),iconSize: 24,iconDisabledColor: Colors.red,iconEnabledColor: Colors.red,...
)
RawMaterialButton(
  onPressed: (){},fillColor: Colors.blue,)
PopupMenuButton<String>(
  itemBuilder: (context) {
    return <PopupMenuEntry<String>>[
      PopupMenuItem<String>(
        value: '语文',child: Text('语文'),PopupMenuItem<String>(
        value: '数学',child: Text('数学'),PopupMenuItem<String>(
        value: '英语',child: Text('英语'),PopupMenuItem<String>(
        value: '生物',child: Text('生物'),PopupMenuItem<String>(
        value: '化学',child: Text('化学'),];
  },)
PopupMenuButton<String>(
  initialValue: '语文',...
)
PopupMenuButton<String>(
  onSelected: (value){
    print('$value');
  },onCanceled: (){
    print('onCanceled');
  },...
)
PopupMenuButton<String>(
  tooltip: 'PopupMenuButton',...
)
PopupMenuButton<String>(
  elevation: 5,padding: EdgeInsets.all(5),color: Colors.red,...
)
PopupMenuButton<String>(
  child: Text('学科'),...
)
PopupMenuButton<String>(
	icon: Icon(Icons.add),...
)
PopupMenuButton<String>(
  shape: RoundedRectangleBorder(
    side: BorderSide(
      color: Colors.red
    ),borderRadius: BorderRadius.circular(10)
  ),...
)
IconButton(
  icon: Icon(Icons.person),iconSize: 30,)
IconButton(
  tooltip: '这是一个图标按钮',icon: Icon(Icons.person),)
BackButton()
CloseButton()
ButtonBar(
  children: <Widget>[
    RaisedButton(),RaisedButton(),)
ButtonBar(
  alignment: MainAxisAlignment.center,mainAxisSize: MainAxisSize.max,...
)
List<bool> _selecteds = [false,false,true];
ToggleButtons(
      isSelected: _selecteds,children: <Widget>[
        Icon(Icons.local_cafe),Icon(Icons.fastfood),Icon(Icons.cake),onPressed: (index) {
        setState(() {
          _selecteds[index] = !_selecteds[index];
        });
      },);
ToggleButtons(
      color: Colors.green,selectedColor: Colors.orange,fillColor: Colors.red,...
)
ToggleButtons(
	renderBorder: false,)
ToggleButtons(
      borderRadius: BorderRadius.circular(30),borderColor: Colors.orange,borderWidth: 3,selectedBorderColor: Colors.deepOrange,)
ToggleButtons(
      splashColor: Colors.purple,highlightColor: Colors.yellow,)
ToggleButtons(
      onPressed: null,disabledColor: Colors.grey[300],disabledBorderColor: Colors.blueGrey,)
ToggleButtons(
      hoverColor: Colors.cyan,)
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_68131.html