Home > Software design >  I can't change ElevatedButton color, Flutter
I can't change ElevatedButton color, Flutter

Time:09-04

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")),
        )
      ],
    );
  }
}

CodePudding user response:

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")),

CodePudding user response:

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