diegoveloper / flutter_percent_indicator

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

Reversing progress start animation from 0.0% #15

Closed joelbrostrom closed 5 years ago

joelbrostrom commented 5 years ago

When you increase the percentage with animateFromLastPercent = true the animation starts from the last value and ends at the new value. However when reducing the value the animation starts from 0 and ends at the new value.

For example: 50% -> 75% animates from 50% to 75% 50% -> 25% animates from 0% to 25%

Is there support for reversing animation if newValue < currentValue?

joelbrostrom commented 5 years ago

Is this plugin no longer supported?

diegoveloper commented 5 years ago

Yes, it's still supported. Could you add a minimum sample code to reproduce the issue please?

joelbrostrom commented 5 years ago

Something like:

class PagerState extends State<MyPager> {
  PageController _pageController = PageController();
  List<PageData> pages;
  double _progress;

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      PageView.builder(
          key: PageStorageKey('Questionnarie'),
          controller: _pageController,
          itemCount: pages.length,
          itemBuilder: (context, index) {
            return SomePage(pages[index]);
          },
          onPageChanged: (index) {
            setState(() {
              _progress = index / pages.length;
            });
          }),
      LinearPercentIndicator(
        alignment: MainAxisAlignment.center,
        width: MediaQuery.of(context).size.width - 50,
        animation: true,
        lineHeight: 15.0,
        animationDuration: 1000,
        percent: _progress,
        animateFromLastPercent: true,
        center: Text("${(100 * _progress).round()}%"),
        linearStrokeCap: LinearStrokeCap.roundAll,
        progressColor: Colors.greenAccent,
      ),
    ]);
  }
}

When scrolling nextPage the animation continues from the previous value, but when scrolling to previous page it starts from 0 and animates to the new value.

joelbrostrom commented 5 years ago

Here, I made a better example app to illustrate the issue. Just copy paste and add percent_indicator: ^1.0.13 to pubspec :)

import 'package:flutter/material.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';

void main() =>  runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(home: MyProgressBar());
}

class MyProgressBar extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyProgressBarState();
}

class MyProgressBarState extends State<MyProgressBar> {
  double _progress;

  @override
  void initState() {
    super.initState();
    _progress = 0.0;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
            child: LinearPercentIndicator(
          width: MediaQuery.of(context).size.width,
          animation: true,
          animateFromLastPercent: true,
          percent: _progress,
        )),
        floatingActionButton: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FloatingActionButton(
                child: Icon(Icons.remove),
                onPressed: () {
                  setState(() {
                    _progress -= 0.1;
                  });
                }),
            FloatingActionButton(
                child: Icon(Icons.add),
                onPressed: () {
                  setState(() {
                    _progress += 0.1;
                  });
                })
          ],
        ));
  }
}
diegoveloper commented 5 years ago

Thanks, I'll check this issue later today

On Fri, Mar 1, 2019 at 10:48 AM joel broström notifications@github.com wrote:

Here, I made a better example app to illustrate the issue. Just copy paste and add percent_indicator: ^1.0.13 to pubspec :)

import 'package:flutter/material.dart'; import 'package:percent_indicator/linear_percent_indicator.dart';

void main() => runApp(App());

class App extends StatelessWidget { @override Widget build(BuildContext context) => MaterialApp(home: MyProgressBar() ); }

class MyProgressBar extends StatefulWidget { @override State createState() => MyProgressBarState(); }

class MyProgressBarState extends State { double _progress;

@override void initState() { super.initState(); _progress = 0.0; }

@override Widget build(BuildContext context) { return Scaffold( body: Center( child: LinearPercentIndicator( width: MediaQuery.of(context).size.width, animation: true, animateFromLastPercent: true, percent: _progress, )), floatingActionButton: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ FloatingActionButton( child: Icon(Icons.remove), onPressed: () { setState(() { _progress -= 0.1; }); }), FloatingActionButton( child: Icon(Icons.add), onPressed: () { setState(() { _progress += 0.1; }); }) ], )); } }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_percent_indicator/issues/15#issuecomment-468710024, or mute the thread https://github.com/notifications/unsubscribe-auth/AEq90L_0o2BoF1L0DprxkyRPpfNot7LNks5vSUvXgaJpZM4a50DQ .

joelbrostrom commented 5 years ago

Sure, If you wan't I can take a look at it and if I figure it out I can send a PR. Do you accept contributions?

diegoveloper commented 5 years ago

Of course, everyone who uses this package would appreciate it. Can you take a look the issue?

On Fri, Mar 1, 2019 at 10:50 AM joel broström notifications@github.com wrote:

Sure, If you wan't I can take a look at it and if I figure it out I can send a PR. Do you accept contributions?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_percent_indicator/issues/15#issuecomment-468710754, or mute the thread https://github.com/notifications/unsubscribe-auth/AEq90MjvteYhC_pos9QzhOm9L42TXhtBks5vSUxfgaJpZM4a50DQ .

joelbrostrom commented 5 years ago

I'm two beers in and the after work party starts in 1h 30m but I'll se what I can do :)

diegoveloper commented 5 years ago

hahaha, have fun bro :)

On Fri, Mar 1, 2019 at 10:56 AM joel broström notifications@github.com wrote:

I'm two beers in and after work party starts in 1h 30m but I'll se what I can do :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_percent_indicator/issues/15#issuecomment-468712707, or mute the thread https://github.com/notifications/unsubscribe-auth/AEq90LTFKu5_QQJnaTAcDF1_hMT8Gc7Hks5vSU2tgaJpZM4a50DQ .

joelbrostrom commented 5 years ago

I opened a PR with the fix for this issue. It was a tiny mistake, so there is not a lot to review. Great lib. Ty for the communication :)

diegoveloper commented 5 years ago

awesome! thanks, it was merged

joelbrostrom commented 5 years ago

Can you push a new release with this fix? I need it in my project :)

diegoveloper commented 5 years ago

Sure, but first, could you check the same issue for circular percent indicator?

On Tue, Mar 5, 2019 at 4:59 AM joel broström notifications@github.com wrote:

Can you push a new version (1.0.14) with this change? I need it in my project :)

— 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/15#issuecomment-469617423, or mute the thread https://github.com/notifications/unsubscribe-auth/AEq90GMSk05rdIrXplLv9NqdrAUrna_4ks5vTkAagaJpZM4a50DQ .

joelbrostrom commented 5 years ago

Done, sorry for the delay.

diegoveloper commented 5 years ago

Thanks bro, it was published : 1.0.14

On Wed, Mar 6, 2019 at 10:59 AM joel broström notifications@github.com wrote:

Done, sorry for the delay.

— 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/15#issuecomment-470163490, or mute the thread https://github.com/notifications/unsubscribe-auth/AEq90Cr6pLjNBf2uGz458dpn6r9Tm1m1ks5vT-XTgaJpZM4a50DQ .