Animating a Loop in FlutterHow can I create a “Please Wait, Loading…” animation using jQuery?Android: Expand/collapse animationHow do I animate constraint changes?Flutter Animation Not WorkingScale Transition in Flutter -Loader AnimationHow to define discrete animation in Flutter?What would be the proper way to update animation values in a Flutter animation?Animation Of Container using Offset - FlutterFlutter conditional animationFlutter animation interpolation

High voltage LED indicator 40-1000 VDC without additional power supply

meaning of に in 本当に?

What are these boxed doors outside store fronts in New York?

How do I deal with an unproductive colleague in a small company?

Fully-Firstable Anagram Sets

Today is the Center

Alternative to sending password over mail?

Which country benefited the most from UN Security Council vetoes?

Perform and show arithmetic with LuaLaTeX

Paid for article while in US on F-1 visa?

What's that red-plus icon near a text?

Is it unprofessional to ask if a job posting on GlassDoor is real?

Malcev's paper "On a class of homogeneous spaces" in English

Why do I get two different answers for this counting problem?

Can you really stack all of this on an Opportunity Attack?

Do I have a twin with permutated remainders?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Intersection point of 2 lines defined by 2 points each

How to format long polynomial?

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

Languages that we cannot (dis)prove to be Context-Free

Can a Cauchy sequence converge for one metric while not converging for another?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Was any UN Security Council vote triple-vetoed?



Animating a Loop in Flutter


How can I create a “Please Wait, Loading…” animation using jQuery?Android: Expand/collapse animationHow do I animate constraint changes?Flutter Animation Not WorkingScale Transition in Flutter -Loader AnimationHow to define discrete animation in Flutter?What would be the proper way to update animation values in a Flutter animation?Animation Of Container using Offset - FlutterFlutter conditional animationFlutter animation interpolation






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to make an animation of sorting algorithms in flutter. So far I've coded the algorithm and managed to get some sort of animation by iterating once at a time instead of the whole sorting process but you have to keep tapping the button to sort, one item at a time. I've been trying to look for a way to animate this process. Here's my code:



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

List<double> rectHeights = new List<double>();
int n = 2;

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

class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Sorting',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);



class MyHomePage extends StatefulWidget
MyHomePage(Key key) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();


class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin
int _selectedIndex = 0;
final _widgetOptions = [
Text('Index 0: Sort'),
Text('Index 1: Shuffle'),
];

@override
void initState()
super.initState();
Random random = new Random();
for (int i = 0; i < 35; i++)
double ranNum = random.nextDouble() * 600;
rectHeights.add(ranNum);



@override
Widget build(BuildContext context)
return Scaffold(
body: Padding(
padding: EdgeInsets.all(8.0),
child: Center(
child: Row(
children: rectangles(),
),
),
),
bottomNavigationBar: BottomNavigationBar(
iconSize: 50.0,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.sort), title: Text('Sort', style: TextStyle(fontSize: 20.0),)),
BottomNavigationBarItem(icon: Icon(Icons.shuffle), title: Text('Shuffle', style: TextStyle(fontSize: 20.0),)),
],
currentIndex: _selectedIndex,
fixedColor: Colors.blue,
onTap: _onItemTapped,
),
);


void _onItemTapped(int index)
setState(()
_selectedIndex = index;
);
switch(_selectedIndex)
case 0:
setState(()
insertSortOnce(rectHeights, 1);
);
break;
case 1:
setState(()
shuffle(rectHeights);
n = 2;
);






List<Widget> rectangles()
List<Widget> rects = new List<Widget>();
for (double height in rectHeights)
var rect = Padding(
padding: EdgeInsets.symmetric(horizontal: 1.0),
child: Container(
width: 8.0,
height: height,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Colors.blue
),
),
);
rects.add(rect);

return rects;


void insertSort(values, choice)
int i, j;
double key, temp;
for (i = 1; i < values.length; i++)
key = values[i];
j = i - 1;
switch (choice)
case 1:
while (j >= 0 && key < values[j])
temp = values[j];
values[j] = values[j + 1];
values[j + 1] = temp;
j--;

break;
case 2:
while (j >= 0 && key > values[j])
temp = values[j];
values[j] = values[j + 1];
values[j + 1] = temp;
j--;

break;




void insertSortOnce(values, choice)
int i, j;
double key, temp;
for (i = 1; i < n; i++)
key = values[i];
j = i - 1;
switch (choice)
case 1:
while (j >= 0 && key < values[j])
temp = values[j];
values[j] = values[j + 1];
values[j + 1] = temp;
j--;

break;
case 2:
while (j >= 0 && key > values[j])
temp = values[j];
values[j] = values[j + 1];
values[j + 1] = temp;
j--;

break;


n++;


List shuffle(List items)
var random = new Random();

// Go through all elements.
for (var i = items.length - 1; i > 0; i--)

// Pick a pseudorandom number according to the list length
var n = random.nextInt(i + 1);

var temp = items[i];
items[i] = items[n];
items[n] = temp;


return items;










share|improve this question




























    0















    I'm trying to make an animation of sorting algorithms in flutter. So far I've coded the algorithm and managed to get some sort of animation by iterating once at a time instead of the whole sorting process but you have to keep tapping the button to sort, one item at a time. I've been trying to look for a way to animate this process. Here's my code:



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

    List<double> rectHeights = new List<double>();
    int n = 2;

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

    class MyApp extends StatelessWidget
    @override
    Widget build(BuildContext context)
    return MaterialApp(
    title: 'Sorting',
    theme: ThemeData(
    primarySwatch: Colors.blue,
    ),
    home: MyHomePage(),
    );



    class MyHomePage extends StatefulWidget
    MyHomePage(Key key) : super(key: key);

    @override
    _MyHomePageState createState() => _MyHomePageState();


    class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin
    int _selectedIndex = 0;
    final _widgetOptions = [
    Text('Index 0: Sort'),
    Text('Index 1: Shuffle'),
    ];

    @override
    void initState()
    super.initState();
    Random random = new Random();
    for (int i = 0; i < 35; i++)
    double ranNum = random.nextDouble() * 600;
    rectHeights.add(ranNum);



    @override
    Widget build(BuildContext context)
    return Scaffold(
    body: Padding(
    padding: EdgeInsets.all(8.0),
    child: Center(
    child: Row(
    children: rectangles(),
    ),
    ),
    ),
    bottomNavigationBar: BottomNavigationBar(
    iconSize: 50.0,
    items: <BottomNavigationBarItem>[
    BottomNavigationBarItem(icon: Icon(Icons.sort), title: Text('Sort', style: TextStyle(fontSize: 20.0),)),
    BottomNavigationBarItem(icon: Icon(Icons.shuffle), title: Text('Shuffle', style: TextStyle(fontSize: 20.0),)),
    ],
    currentIndex: _selectedIndex,
    fixedColor: Colors.blue,
    onTap: _onItemTapped,
    ),
    );


    void _onItemTapped(int index)
    setState(()
    _selectedIndex = index;
    );
    switch(_selectedIndex)
    case 0:
    setState(()
    insertSortOnce(rectHeights, 1);
    );
    break;
    case 1:
    setState(()
    shuffle(rectHeights);
    n = 2;
    );






    List<Widget> rectangles()
    List<Widget> rects = new List<Widget>();
    for (double height in rectHeights)
    var rect = Padding(
    padding: EdgeInsets.symmetric(horizontal: 1.0),
    child: Container(
    width: 8.0,
    height: height,
    decoration: BoxDecoration(
    shape: BoxShape.rectangle,
    color: Colors.blue
    ),
    ),
    );
    rects.add(rect);

    return rects;


    void insertSort(values, choice)
    int i, j;
    double key, temp;
    for (i = 1; i < values.length; i++)
    key = values[i];
    j = i - 1;
    switch (choice)
    case 1:
    while (j >= 0 && key < values[j])
    temp = values[j];
    values[j] = values[j + 1];
    values[j + 1] = temp;
    j--;

    break;
    case 2:
    while (j >= 0 && key > values[j])
    temp = values[j];
    values[j] = values[j + 1];
    values[j + 1] = temp;
    j--;

    break;




    void insertSortOnce(values, choice)
    int i, j;
    double key, temp;
    for (i = 1; i < n; i++)
    key = values[i];
    j = i - 1;
    switch (choice)
    case 1:
    while (j >= 0 && key < values[j])
    temp = values[j];
    values[j] = values[j + 1];
    values[j + 1] = temp;
    j--;

    break;
    case 2:
    while (j >= 0 && key > values[j])
    temp = values[j];
    values[j] = values[j + 1];
    values[j + 1] = temp;
    j--;

    break;


    n++;


    List shuffle(List items)
    var random = new Random();

    // Go through all elements.
    for (var i = items.length - 1; i > 0; i--)

    // Pick a pseudorandom number according to the list length
    var n = random.nextInt(i + 1);

    var temp = items[i];
    items[i] = items[n];
    items[n] = temp;


    return items;










    share|improve this question
























      0












      0








      0








      I'm trying to make an animation of sorting algorithms in flutter. So far I've coded the algorithm and managed to get some sort of animation by iterating once at a time instead of the whole sorting process but you have to keep tapping the button to sort, one item at a time. I've been trying to look for a way to animate this process. Here's my code:



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

      List<double> rectHeights = new List<double>();
      int n = 2;

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

      class MyApp extends StatelessWidget
      @override
      Widget build(BuildContext context)
      return MaterialApp(
      title: 'Sorting',
      theme: ThemeData(
      primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
      );



      class MyHomePage extends StatefulWidget
      MyHomePage(Key key) : super(key: key);

      @override
      _MyHomePageState createState() => _MyHomePageState();


      class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin
      int _selectedIndex = 0;
      final _widgetOptions = [
      Text('Index 0: Sort'),
      Text('Index 1: Shuffle'),
      ];

      @override
      void initState()
      super.initState();
      Random random = new Random();
      for (int i = 0; i < 35; i++)
      double ranNum = random.nextDouble() * 600;
      rectHeights.add(ranNum);



      @override
      Widget build(BuildContext context)
      return Scaffold(
      body: Padding(
      padding: EdgeInsets.all(8.0),
      child: Center(
      child: Row(
      children: rectangles(),
      ),
      ),
      ),
      bottomNavigationBar: BottomNavigationBar(
      iconSize: 50.0,
      items: <BottomNavigationBarItem>[
      BottomNavigationBarItem(icon: Icon(Icons.sort), title: Text('Sort', style: TextStyle(fontSize: 20.0),)),
      BottomNavigationBarItem(icon: Icon(Icons.shuffle), title: Text('Shuffle', style: TextStyle(fontSize: 20.0),)),
      ],
      currentIndex: _selectedIndex,
      fixedColor: Colors.blue,
      onTap: _onItemTapped,
      ),
      );


      void _onItemTapped(int index)
      setState(()
      _selectedIndex = index;
      );
      switch(_selectedIndex)
      case 0:
      setState(()
      insertSortOnce(rectHeights, 1);
      );
      break;
      case 1:
      setState(()
      shuffle(rectHeights);
      n = 2;
      );






      List<Widget> rectangles()
      List<Widget> rects = new List<Widget>();
      for (double height in rectHeights)
      var rect = Padding(
      padding: EdgeInsets.symmetric(horizontal: 1.0),
      child: Container(
      width: 8.0,
      height: height,
      decoration: BoxDecoration(
      shape: BoxShape.rectangle,
      color: Colors.blue
      ),
      ),
      );
      rects.add(rect);

      return rects;


      void insertSort(values, choice)
      int i, j;
      double key, temp;
      for (i = 1; i < values.length; i++)
      key = values[i];
      j = i - 1;
      switch (choice)
      case 1:
      while (j >= 0 && key < values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;
      case 2:
      while (j >= 0 && key > values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;




      void insertSortOnce(values, choice)
      int i, j;
      double key, temp;
      for (i = 1; i < n; i++)
      key = values[i];
      j = i - 1;
      switch (choice)
      case 1:
      while (j >= 0 && key < values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;
      case 2:
      while (j >= 0 && key > values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;


      n++;


      List shuffle(List items)
      var random = new Random();

      // Go through all elements.
      for (var i = items.length - 1; i > 0; i--)

      // Pick a pseudorandom number according to the list length
      var n = random.nextInt(i + 1);

      var temp = items[i];
      items[i] = items[n];
      items[n] = temp;


      return items;










      share|improve this question














      I'm trying to make an animation of sorting algorithms in flutter. So far I've coded the algorithm and managed to get some sort of animation by iterating once at a time instead of the whole sorting process but you have to keep tapping the button to sort, one item at a time. I've been trying to look for a way to animate this process. Here's my code:



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

      List<double> rectHeights = new List<double>();
      int n = 2;

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

      class MyApp extends StatelessWidget
      @override
      Widget build(BuildContext context)
      return MaterialApp(
      title: 'Sorting',
      theme: ThemeData(
      primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
      );



      class MyHomePage extends StatefulWidget
      MyHomePage(Key key) : super(key: key);

      @override
      _MyHomePageState createState() => _MyHomePageState();


      class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin
      int _selectedIndex = 0;
      final _widgetOptions = [
      Text('Index 0: Sort'),
      Text('Index 1: Shuffle'),
      ];

      @override
      void initState()
      super.initState();
      Random random = new Random();
      for (int i = 0; i < 35; i++)
      double ranNum = random.nextDouble() * 600;
      rectHeights.add(ranNum);



      @override
      Widget build(BuildContext context)
      return Scaffold(
      body: Padding(
      padding: EdgeInsets.all(8.0),
      child: Center(
      child: Row(
      children: rectangles(),
      ),
      ),
      ),
      bottomNavigationBar: BottomNavigationBar(
      iconSize: 50.0,
      items: <BottomNavigationBarItem>[
      BottomNavigationBarItem(icon: Icon(Icons.sort), title: Text('Sort', style: TextStyle(fontSize: 20.0),)),
      BottomNavigationBarItem(icon: Icon(Icons.shuffle), title: Text('Shuffle', style: TextStyle(fontSize: 20.0),)),
      ],
      currentIndex: _selectedIndex,
      fixedColor: Colors.blue,
      onTap: _onItemTapped,
      ),
      );


      void _onItemTapped(int index)
      setState(()
      _selectedIndex = index;
      );
      switch(_selectedIndex)
      case 0:
      setState(()
      insertSortOnce(rectHeights, 1);
      );
      break;
      case 1:
      setState(()
      shuffle(rectHeights);
      n = 2;
      );






      List<Widget> rectangles()
      List<Widget> rects = new List<Widget>();
      for (double height in rectHeights)
      var rect = Padding(
      padding: EdgeInsets.symmetric(horizontal: 1.0),
      child: Container(
      width: 8.0,
      height: height,
      decoration: BoxDecoration(
      shape: BoxShape.rectangle,
      color: Colors.blue
      ),
      ),
      );
      rects.add(rect);

      return rects;


      void insertSort(values, choice)
      int i, j;
      double key, temp;
      for (i = 1; i < values.length; i++)
      key = values[i];
      j = i - 1;
      switch (choice)
      case 1:
      while (j >= 0 && key < values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;
      case 2:
      while (j >= 0 && key > values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;




      void insertSortOnce(values, choice)
      int i, j;
      double key, temp;
      for (i = 1; i < n; i++)
      key = values[i];
      j = i - 1;
      switch (choice)
      case 1:
      while (j >= 0 && key < values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;
      case 2:
      while (j >= 0 && key > values[j])
      temp = values[j];
      values[j] = values[j + 1];
      values[j + 1] = temp;
      j--;

      break;


      n++;


      List shuffle(List items)
      var random = new Random();

      // Go through all elements.
      for (var i = items.length - 1; i > 0; i--)

      // Pick a pseudorandom number according to the list length
      var n = random.nextInt(i + 1);

      var temp = items[i];
      items[i] = items[n];
      items[n] = temp;


      return items;







      animation dart flutter mobile-development flutter-animation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 2:09









      Fabio SuarezFabio Suarez

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can use a Future function with a short delay, for example (one second) to call the insertSort() after each second till the rectHeights are sorted:



           var _notSorted = true ;
          var _shiftNotPressed = true ;

          Future sortRectangles() async
          while(_notSorted & _shiftPressed) // You have to provide a condition to know when to stop
          await new Future.delayed(const Duration(seconds: 1), ()
          insertSortOnce(rectHeights, 1);

          );




          Then checking for shuffling:



           void _onItemTapped(int index) 
          setState(()
          _selectedIndex = index;
          );
          switch(_selectedIndex)
          case 0:
          setState(()
          insertSortOnce(rectHeights, 1);
          );
          break;
          case 1:
          _shiftNotPressed = false ; // This is what you should add
          setState(()
          shuffle(rectHeights);
          n = 2;
          );





          Then Sorting completion:



           void insertSortOnce(values, choice) 
          _notSorted = false ; // if it didn't execute the loop it means sorted
          int i, j;
          double key, temp;
          for (i = 1; i < n; i++)
          key = values[i];
          j = i - 1;
          switch (choice)
          case 1:
          while (j >= 0 && key < values[j])
          _notSorted = true ; //You should figure a more efficient way to do this
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;
          case 2:
          while (j >= 0 && key > values[j])
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;


          n++;



          Also, You should include in your condition whether the shift button is pressed and to terminate accordingly.






          share|improve this answer

























          • I'm having trouble setting it up. Do you mean like this? Future sortRectangles() async while(_notSorted & _shiftNotPressed) // You have to provide a condition to know when to stop await new Future.delayed(const Duration(seconds: 1), () insertSortOnce(rectsHeights, 1); );

            – Fabio Suarez
            Mar 8 at 23:09












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055742%2fanimating-a-loop-in-flutter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can use a Future function with a short delay, for example (one second) to call the insertSort() after each second till the rectHeights are sorted:



           var _notSorted = true ;
          var _shiftNotPressed = true ;

          Future sortRectangles() async
          while(_notSorted & _shiftPressed) // You have to provide a condition to know when to stop
          await new Future.delayed(const Duration(seconds: 1), ()
          insertSortOnce(rectHeights, 1);

          );




          Then checking for shuffling:



           void _onItemTapped(int index) 
          setState(()
          _selectedIndex = index;
          );
          switch(_selectedIndex)
          case 0:
          setState(()
          insertSortOnce(rectHeights, 1);
          );
          break;
          case 1:
          _shiftNotPressed = false ; // This is what you should add
          setState(()
          shuffle(rectHeights);
          n = 2;
          );





          Then Sorting completion:



           void insertSortOnce(values, choice) 
          _notSorted = false ; // if it didn't execute the loop it means sorted
          int i, j;
          double key, temp;
          for (i = 1; i < n; i++)
          key = values[i];
          j = i - 1;
          switch (choice)
          case 1:
          while (j >= 0 && key < values[j])
          _notSorted = true ; //You should figure a more efficient way to do this
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;
          case 2:
          while (j >= 0 && key > values[j])
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;


          n++;



          Also, You should include in your condition whether the shift button is pressed and to terminate accordingly.






          share|improve this answer

























          • I'm having trouble setting it up. Do you mean like this? Future sortRectangles() async while(_notSorted & _shiftNotPressed) // You have to provide a condition to know when to stop await new Future.delayed(const Duration(seconds: 1), () insertSortOnce(rectsHeights, 1); );

            – Fabio Suarez
            Mar 8 at 23:09
















          0














          You can use a Future function with a short delay, for example (one second) to call the insertSort() after each second till the rectHeights are sorted:



           var _notSorted = true ;
          var _shiftNotPressed = true ;

          Future sortRectangles() async
          while(_notSorted & _shiftPressed) // You have to provide a condition to know when to stop
          await new Future.delayed(const Duration(seconds: 1), ()
          insertSortOnce(rectHeights, 1);

          );




          Then checking for shuffling:



           void _onItemTapped(int index) 
          setState(()
          _selectedIndex = index;
          );
          switch(_selectedIndex)
          case 0:
          setState(()
          insertSortOnce(rectHeights, 1);
          );
          break;
          case 1:
          _shiftNotPressed = false ; // This is what you should add
          setState(()
          shuffle(rectHeights);
          n = 2;
          );





          Then Sorting completion:



           void insertSortOnce(values, choice) 
          _notSorted = false ; // if it didn't execute the loop it means sorted
          int i, j;
          double key, temp;
          for (i = 1; i < n; i++)
          key = values[i];
          j = i - 1;
          switch (choice)
          case 1:
          while (j >= 0 && key < values[j])
          _notSorted = true ; //You should figure a more efficient way to do this
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;
          case 2:
          while (j >= 0 && key > values[j])
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;


          n++;



          Also, You should include in your condition whether the shift button is pressed and to terminate accordingly.






          share|improve this answer

























          • I'm having trouble setting it up. Do you mean like this? Future sortRectangles() async while(_notSorted & _shiftNotPressed) // You have to provide a condition to know when to stop await new Future.delayed(const Duration(seconds: 1), () insertSortOnce(rectsHeights, 1); );

            – Fabio Suarez
            Mar 8 at 23:09














          0












          0








          0







          You can use a Future function with a short delay, for example (one second) to call the insertSort() after each second till the rectHeights are sorted:



           var _notSorted = true ;
          var _shiftNotPressed = true ;

          Future sortRectangles() async
          while(_notSorted & _shiftPressed) // You have to provide a condition to know when to stop
          await new Future.delayed(const Duration(seconds: 1), ()
          insertSortOnce(rectHeights, 1);

          );




          Then checking for shuffling:



           void _onItemTapped(int index) 
          setState(()
          _selectedIndex = index;
          );
          switch(_selectedIndex)
          case 0:
          setState(()
          insertSortOnce(rectHeights, 1);
          );
          break;
          case 1:
          _shiftNotPressed = false ; // This is what you should add
          setState(()
          shuffle(rectHeights);
          n = 2;
          );





          Then Sorting completion:



           void insertSortOnce(values, choice) 
          _notSorted = false ; // if it didn't execute the loop it means sorted
          int i, j;
          double key, temp;
          for (i = 1; i < n; i++)
          key = values[i];
          j = i - 1;
          switch (choice)
          case 1:
          while (j >= 0 && key < values[j])
          _notSorted = true ; //You should figure a more efficient way to do this
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;
          case 2:
          while (j >= 0 && key > values[j])
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;


          n++;



          Also, You should include in your condition whether the shift button is pressed and to terminate accordingly.






          share|improve this answer















          You can use a Future function with a short delay, for example (one second) to call the insertSort() after each second till the rectHeights are sorted:



           var _notSorted = true ;
          var _shiftNotPressed = true ;

          Future sortRectangles() async
          while(_notSorted & _shiftPressed) // You have to provide a condition to know when to stop
          await new Future.delayed(const Duration(seconds: 1), ()
          insertSortOnce(rectHeights, 1);

          );




          Then checking for shuffling:



           void _onItemTapped(int index) 
          setState(()
          _selectedIndex = index;
          );
          switch(_selectedIndex)
          case 0:
          setState(()
          insertSortOnce(rectHeights, 1);
          );
          break;
          case 1:
          _shiftNotPressed = false ; // This is what you should add
          setState(()
          shuffle(rectHeights);
          n = 2;
          );





          Then Sorting completion:



           void insertSortOnce(values, choice) 
          _notSorted = false ; // if it didn't execute the loop it means sorted
          int i, j;
          double key, temp;
          for (i = 1; i < n; i++)
          key = values[i];
          j = i - 1;
          switch (choice)
          case 1:
          while (j >= 0 && key < values[j])
          _notSorted = true ; //You should figure a more efficient way to do this
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;
          case 2:
          while (j >= 0 && key > values[j])
          temp = values[j];
          values[j] = values[j + 1];
          values[j + 1] = temp;
          j--;

          break;


          n++;



          Also, You should include in your condition whether the shift button is pressed and to terminate accordingly.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 9 at 5:49

























          answered Mar 8 at 5:04









          Mazin IbrahimMazin Ibrahim

          1,4121717




          1,4121717












          • I'm having trouble setting it up. Do you mean like this? Future sortRectangles() async while(_notSorted & _shiftNotPressed) // You have to provide a condition to know when to stop await new Future.delayed(const Duration(seconds: 1), () insertSortOnce(rectsHeights, 1); );

            – Fabio Suarez
            Mar 8 at 23:09


















          • I'm having trouble setting it up. Do you mean like this? Future sortRectangles() async while(_notSorted & _shiftNotPressed) // You have to provide a condition to know when to stop await new Future.delayed(const Duration(seconds: 1), () insertSortOnce(rectsHeights, 1); );

            – Fabio Suarez
            Mar 8 at 23:09

















          I'm having trouble setting it up. Do you mean like this? Future sortRectangles() async while(_notSorted & _shiftNotPressed) // You have to provide a condition to know when to stop await new Future.delayed(const Duration(seconds: 1), () insertSortOnce(rectsHeights, 1); );

          – Fabio Suarez
          Mar 8 at 23:09






          I'm having trouble setting it up. Do you mean like this? Future sortRectangles() async while(_notSorted & _shiftNotPressed) // You have to provide a condition to know when to stop await new Future.delayed(const Duration(seconds: 1), () insertSortOnce(rectsHeights, 1); );

          – Fabio Suarez
          Mar 8 at 23:09




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055742%2fanimating-a-loop-in-flutter%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved