Skip to content

Commit 94fb442

Browse files
authored
Dependencies Updated (builtree#156)
Layout Builder is used in each simulation to generate Boxconstrains, required for ScreenUtil library
1 parent 72bc9ed commit 94fb442

12 files changed

+1237
-1160
lines changed

lib/generated_plugin_registrant.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
// Generated file. Do not edit.
33
//
44

5-
// ignore: unused_import
6-
import 'dart:ui';
5+
// ignore_for_file: lines_longer_than_80_chars
76

87
import 'package:shared_preferences_web/shared_preferences_web.dart';
98
import 'package:url_launcher_web/url_launcher_web.dart';
109

1110
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
1211

1312
// ignore: public_member_api_docs
14-
void registerPlugins(PluginRegistry registry) {
15-
SharedPreferencesPlugin.registerWith(registry.registrarFor(SharedPreferencesPlugin));
16-
UrlLauncherPlugin.registerWith(registry.registrarFor(UrlLauncherPlugin));
17-
registry.registerMessageHandler();
13+
void registerPlugins(Registrar registrar) {
14+
SharedPreferencesPlugin.registerWith(registrar);
15+
UrlLauncherPlugin.registerWith(registrar);
16+
registrar.registerMessageHandler();
1817
}

lib/src/custom_items/home_page.dart

+41-27
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,44 @@ import 'package:provider/provider.dart';
66
class HomePage extends StatelessWidget {
77
@override
88
Widget build(BuildContext context) {
9-
ScreenUtil.init(context, width: 512, height: 1005, allowFontScaling: false);
109
final appState = Provider.of<Simulations>(context);
11-
return Container(
12-
child: ListView(
13-
children: <Widget>[
14-
HomeHorizontalList(
15-
listName: 'Favorites',
16-
elements: (appState.favorites.length != 0)
17-
? appState.favorites
18-
: [
19-
Container(
20-
width: MediaQuery.of(context).size.width - 20,
21-
child: Center(
22-
child: Text(
23-
"No favorites yet!",
24-
style: Theme.of(context).textTheme.caption,
25-
),
26-
),
27-
),
28-
],
29-
),
30-
HomeHorizontalList(
31-
listName: 'All',
32-
elements: appState.all,
33-
),
34-
],
35-
),
10+
return LayoutBuilder(
11+
// ignore: missing_return
12+
builder: (_, BoxConstraints constraints) {
13+
if (constraints.maxWidth != 0) {
14+
ScreenUtil.init(
15+
constraints,
16+
designSize: Size(512.0, 850.0),
17+
allowFontScaling: false,
18+
);
19+
return Container(
20+
child: ListView(
21+
children: <Widget>[
22+
HomeHorizontalList(
23+
listName: 'Favorites',
24+
elements: (appState.favorites.length != 0)
25+
? appState.favorites
26+
: [
27+
Container(
28+
width: MediaQuery.of(context).size.width - 20,
29+
child: Center(
30+
child: Text(
31+
"No favorites yet!",
32+
style: Theme.of(context).textTheme.caption,
33+
),
34+
),
35+
),
36+
],
37+
),
38+
HomeHorizontalList(
39+
listName: 'All',
40+
elements: appState.all,
41+
),
42+
],
43+
),
44+
);
45+
}
46+
},
3647
);
3748
}
3849
}
@@ -61,7 +72,10 @@ class HomeHorizontalList extends StatelessWidget {
6172
),
6273
),
6374
Container(
64-
height: MediaQuery.of(context).size.height > MediaQuery.of(context).size.width ? ScreenUtil().setHeight(260) : 250,
75+
height: MediaQuery.of(context).size.height >
76+
MediaQuery.of(context).size.width
77+
? ScreenUtil().setHeight(260)
78+
: 250,
6579
child: ListView(
6680
scrollDirection: Axis.horizontal,
6781
children: elements,

lib/src/simulations/bubble_sort.dart

+129-122
Original file line numberDiff line numberDiff line change
@@ -132,143 +132,150 @@ class _BubbleSortBarsState extends State<BubbleSortBars> {
132132

133133
@override
134134
Widget build(BuildContext context) {
135-
ScreenUtil.init(
136-
context,
137-
width: 512.0,
138-
height: 1024.0,
139-
allowFontScaling: true,
140-
);
141135
_containerList();
142136
if (swap == true || finalIterator != 0) {
143137
WidgetsBinding.instance.addPostFrameCallback((_) => nextStep());
144138
}
145139

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+
),
171248
),
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(
189252
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+
],
212264
),
213265
),
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,
237269
child: Text(
238-
"Delay: ${delay2.toInt()} ms",
270+
"Comparisons: $counter \nMax: ${_elements[i]} \nArray Iteration: ${_elements.length - n + 1}",
239271
style: Theme.of(context).textTheme.subtitle2,
240272
),
241273
),
242274
],
243275
),
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 \nMax: ${_elements[i]} \nArray Iteration: ${_elements.length - n + 1}",
267-
style: Theme.of(context).textTheme.subtitle2,
268-
),
269-
),
270-
],
271-
),
276+
);
277+
}
278+
},
272279
);
273280
}
274281
}

0 commit comments

Comments
 (0)