If you want to override widget style in flutter. You can actually achieve it by extending RaisedButton class and overriding the default properties that you need.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | class Sample extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center( child: MyButton(onClicked: () => null,child: Text('Sample'),), ), ); } } class MyButton extends RaisedButton { const MyButton({@required this.onClicked, this.child}) : super(onPressed: onClicked, elevation: 0.0, child: child); final VoidCallback onClicked; final Widget child; @override Widget build(BuildContext context) { return Theme( data: Theme.of(context).copyWith( buttonColor: Theme.of(context).accentColor, buttonTheme: Theme.of(context).buttonTheme.copyWith( shape: RoundedRectangleBorder( side: const BorderSide( color: Colors.white, width: 1.0, style: BorderStyle.solid, ), borderRadius: BorderRadius.circular(30), ), ), ), child: Builder(builder: super.build), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.