Flutter - Change Stepper - Step Color
Asked Answered
F

12

12

Is there a way to change the color of the Steps without creating a custom Stepper? the current step is blue.

https://docs.flutter.io/flutter/material/Stepper-class.html
https://docs.flutter.io/flutter/material/Step-class.html

Forego answered 16/11, 2018 at 11:54 Comment(3)
see github.com/flutter/flutter/blob/master/packages/flutter/lib/src/…Kirstenkirsteni
Thank you , so its using the primaryColor of the material app theme. :)Forego
Submitted a bug here github.com/flutter/flutter/issues/57364 the other buttons are using accentColor as button background...Grettagreuze
L
11

Wrap your stepper in a Theme Widget.

body: Theme(
    data: ThemeData(
                  accentColor: Colors.orange,
                  primarySwatch: Colors.orange,
                  colorScheme: ColorScheme.light(
                    primary: Colors.orange
                  )
                ),
    child: Stepper(
       steps: []
    ))

It will change the index color of the stepper as well as the CONTINUE button color to orange(Set the color as per your own requirement).

Loella answered 23/9, 2020 at 8:36 Comment(0)
U
10

In April 2022 these properties work

  1. Light theme - primary - the active state, primary.withOpacity(0.38) will be used for the disabled state.

  2. Dark theme - secondary - the active state, background - the disabled state.

    body: SafeArea(
      child: Theme(
        data: ThemeData(
          canvasColor: Colors.yellow,
          colorScheme: Theme.of(context).colorScheme.copyWith(
                primary: Colors.green,
                background: Colors.red,
                secondary: Colors.green,
              ),
        ),
        child: Stepper(

The result in the dark mode.

enter image description here

Undertone answered 26/4, 2022 at 7:7 Comment(4)
How to change disabled state color in light theme?Miller
I afraid it is not possible. I've submitted the issue 2 weeks ago, you can vote to speed up the fixes. github.com/flutter/flutter/issues/102558Undertone
@Undertone how would you change the color of the icons and number within the circles, like the black tick mark to white and the 3 from white to blackSthilaire
You can't github.com/flutter/flutter/issues/102558 you can vote for this issue, for speed up the fix.Undertone
H
5

The color of the steps depends on ColorScheme.primary color, to change it you have to wrap Stepper with Theme and in ThemeData add colorScheme property like this:

Theme(
  data: ThemeData(
          colorScheme: Theme.of(context).colorScheme.copyWith(primary: yourColor),
              ),
  child: Stepper(...),
      );
Humiliate answered 14/7, 2021 at 14:3 Comment(0)
M
3

As of flutter version 1.22.0, the stepper button colors are determined by ThemeData.colorScheme instead of ThemeData.primaryColor.

Margarettmargaretta answered 6/10, 2020 at 11:21 Comment(0)
U
2

If you take a look at the Flutter package material stepper code you will see that the step's circular icon/indicator depends on whether it is active or not.

It will use your colorScheme.primary color when active in light mode, or your colorScheme.secondary colour when active in dark mode.

When a step is not the currently active one, it will use either:

Light Mode: Your colorScheme.onSurface value with an opacity of 0.38
Dark Mode: Your colorScheme.background colour

So, you can use a custom theme wrapped around your stepper to override your default theme; or, use the stepper's active state to control the current step's colour as intended by the widget.

Flutter Stepper _circleColor method:

Color _circleColor(int index) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;
    if (!_isDark()) {
      return widget.steps[index].isActive ? colorScheme.primary : colorScheme.onSurface.withOpacity(0.38);
    } else {
      return widget.steps[index].isActive ? colorScheme.secondary : colorScheme.background;
    }
  }

Example implementation in light mode :

 Theme(
         data: Theme.of(context).copyWith(
                    colorScheme: Theme.of(context)
                              .colorScheme
                              .copyWith(onSurface: Colors.red.shade200,
primary: Colors.red)),
                      child: Stepper());
Unrepair answered 11/12, 2021 at 12:18 Comment(0)
D
1

Ctrl + right-click on Step (it takes you to Stepper.dart file) here you can find all the config and colors for the step. for me changed the continueenter image description here flat button by changing this code.

Deedee answered 8/4, 2020 at 16:13 Comment(0)
B
1

Use Your Existing Theme Colors

For some reason, stepper does not inherit your main MaterialApp()'s theme. But you can wrap your Stepper() widget with Theme() and use your primary theme's colors anyways.

Assuming you're using the theme property of your MaterialApp(), and that you've set the colorScheme property with both primary and secondary colors. (as of Flutter 2.5, accentColor is officially deprecated)

A basic colorScheme example for ThemeData():

colorScheme: ColorScheme.fromSwatch().copyWith(primary: Colors.green, secondary: Colors.lightGreen),

To apply this colorScheme to your Stepper() widget, you can copy your primary theme using Theme.of(context).

Container(
  child: Theme(
    data: Theme.of(context),
    child: Stepper(
      ...
    ),
  ),
),

For Different Colors

Just create the new colorscheme here on the data property, the same way you'd apply the ThemeData() to your MaterialApp()'s theme property.

Reference

Brimmer answered 12/9, 2021 at 22:11 Comment(0)
S
0

Here's how I achieved this:

body: Theme(
  data: ThemeData(
    accentColor: Colors.blueAccent
  ),
  child: Stepper(
    steps: []
  ),
)

Basically wrap your stepper in a Theme widget and set the accentColor of ThemeData to your desired color.

Swords answered 18/3, 2019 at 12:50 Comment(3)
Didn't work for me, only the 'Continue' color changed not the indexes of Stepper;Requisite
If you don't want the above code to override all your styles use ThemeData.of(context).copyWith().Potomac
not working!!!!Rika
A
0

Wrap your stepper in a Theme Widget

body: Theme(
  data: ThemeData(
    primaryColor: Colors.blueAccent
  ),
  child: Stepper(
    steps: []
  ),
)
Antistrophe answered 13/11, 2019 at 9:53 Comment(0)
R
0

There is an open issue in flutter where color is hardcoded for stepper icons and numbers as per https://github.com/flutter/flutter/issues/102558.

Raulrausch answered 8/7, 2023 at 8:33 Comment(0)
C
0

You can use connectorColor for Stepper line color

Material(
        color: lightGreen,
        shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(15),
                bottomRight: Radius.circular(15))),
        elevation: 1,
        child: Stepper(
          currentStep: 2,
          connectorThickness: 5,
          controlsBuilder: (context, details) {
            return Container();
          },
          steps: steps,
          connectorColor: MaterialStateProperty.resolveWith<Color>(
              (Set<MaterialState> states) =>  Color.fromRGBO(0, 178, 187, 1)[enter image description here][1]),
        ),
      ),

enter image description here

Couscous answered 18/9, 2023 at 9:7 Comment(0)
K
-1

 In Flutter 2 just follow this :
 
 Theme(
      data: ThemeData(colorScheme:          ColorScheme.fromSwatch().copyWith( primary: Color(0xfffada36),
                                  ),
                                ),

In flutter 2 just follow this: Theme( data: ThemeData( colorScheme: ColorScheme.fromSwatch().copyWith( primary: Color(0xfffada36), ), ),

Karyogamy answered 5/12, 2021 at 19:30 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Citronella

© 2022 - 2024 — McMap. All rights reserved.