@@ -132,143 +132,150 @@ class _BubbleSortBarsState extends State<BubbleSortBars> {
132
132
133
133
@override
134
134
Widget build (BuildContext context) {
135
- ScreenUtil .init (
136
- context,
137
- width: 512.0 ,
138
- height: 1024.0 ,
139
- allowFontScaling: true ,
140
- );
141
135
_containerList ();
142
136
if (swap == true || finalIterator != 0 ) {
143
137
WidgetsBinding .instance.addPostFrameCallback ((_) => nextStep ());
144
138
}
145
139
146
- return Scaffold (
147
- appBar: AppBar (
148
- automaticallyImplyLeading: false ,
149
- leading: IconButton (
150
- icon: Icon (Icons .arrow_back_ios),
151
- onPressed: () {
152
- Navigator .pop (context);
153
- },
154
- ),
155
- centerTitle: true ,
156
- title: Text (
157
- 'Bubble Sort' ,
158
- style: Theme .of (context).textTheme.headline6,
159
- ),
160
- ),
161
- floatingActionButton: FloatingActionButton (
162
- backgroundColor: Colors .white,
163
- child: (! swap)
164
- ? Icon (
165
- Icons .play_arrow,
166
- color: Colors .black,
167
- )
168
- : Icon (
169
- Icons .pause,
170
- color: Colors .black,
140
+ return LayoutBuilder (
141
+ // ignore: missing_return
142
+ builder: (_, BoxConstraints constraints) {
143
+ if (constraints.maxWidth != 0 ) {
144
+ ScreenUtil .init (
145
+ constraints,
146
+ designSize: Size (512.0 , 1024.0 ),
147
+ allowFontScaling: true ,
148
+ );
149
+ return Scaffold (
150
+ appBar: AppBar (
151
+ automaticallyImplyLeading: false ,
152
+ leading: IconButton (
153
+ icon: Icon (Icons .arrow_back_ios),
154
+ onPressed: () {
155
+ Navigator .pop (context);
156
+ },
157
+ ),
158
+ centerTitle: true ,
159
+ title: Text (
160
+ 'Bubble Sort' ,
161
+ style: Theme .of (context).textTheme.headline6,
162
+ ),
163
+ ),
164
+ floatingActionButton: FloatingActionButton (
165
+ backgroundColor: Colors .white,
166
+ child: (! swap)
167
+ ? Icon (
168
+ Icons .play_arrow,
169
+ color: Colors .black,
170
+ )
171
+ : Icon (
172
+ Icons .pause,
173
+ color: Colors .black,
174
+ ),
175
+ onPressed: () {
176
+ doNotRefresh = true ;
177
+ swap = ! swap;
178
+ setState (() {});
179
+ }),
180
+ floatingActionButtonLocation:
181
+ FloatingActionButtonLocation .centerDocked,
182
+ bottomNavigationBar: Container (
183
+ height: ScreenUtil ().setHeight (1024 / 5.5 ),
184
+ child: Material (
185
+ elevation: 30 ,
186
+ color: Theme .of (context).primaryColor,
187
+ child: Scrollbar (
188
+ controller: _scrollController,
189
+ isAlwaysShown: true ,
190
+ child: ListView (
191
+ controller: _scrollController,
192
+ padding: EdgeInsets .all (8.0 ),
193
+ children: < Widget > [
194
+ SizedBox (
195
+ height: 20 ,
196
+ ),
197
+ Slider (
198
+ min: 2 ,
199
+ max: 200 ,
200
+ activeColor: Theme .of (context).accentColor,
201
+ inactiveColor: Colors .grey,
202
+ onChanged: (value) {
203
+ doNotRefresh = false ;
204
+ counter = 0 ;
205
+ swap = false ;
206
+ setState (() {
207
+ _numberOfElements = value.toInt ();
208
+ });
209
+ },
210
+ value: _numberOfElements.toDouble (),
211
+ ),
212
+ Center (
213
+ child: Text (
214
+ "Elements: ${_numberOfElements .toInt ()}" ,
215
+ style: Theme .of (context).textTheme.subtitle2,
216
+ ),
217
+ ),
218
+ SizedBox (
219
+ height: 20 ,
220
+ ),
221
+ Slider (
222
+ min: 0 ,
223
+ max: 100 ,
224
+ divisions: 10 ,
225
+ activeColor: Theme .of (context).accentColor,
226
+ inactiveColor: Colors .grey,
227
+ onChanged: (value) {
228
+ setState (() {
229
+ delay2 = value.toInt ();
230
+ });
231
+ },
232
+ onChangeEnd: (value) {
233
+ setState (() {
234
+ doNotRefresh = true ;
235
+ delay = value.toInt ();
236
+ });
237
+ },
238
+ value: delay2.roundToDouble (),
239
+ ),
240
+ Center (
241
+ child: Text (
242
+ "Delay: ${delay2 .toInt ()} ms" ,
243
+ style: Theme .of (context).textTheme.subtitle2,
244
+ ),
245
+ ),
246
+ ],
247
+ ),
171
248
),
172
- onPressed: () {
173
- doNotRefresh = true ;
174
- swap = ! swap;
175
- setState (() {});
176
- }),
177
- floatingActionButtonLocation: FloatingActionButtonLocation .centerDocked,
178
- bottomNavigationBar: Container (
179
- height: ScreenUtil ().setHeight (1024 / 5.5 ),
180
- child: Material (
181
- elevation: 30 ,
182
- color: Theme .of (context).primaryColor,
183
- child: Scrollbar (
184
- controller: _scrollController,
185
- isAlwaysShown: true ,
186
- child: ListView (
187
- controller: _scrollController,
188
- padding: EdgeInsets .all (8.0 ),
249
+ ),
250
+ ),
251
+ body: Stack (
189
252
children: < Widget > [
190
- SizedBox (
191
- height: 20 ,
192
- ),
193
- Slider (
194
- min: 2 ,
195
- max: 200 ,
196
- activeColor: Theme .of (context).accentColor,
197
- inactiveColor: Colors .grey,
198
- onChanged: (value) {
199
- doNotRefresh = false ;
200
- counter = 0 ;
201
- swap = false ;
202
- setState (() {
203
- _numberOfElements = value.toInt ();
204
- });
205
- },
206
- value: _numberOfElements.toDouble (),
207
- ),
208
- Center (
209
- child: Text (
210
- "Elements: ${_numberOfElements .toInt ()}" ,
211
- style: Theme .of (context).textTheme.subtitle2,
253
+ Container (
254
+ color: Colors .grey[900 ],
255
+ child: Column (
256
+ children: < Widget > [
257
+ Spacer (),
258
+ Row (
259
+ mainAxisAlignment: MainAxisAlignment .spaceEvenly,
260
+ children: containerList,
261
+ ),
262
+ Spacer (),
263
+ ],
212
264
),
213
265
),
214
- SizedBox (
215
- height: 20 ,
216
- ),
217
- Slider (
218
- min: 0 ,
219
- max: 100 ,
220
- divisions: 10 ,
221
- activeColor: Theme .of (context).accentColor,
222
- inactiveColor: Colors .grey,
223
- onChanged: (value) {
224
- setState (() {
225
- delay2 = value.toInt ();
226
- });
227
- },
228
- onChangeEnd: (value) {
229
- setState (() {
230
- doNotRefresh = true ;
231
- delay = value.toInt ();
232
- });
233
- },
234
- value: delay2.roundToDouble (),
235
- ),
236
- Center (
266
+ Positioned (
267
+ top: 5 ,
268
+ left: 5 ,
237
269
child: Text (
238
- "Delay : ${ delay2 . toInt ()} ms " ,
270
+ "Comparisons : $counter \n Max: ${ _elements [ i ]} \n Array Iteration: ${ _elements . length - n + 1 } " ,
239
271
style: Theme .of (context).textTheme.subtitle2,
240
272
),
241
273
),
242
274
],
243
275
),
244
- ),
245
- ),
246
- ),
247
- body: Stack (
248
- children: < Widget > [
249
- Container (
250
- color: Colors .grey[900 ],
251
- child: Column (
252
- children: < Widget > [
253
- Spacer (),
254
- Row (
255
- mainAxisAlignment: MainAxisAlignment .spaceEvenly,
256
- children: containerList,
257
- ),
258
- Spacer (),
259
- ],
260
- ),
261
- ),
262
- Positioned (
263
- top: 5 ,
264
- left: 5 ,
265
- child: Text (
266
- "Comparisons: $counter \n Max: ${_elements [i ]} \n Array Iteration: ${_elements .length - n + 1 }" ,
267
- style: Theme .of (context).textTheme.subtitle2,
268
- ),
269
- ),
270
- ],
271
- ),
276
+ );
277
+ }
278
+ },
272
279
);
273
280
}
274
281
}
0 commit comments