Ahmed AlNeaimy
Ahmed AlNeaimy

Reputation: 614

I can't change ElevatedButton color, Flutter

I'm trying to change the button color, but i don't know what is happening, just can't change it at all, what should i add to my code please?

    enter code hereclass NotLoggedInUnregisteredView extends StatelessWidget {
  const NotLoggedInUnregisteredView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        const SizedBox(height: 25),
        Text(
          "Text",
          style: Theme.of(context).textTheme.headlineLarge,
        ),
        const SizedBox(height: 25),
        SizedBox(
          width: 300,
          child: ElevatedButton(
              onPressed: () {
                Navigator.pushNamed(context, 'register');
              },
              child: const Text("Button")),
        )
      ],
    );
  }
}

Upvotes: -1

Views: 108

Answers (2)

Tomislav Juroš
Tomislav Juroš

Reputation: 380

You can style ElevatedButton by using the styleFrom static method or the ButtonStyle class. The first one is more convenience than the second one.

Using styleFrom to style an ElevatedButton:

 child: ElevatedButton(
              onPressed: () {
                Navigator.pushNamed(context, 'register');
              },
              style: ElevatedButton.styleFrom(primary: Colors.green),
              child: const Text("Button")),

Upvotes: 1

FLjubic
FLjubic

Reputation: 191

style: ElevatedButton.styleFrom(primary: Colors.red)

Upvotes: 0

Related Questions