Answers for "color for text button in fluter"

4

textbutton background color flutter

// first way (most upvoted)
TextButton(
    child: Text('test'),
    style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.red)),
    onPressed: () {},
),

// second way 
TextButton(
  child: Text('Example'),
  onPressed: () {},
  style: TextButton.styleFrom(backgroundcolor: Colors.red),
)

// third way
TextButton(
  onPressed: () {},
  child: Container(
    padding: EdgeInsets.fromLTRB(30, 10, 30, 10),
    color: Colors.red,
    child: Text(""),
  ),
)
Posted by: Guest on June-15-2021
4

how to style text button in flutter

TextButton(
                      style: ButtonStyle(
                          elevation: MaterialStateProperty.all(0),
                          backgroundColor: MaterialStateProperty.all(
                              Theme.of(context).accentColor),
                          padding: MaterialStateProperty.all(
                              const EdgeInsets.symmetric(
                                  horizontal: 20, vertical: 20)),
                          textStyle: MaterialStateProperty.all(TextStyle(
                            color: Colors.black,
                          )),
                          shape:
                              MaterialStateProperty.all<RoundedRectangleBorder>(
                                  RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(10.0),
                          ))),
                      onPressed: () {
                  // do logic here
                      },
                      child: Text("My Button",
                          style: Theme.of(context).textTheme.bodyText2.copyWith(
                              color: Colors.white,
                              fontWeight: FontWeight.normal)),
                    ),
Posted by: Guest on June-13-2021

Browse Popular Code Answers by Language