diegoveloper / flutter_percent_indicator

Flutter percent indicator library
BSD 2-Clause "Simplified" License
679 stars 206 forks source link

Feature Request: Attach widget to percentage bar #73

Closed Manuito83 closed 3 years ago

Manuito83 commented 4 years ago

Hello. I think this is not yet possible, but it would probably be a nice addition to the package.

I created an example image of what could be the result:

Imgur

It doesn't necessarily have to be an icon, but it's the idea I had in mind. Ideally the widget attached should be able to pass over the bar limits (as shown in the image) to create a better effect.

I'm not sure if this would be possible/trickier for the circular progress indicator, as there might be a need (option?) to rotate the widget as it moves.

br-programmer commented 4 years ago

Sounds good, I could take this issue, I'll let you know when it's ready to test.

br-programmer commented 4 years ago

This is the current progress ezgif-2-1346d463b8cf

diegoveloper commented 4 years ago

It's looking good, thanks for the help on this new feature.

diegoveloper commented 3 years ago

hey @Manuito83 , check the latest version :) percent_indicator 2.1.7+1 , now it includes a new param : indicatorWidget that you can use as an indicator. Let me know if it works for you.

Thanks @br-programmer

br-programmer commented 3 years ago

I hope to know if it works

Manuito83 commented 3 years ago

Hey guys, this is looking very good to me, thanks a lot @br-programmer!

In combination with center for the linear indicator, I think this allows for very nice visual effects. The only improvement I could think of would be to allow the user to decide which widget (center or widgetIndicator) is on top of the other.

But this is already great as it is.

Thanks for the support!

diegoveloper commented 3 years ago

sounds good, could close this issue and open a new one maybe. Thanks

Manuito83 commented 3 years ago

Absolutely, up to you guys. Thanks for the help!

Manuito83 commented 3 years ago

Actually, I think there is an issue if using isRTL: true with the LinearPercentIndicator, as the widgetIndicator continues left-to-right based on the current percent:

Imgur

br-programmer commented 3 years ago

Sorry, if it's a problem. This afternoon I check it

diegoveloper commented 3 years ago

@Manuito83 check the latest version, thanks @br-programmer

br-programmer commented 3 years ago

@Manuito83 I would like to know if this was the expected result!

Manuito83 commented 3 years ago

Hello. Yes, it's working flawlessly now with isRTL: true.

Thanks for the help @br-programmer!

Manuito83 commented 3 years ago

Sorry to bring this back, but I've been getting a lot of errors when updating a LinearPercentIndicator after this update.

The issue seems to occur when reloading a LinearPercentIndicator or a series of them, for example in a ListView, but I've been unable to determine the exact reason. Scrolling the ListView seems to trigger the error more frequently, as The error I'm getting is:

I/flutter (21136): ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (21136): The following assertion was thrown during a scheduler callback:
I/flutter (21136): setState() called after dispose(): _LinearPercentIndicatorState#94082(lifecycle state: defunct, not
I/flutter (21136): mounted)
I/flutter (21136): This error happens if you call setState() on a State object for a widget that no longer appears in
I/flutter (21136): the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error
I/flutter (21136): can occur when code calls setState() from a timer or an animation callback.
I/flutter (21136): The preferred solution is to cancel the timer or stop listening to the animation in the dispose()
I/flutter (21136): callback. Another solution is to check the "mounted" property of this object before calling
I/flutter (21136): setState() to ensure the object is still in the tree.
I/flutter (21136): This error might indicate a memory leak if setState() is being called because another object is
I/flutter (21136): retaining a reference to this State object after it has been removed from the tree. To avoid memory
I/flutter (21136): leaks, consider breaking the reference to this object during dispose().
I/flutter (21136): 
I/flutter (21136): When the exception was thrown, this was the stack:
I/flutter (21136): #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1219:9)
I/flutter (21136): #1      State.setState (package:flutter/src/widgets/framework.dart:1254:6)
I/flutter (21136): #2      _LinearPercentIndicatorState.initState.<anonymous closure> (package:percent_indicator/linear_percent_indicator.dart:146:7)
I/flutter (21136): #3      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
I/flutter (21136): #4      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1063:9)
I/flutter (21136): #5      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5)
I/flutter (21136): #9      _invoke (dart:ui/hooks.dart:251:10)
I/flutter (21136): #10     _drawFrame (dart:ui/hooks.dart:209:3)
I/flutter (21136): (elided 3 frames from dart:async)
I/flutter (21136): ════════════════════════════════════════════════════════════════════════════════════════════════════

I wasn't getting any of this before, and the code hasn't changed for a long time.

However, I've been able to correct it by adding a check for mounted in LinearPercentIndicator:

    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (mounted) {
        setState(() {
          _containerWidth = _containerKey.currentContext.size.width;
          _containerHeight = _containerKey.currentContext.size.height;
          if (_keyIndicator.currentContext != null) {
            _indicatorWidth = _keyIndicator.currentContext.size.width;
            _indicatorHeight = _keyIndicator.currentContext.size.height;
          }
        });
      }
    });

I'm not sure if it makes sense.

diegoveloper commented 3 years ago

hey @Manuito83 I can't find the issue, can you create a simple file to reproduce the issue? I tried with a long list but is not happening, maybe some property you have in LinearPercentIndicator?

diegoveloper commented 3 years ago

I set a new version, can you check?

On Sun, Sep 27, 2020 at 5:58 PM Manuel Ortega notifications@github.com wrote:

Sorry to bring this back, but I've been getting a lot of errors when updating a LinearPercentIndicator after this update.

The issue seems to occur when reloading a LinearPercentIndicator or a series of them, for example in a ListView, but I've been unable to determine the exact reason. Scrolling the ListView seems to trigger the error more frequently, as The error I'm getting is:

I/flutter (21136): ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════

I/flutter (21136): The following assertion was thrown during a scheduler callback:

I/flutter (21136): setState() called after dispose(): _LinearPercentIndicatorState#94082(lifecycle state: defunct, not

I/flutter (21136): mounted)

I/flutter (21136): This error happens if you call setState() on a State object for a widget that no longer appears in

I/flutter (21136): the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error

I/flutter (21136): can occur when code calls setState() from a timer or an animation callback.

I/flutter (21136): The preferred solution is to cancel the timer or stop listening to the animation in the dispose()

I/flutter (21136): callback. Another solution is to check the "mounted" property of this object before calling

I/flutter (21136): setState() to ensure the object is still in the tree.

I/flutter (21136): This error might indicate a memory leak if setState() is being called because another object is

I/flutter (21136): retaining a reference to this State object after it has been removed from the tree. To avoid memory

I/flutter (21136): leaks, consider breaking the reference to this object during dispose().

I/flutter (21136):

I/flutter (21136): When the exception was thrown, this was the stack:

I/flutter (21136): #0 State.setState. (package:flutter/src/widgets/framework.dart:1219:9)

I/flutter (21136): #1 State.setState (package:flutter/src/widgets/framework.dart:1254:6)

I/flutter (21136): #2 _LinearPercentIndicatorState.initState. (package:percent_indicator/linear_percent_indicator.dart:146:7)

I/flutter (21136): #3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)

I/flutter (21136): #4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1063:9)

I/flutter (21136): #5 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5)

I/flutter (21136): #9 _invoke (dart:ui/hooks.dart:251:10)

I/flutter (21136): #10 _drawFrame (dart:ui/hooks.dart:209:3)

I/flutter (21136): (elided 3 frames from dart:async)

I/flutter (21136): ════════════════════════════════════════════════════════════════════════════════════════════════════

I wasn't getting any of this before, and the code hasn't changed for a long time.

However, I've been able to correct it by adding a check for mounted in LinearPercentIndicator:

WidgetsBinding.instance.addPostFrameCallback((_) {

  if (mounted) {

    setState(() {

      _containerWidth = _containerKey.currentContext.size.width;

      _containerHeight = _containerKey.currentContext.size.height;

      if (_keyIndicator.currentContext != null) {

        _indicatorWidth = _keyIndicator.currentContext.size.width;

        _indicatorHeight = _keyIndicator.currentContext.size.height;

      }

    });

  }

});

I'm not sure if it makes sense.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_percent_indicator/issues/73#issuecomment-699699080, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFL3UDQUBYXAVNYFYSZ3MTSH67R5ANCNFSM4RFR3ZFA .

Manuito83 commented 3 years ago

Thanks Diego, this is working now for me. I tried several different scenarios with widgetIndicator implemented and it works as expected.

It occured with a ListView updating values through a Provider, probably because we were trying to get the container size before some of the items in the ListView had been initialized. I'll continue testing and report back if I see any other issues.

PawlikMichal25 commented 3 years ago

I was able to reproduce this bug and created an issue for it here: https://github.com/diegoveloper/flutter_percent_indicator/issues/89

br-programmer commented 3 years ago

@BaranMichal25 Thanks for advising, I will review it as soon as possible