0

I still new with Dart language.

I want to create a custom Stepper class with extends current Stepper class. The reason why I need to create custom Stepper because I need to override function _buildHorizontal

Current workaround:



import 'package:flutter/material.dart';

class CustomStepper extends Stepper {


  CustomStepper({
    Key key,
    @required Step steps,
    ScrollPhysics physics,
    StepperType type = StepperType.vertical,
    int currentStep = 0,
    ValueChanged<int> onStepTapped,
    VoidCallback onStepContinue,
    VoidCallback onStepCancel,
    ControlsWidgetBuilder controlsBuilder,
  }) : assert(steps != null),
       assert(type != null),
       assert(currentStep != null),
       super(key: key);
}

My question is, how to override _buildHorizontal in a right way?

Zarul Izham
  • 569
  • 5
  • 17

1 Answers1

0

You can see here the colors that are being used by default by the Stepper that are being get from the Theme, such as primary color, accent color and so on.

If you want to change it only for that stepper, a more convenient approach is by wrapping it in a Theme and override those properties only for that widget, such as:

Theme(
        data: ThemeData(
          accentColor: Colors.blueAccent
        ),
        child: Stepper()
)

Otherwise, the best way is to copy the source of the Stepper for your own custom widget and tweak it for your needs.

Miguel Ruivo
  • 16,035
  • 7
  • 57
  • 87
  • By using `ThemeData`, it is still not enough for me. I still can't figure to change black color (the background) to red. See image https://imgur.com/QvWb7fy. Futhermore, I cannot adjust the `padding` in the Stepper due value of the padding is hardcoded in the class. See image https://imgur.com/5MSuIzn – Zarul Izham May 12 '19 at 10:09
  • You can just copy the class and tweak it yourself. For the time being is one of the reliable solutions. – Miguel Ruivo May 12 '19 at 15:48
  • Did you suggest to duplicate `stepper.dart`, give a new name, and modify the code from the duplicated .dart? I am looking forward for a solution like this: https://stackoverflow.com/a/52659964/4358651 – Zarul Izham May 12 '19 at 16:34