Reputation: 6181
Lets say I have this TextButton
:
TextButton(
style: TextButton.styleFrom(
minimumSize: const Size(newWidth, newHeight),
),
onPressed: _onTapped,
child: const Text('Button'),
),
The motivation here is to keep the theme's values and overriding only what I need.
I was hoping that TextButton.defaultStyleOf(context)
would be helpful alas it is not a static method.
Some notes:
I am not looking to use the old material buttons like FlatButton
as they are being replaced with the new buttons (TextButton
in this case), which is why I have this question in the first place.
But if there is a way to achieve that with MaterialButton
, that would be good enough.
Upvotes: 7
Views: 5925
Reputation: 127
Use MediaQuery for size in ratio.
TextButton(onPressed:() {
},
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: Colors.teal,
onSurface: Colors.grey,
minimumSize: Size(MediaQuery.of(context).size.width-20,40)
),
child: Text("Button")),
by default it take width according to its text width Or you can try with MediaQuery
Upvotes: 6