Skip to content

Commit 7ecf5df

Browse files
committed
Some Changes
1 parent 66fac08 commit 7ecf5df

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

lib/src/simulations/bubble_sort.dart

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,33 @@ class _BubbleSortBarsState extends State<BubbleSortBars> {
4949
}
5050

5151
_initialize() {
52-
barColor.clear();
5352
if (refresh) {
53+
barColor.clear();
5454
_elements.clear();
5555
_index.clear();
5656
i = 0;
5757
var rng = new Random();
5858
for (int i = 0; i < _numberOfElements; i++) {
5959
_elements.add(rng.nextInt(400));
6060
_index.add(i);
61+
barColor.add(Theme.of(context).primaryColor);
6162
}
6263
n = _elements.length;
6364
}
6465
this.barwidth = MediaQuery.of(context).size.width / (_elements.length + 1);
65-
for (int j = 0; j < _elements.length; j++) {
66-
if (n == 1)
67-
barColor.add(Colors.greenAccent[400]);
68-
else {
69-
if (j == i)
70-
barColor.add(Colors.red);
71-
else if (j == i - 1)
72-
barColor.add(Colors.blue);
73-
else
74-
barColor.add(Theme.of(context).primaryColor);
75-
}
76-
}
7766
}
7867

7968
nextStep() async {
8069
await Future.delayed(Duration(milliseconds: delay));
8170
setState(() {
82-
for (int k = 0; k < _numberOfElements; k++) _index[k] = k;
71+
barColor.clear();
72+
for (int j = 0; j < _elements.length; j++) {
73+
if (n == 1)
74+
barColor.add(Colors.greenAccent[400]);
75+
else
76+
barColor.add(Theme.of(context).primaryColor);
77+
_index[j] = j;
78+
}
8379
if (n == 1) {
8480
animating = false;
8581
return;
@@ -100,6 +96,8 @@ class _BubbleSortBarsState extends State<BubbleSortBars> {
10096
} else {
10197
i++;
10298
}
99+
barColor[i] = Colors.red;
100+
barColor[i - 1] = Colors.blue;
103101
});
104102
}
105103

@@ -233,7 +231,7 @@ class _BubbleSortBarsState extends State<BubbleSortBars> {
233231
),
234232
Center(
235233
child: Text(
236-
"Delay: ${delay2/1000.toInt()} s",
234+
"Delay: ${delay2 / 1000.toInt()} s",
237235
style: TextStyle(
238236
fontSize: 18,
239237
fontFamily: 'Ubuntu',

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description: A new Flutter project.
1414
version: 1.0.0+1
1515

1616
environment:
17-
sdk: ">=2.1.0 <3.0.0"
17+
sdk: ">=2.2.2 <3.0.0"
1818

1919
dependencies:
2020
flutter:

0 commit comments

Comments
 (0)