matthewfx / sleek_circular_slider

Sleek circular slider for Flutter
MIT License
524 stars 102 forks source link

Progress Bar Colour doesn't change on state Change #27

Open gmccormack95 opened 4 years ago

gmccormack95 commented 4 years ago

SleekCircularSlider seems to be a StatefulWidget so when changing the state of the progress bar colour it just keeps it's initial colour. What would be the best way to update the progress bar colour without rebuilding the page?

nero-angela commented 4 years ago

I solved this problem like this. https://github.com/nero-angela/sleek_circular_slider/commit/3343b5e3ecb35a454cc1c69b59e977e78d140ddd

mvarendorff commented 4 years ago

Might be worth to open a PR for this, there are likely to be more people with the same or similar requirements

matthewfx commented 4 years ago

Hi, I'm on a short holiday. Will check the PR when back (after the 14th of Oct)

matthewfx commented 4 years ago

Could you please provide some code with an example of what you want to achieve? I've been playing with the slider and whenever I change an appearance it updates for me.

nero-angela commented 4 years ago

Could you please provide some code with an example of what you want to achieve? I've been playing with the slider and whenever I change an appearance it updates for me.

I tried to change the color of SleekCircularSlider in StatefullWidget using setState method, but it didn't work. I've attached the code for reproduction below.

import 'package:flutter/material.dart';
import 'package:sleek_circular_slider/sleek_circular_slider.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Color _pointColor = Colors.pinkAccent;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(width: double.infinity),
            SleekCircularSlider(
              min: 0,
              max: 1000,
              initialValue: 426,
              appearance: CircularSliderAppearance(
                customColors: CustomSliderColors(
                  progressBarColor: _pointColor,
                  trackColor: _pointColor.withOpacity(0.2),
                  dotColor: _pointColor,
                ),
                customWidths: CustomSliderWidths(
                  progressBarWidth: 4,
                  trackWidth: 4,
                ),
              ),
            ),
            RaisedButton(
              child: Text('change color'),
              onPressed: () {
                setState(() {
                  _pointColor = Colors.blueAccent;
                });
              },
            )
          ],
        ),
      ),
    );
  }
}
cihadturhan commented 3 years ago

@nero-angela I confirm your fix works. +1 for your PR. I'll use your repo until #32 is merged.