Style the Buttons and Slider | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/13739693-your-first-flutter-app/lessons/42

The paint method in sliderthumbimage.dart causes an error :

    lib/sliderthumbimage.dart:15:10: Error: The method 'SliderThumbImage.paint' has fewer named arguments than those of overridden method 'SliderComponentShape.paint'.
    void paint(PaintingContext context, Offset center,                  
         ^                                                              
../../../../development/flutter/packages/flutter/lib/src/material/slider_theme.dart:870:8: Context: This is the overridden method ('paint').
  void paint(                                                           
       ^                                                                
lib/sliderthumbimage.dart:15:10: Error: The method 'SliderThumbImage.paint' doesn't have the named parameter 'sizeWithOverflow' of overridden method 'SliderComponentShape.paint'.
    void paint(PaintingContext context, Offset center,                  
         ^                                                              
../../../../development/flutter/packages/flutter/lib/src/material/slider_theme.dart:870:8: Context: This is the overridden method ('paint').
  void paint(                                                           
       ^                                                                
                                                                        
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* Where:                                                                
Script '/Users/projects/development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 904
                                                                        
* What went wrong:                                                      
Execution failed for task ':app:compileFlutterBuildRelease'.            
> Process 'command '/Users/projects/development/flutter/bin/flutter'' finished with non-zero exit value 1
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 9s     

Not sure how to resolve the issue as it prevents the rest of the course from being error free.

Version of Flutter 1.22.1, VSCode1.49.2

Hi @jamiedaniel thank you for the question! Looks like in Flutter 1.22, the SliderComponentShape class that SliderThumbImage extends has some additional parameters in its paint() method.

If you add the two new parameters to the method signature, I think it will fix the error. So the paint() method should look like this in SliderThumbImage:

    @override
    void paint(PaintingContext context, Offset center,
        {Animation<double> activationAnimation,
        Animation<double> enableAnimation,
        bool isDiscrete,
        TextPainter labelPainter,
        RenderBox parentBox,
        SliderThemeData sliderTheme,
        TextDirection textDirection,
        double value,
        double textScaleFactor,
        Size sizeWithOverflow}) { ...

The last two parameters need to be added.

If that does not work, as a backup you could also just skip styling the slider thumb button, and delete the SliderThumbImage file from the project. That would at least let you finish the course.

Thanks again!

2 Likes

That solves it. Thank you!

How to fix collision ? image