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

On a tidally locked planet, would time be quantized?

Using substitution ciphers to generate new alphabets in a novel

Do the primes contain an infinite almost arithmetic progression?

Terse Method to Swap Lowest for Highest?

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?

How do you make your own symbol when Detexify fails?

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

Is there a RAID 0 Equivalent for RAM?

Can a Canadian Travel to the USA twice, less than 180 days each time?

What is the highest possible scrabble score for placing a single tile

Can I still be respawned if I die by falling off the map?

Is there a way to get `mathscr' with lower case letters in pdfLaTeX?

Why is so much work done on numerical verification of the Riemann Hypothesis?

How does the math work for Perception checks?

How should I respond when I lied about my education and the company finds out through background check?

Temporarily disable WLAN internet access for children, but allow it for adults

Multiplicative persistence

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

Can a College of Swords bard use a Blade Flourish option on an opportunity attack provoked by their own Dissonant Whispers spell?

Can disgust be a key component of horror?

Does IPv6 have similar concept of network mask?

How much character growth crosses the line into breaking the character

PTIJ: Haman's bad computer



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













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

      1




      1






















          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,0671515




          1,0671515












          • 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

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived