按鈕元件和自定義按鈕
阿新 • • 發佈:2021-08-05
import'package:flutter/material.dart';
classButtonPageextendsStatelessWidget{ constButtonPage({Key?key}):super(key:key);
@override Widgetbuild(BuildContextcontext){ returnScaffold( appBar:AppBar( title:Text("按鈕演示頁面"), ), body:Column( mainAxisAlignment:MainAxisAlignment.center, children:[ Row( mainAxisAlignment:MainAxisAlignment.center, children:[ RaisedButton( child:Text('普通按鈕'), onPressed:(){ print('普通按鈕'); }, ), SizedBox( width:5, ), RaisedButton( child:Text('有顏色的按鈕'), color:Colors.blue, textColor:Colors.white, onPressed:(){ print('有顏色的按鈕'); }, ), SizedBox( width:5, ), RaisedButton( child:Text('有陰影的按鈕'), color:Colors.blue, textColor:Colors.white, elevation:10, onPressed:(){ print('有顏色的按鈕'); }, ), ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ Container( child:RaisedButton.icon( icon:Icon(Icons.search), label:Text('圖示按鈕'), color:Colors.blue, textColor:Colors.white, onPressed:(){ print('圖示按鈕'); }, ), ) ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ RaisedButton.icon( icon:Icon(Icons.search), label:Text('圓角按鈕'), color:Colors.blue, textColor:Colors.white, elevation:20, //圓角 shape:RoundedRectangleBorder( borderRadius:BorderRadius.circular(10), ), onPressed:(){ print('圓角按鈕'); }, ), SizedBox( width:10, ), RaisedButton.icon( icon:Icon(Icons.search), label:Text('圓角按鈕'), color:Colors.blue, textColor:Colors.white, elevation:20, splashColor:Colors.grey,//水波紋 //圓角 shape:CircleBorder( side:BorderSide(color:Colors.white), ), onPressed:(){ print('圓角按鈕'); }, ), FlatButton( child:Text('按鈕'), color:Colors.blue, textColor:Colors.white, splashColor:Colors.grey,//水波紋 //圓角 shape:CircleBorder( side:BorderSide(color:Colors.white), ), onPressed:(){ print('按鈕'); }, ), ], ), SizedBox( height:10, ), Row( children:[ OutlinedButton( child:Text('按鈕'), onPressed:(){ print('按鈕'); }, ), MyButton( text:"自定義按鈕", height:60, width:150, pressed:(){ print('自定義按鈕'); }, ), ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ Container( height:50, width:150, child:RaisedButton( child:Text('寬度和高度'), color:Colors.blue, textColor:Colors.white, elevation:10, onPressed:(){ print('有顏色的按鈕'); }, ), ) ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ Expanded( child:Container( height:60, margin:EdgeInsets.all(10), child:RaisedButton( child:Text('自適應按鈕'), color:Colors.blue, textColor:Colors.white, elevation:10, onPressed:(){ print('有顏色的按鈕'); }, ), )), ], ), ], ), ); } }
//自定義按鈕元件 classMyButtonextendsStatelessWidget{ finaltext; finalpressed; finaldoublewidth; finaldoubleheight; constMyButton( {this.text='',this.pressed,this.width=80.0,this.height=30.0}); @override Widgetbuild(BuildContextcontext){ returnContainer( height:this.height, width:this.width, child:ElevatedButton( child:Text(this.text), onPressed:this.pressed, ), ); } } 我是Eric,手機號是13522679763
classButtonPageextendsStatelessWidget{ constButtonPage({Key?key}):super(key:key);
@override Widgetbuild(BuildContextcontext){ returnScaffold( appBar:AppBar( title:Text("按鈕演示頁面"), ), body:Column( mainAxisAlignment:MainAxisAlignment.center, children:[ Row( mainAxisAlignment:MainAxisAlignment.center, children:[ RaisedButton( child:Text('普通按鈕'), onPressed:(){ print('普通按鈕'); }, ), SizedBox( width:5, ), RaisedButton( child:Text('有顏色的按鈕'), color:Colors.blue, textColor:Colors.white, onPressed:(){ print('有顏色的按鈕'); }, ), SizedBox( width:5, ), RaisedButton( child:Text('有陰影的按鈕'), color:Colors.blue, textColor:Colors.white, elevation:10, onPressed:(){ print('有顏色的按鈕'); }, ), ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ Container( child:RaisedButton.icon( icon:Icon(Icons.search), label:Text('圖示按鈕'), color:Colors.blue, textColor:Colors.white, onPressed:(){ print('圖示按鈕'); }, ), ) ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ RaisedButton.icon( icon:Icon(Icons.search), label:Text('圓角按鈕'), color:Colors.blue, textColor:Colors.white, elevation:20, //圓角 shape:RoundedRectangleBorder( borderRadius:BorderRadius.circular(10), ), onPressed:(){ print('圓角按鈕'); }, ), SizedBox( width:10, ), RaisedButton.icon( icon:Icon(Icons.search), label:Text('圓角按鈕'), color:Colors.blue, textColor:Colors.white, elevation:20, splashColor:Colors.grey,//水波紋 //圓角 shape:CircleBorder( side:BorderSide(color:Colors.white), ), onPressed:(){ print('圓角按鈕'); }, ), FlatButton( child:Text('按鈕'), color:Colors.blue, textColor:Colors.white, splashColor:Colors.grey,//水波紋 //圓角 shape:CircleBorder( side:BorderSide(color:Colors.white), ), onPressed:(){ print('按鈕'); }, ), ], ), SizedBox( height:10, ), Row( children:[ OutlinedButton( child:Text('按鈕'), onPressed:(){ print('按鈕'); }, ), MyButton( text:"自定義按鈕", height:60, width:150, pressed:(){ print('自定義按鈕'); }, ), ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ Container( height:50, width:150, child:RaisedButton( child:Text('寬度和高度'), color:Colors.blue, textColor:Colors.white, elevation:10, onPressed:(){ print('有顏色的按鈕'); }, ), ) ], ), SizedBox( height:10, ), Row( mainAxisAlignment:MainAxisAlignment.center, children:[ Expanded( child:Container( height:60, margin:EdgeInsets.all(10), child:RaisedButton( child:Text('自適應按鈕'), color:Colors.blue, textColor:Colors.white, elevation:10, onPressed:(){ print('有顏色的按鈕'); }, ), )), ], ), ], ), ); } }
//自定義按鈕元件 classMyButtonextendsStatelessWidget{ finaltext; finalpressed; finaldoublewidth; finaldoubleheight; constMyButton( {this.text='',this.pressed,this.width=80.0,this.height=30.0}); @override Widgetbuild(BuildContextcontext){ returnContainer( height:this.height, width:this.width, child:ElevatedButton( child:Text(this.text), onPressed:this.pressed, ), ); } } 我是Eric,手機號是13522679763