Skip to content

Commit 2db33d9

Browse files
committed
Replace picture_url with id
1 parent 4a52d5b commit 2db33d9

File tree

3 files changed

+79
-56
lines changed

3 files changed

+79
-56
lines changed

lib/main.dart

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,31 @@ class BuildingPosition {
187187
});
188188
}
189189

190+
typedef Id = String;
191+
190192
class Area {
191193
final String title;
194+
final Id id;
192195
final String floor;
193196
final bool indoor;
194-
final String pictureUrl;
197+
final bool hasImage;
195198

196199
Area({
197200
required this.title,
198201
required this.floor,
199202
required this.indoor,
200-
required this.pictureUrl,
203+
required this.id,
204+
this.hasImage = true,
201205
});
202206
}
203207

208+
Id getAreaId(Id buildingId, Id areaId) => "${buildingId}_$areaId";
209+
204210
class StudySpace {
205211
final String title;
212+
final String id;
206213
List<OpeningHours>
207214
openingHours; // From Monday (list index 0) to Sunday (list index 6)
208-
final String pictureUrl;
209215
final BuildingPosition buildingPosition;
210216
final String address;
211217
final String phoneNumber;
@@ -214,8 +220,8 @@ class StudySpace {
214220

215221
StudySpace({
216222
required this.title,
223+
required this.id,
217224
required this.openingHours,
218-
required this.pictureUrl,
219225
required this.buildingPosition,
220226
required this.address,
221227
required this.phoneNumber,
@@ -224,6 +230,12 @@ class StudySpace {
224230
});
225231
}
226232

233+
String getImageUrl({
234+
required Id id,
235+
hasImage = true,
236+
}) =>
237+
hasImage ? "assets/$id.webp" : "assets/image_coming_soon.webp";
238+
227239
class MyHomePage extends StatefulWidget {
228240
const MyHomePage({Key? key, required this.title}) : super(key: key);
229241

@@ -660,7 +672,8 @@ class _MyHomePageState extends State<MyHomePage> {
660672
decoration: BoxDecoration(
661673
image: DecorationImage(
662674
fit: BoxFit.fitHeight,
663-
image: AssetImage(studySpace.pictureUrl)))))),
675+
image: AssetImage(
676+
getImageUrl(id: studySpace.id))))))),
664677
]),
665678
)),
666679
);

lib/studySpaceList.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import 'package:mstudy/main.dart';
44
List<StudySpace> studySpaces = [
55
StudySpace(
66
title: "Art, Architecture, and Engineering Library",
7+
id: "duderstadt",
78
openingHours: List.filled(7, const OpeningHours.allDay()),
8-
pictureUrl: "assets/duderstadt.webp",
99
address: "2281 Bonisteel Blvd",
1010
buildingPosition:
1111
const BuildingPosition(latitude: 42.291165, longitude: -83.715716),
@@ -15,6 +15,7 @@ List<StudySpace> studySpaces = [
1515
),
1616
StudySpace(
1717
title: "Hatcher Library",
18+
id: "hatcher",
1819
openingHours: [
1920
...List.filled(
2021
4,
@@ -27,7 +28,6 @@ List<StudySpace> studySpaces = [
2728
const OpeningHours.range(
2829
TimeOfDay(hour: 13, minute: 0), TimeOfDay(hour: 19, minute: 0)),
2930
],
30-
pictureUrl: "assets/hatcher.webp",
3131
address: "913 S. University Avenue",
3232
buildingPosition: const BuildingPosition(
3333
latitude: 42.276334,
@@ -37,14 +37,15 @@ List<StudySpace> studySpaces = [
3737
areas: [
3838
Area(
3939
title: "Asia Library",
40+
id: "asia",
4041
floor: "4",
41-
pictureUrl: "assets/hatcher_asia.webp",
4242
indoor: true,
4343
)
4444
],
4545
),
4646
StudySpace(
4747
title: "Shapiro Library",
48+
id: "shapiro",
4849
openingHours: [
4950
...List.filled(4, const OpeningHours.allDay()),
5051
const OpeningHours.range(
@@ -54,7 +55,6 @@ List<StudySpace> studySpaces = [
5455
const OpeningHours.range(
5556
TimeOfDay(hour: 10, minute: 0), TimeOfDay(hour: 0, minute: 0)),
5657
],
57-
pictureUrl: "assets/shapiro.webp",
5858
address: "919 S. University Ave",
5959
buildingPosition:
6060
const BuildingPosition(latitude: 42.275615, longitude: -83.737183),
@@ -64,6 +64,7 @@ List<StudySpace> studySpaces = [
6464
),
6565
StudySpace(
6666
title: "Fine Arts Library",
67+
id: "fine_arts",
6768
openingHours: [
6869
...List.filled(
6970
5,
@@ -72,7 +73,6 @@ List<StudySpace> studySpaces = [
7273
const OpeningHours.closed(),
7374
const OpeningHours.closed(),
7475
],
75-
pictureUrl: "assets/fine_arts.webp",
7676
address: "855 S. University Ave",
7777
buildingPosition:
7878
const BuildingPosition(latitude: 42.274944, longitude: -83.738995),
@@ -82,6 +82,7 @@ List<StudySpace> studySpaces = [
8282
),
8383
StudySpace(
8484
title: "Taubman Health Sciences Library",
85+
id: "taubman",
8586
openingHours: [
8687
...List.filled(
8788
5,
@@ -90,7 +91,6 @@ List<StudySpace> studySpaces = [
9091
const OpeningHours.closed(),
9192
const OpeningHours.closed(),
9293
],
93-
pictureUrl: "assets/taubman.webp",
9494
address: "1135 Catherine St",
9595
buildingPosition:
9696
const BuildingPosition(latitude: 42.283548, longitude: -83.734451),
@@ -100,6 +100,7 @@ List<StudySpace> studySpaces = [
100100
),
101101
StudySpace(
102102
title: "Music Library",
103+
id: "music",
103104
openingHours: [
104105
...List.filled(
105106
5,
@@ -108,7 +109,6 @@ List<StudySpace> studySpaces = [
108109
const OpeningHours.closed(),
109110
const OpeningHours.closed(),
110111
],
111-
pictureUrl: "assets/music.webp",
112112
address: "1100 Baits Dr",
113113
buildingPosition:
114114
const BuildingPosition(latitude: 42.290373, longitude: -83.721006),
@@ -118,6 +118,7 @@ List<StudySpace> studySpaces = [
118118
),
119119
StudySpace(
120120
title: "East Quad",
121+
id: "east_quad",
121122
openingHours: [
122123
...List.filled(
123124
5,
@@ -128,7 +129,6 @@ List<StudySpace> studySpaces = [
128129
const OpeningHours.range(
129130
TimeOfDay(hour: 9, minute: 0), TimeOfDay(hour: 20, minute: 0)),
130131
],
131-
pictureUrl: "assets/east_quad.webp",
132132
address: "701 E. University",
133133
buildingPosition: const BuildingPosition(
134134
latitude: 42.272745760362035, longitude: -83.73550729385826),
@@ -137,21 +137,22 @@ List<StudySpace> studySpaces = [
137137
areas: [
138138
Area(
139139
title: "Blue Cafe",
140+
id: "blue_cafe",
140141
floor: "Main",
141142
indoor: true,
142-
pictureUrl: 'assets/east_quad_blue_cafe.webp',
143143
),
144144
Area(
145145
title: "Open Space",
146+
id: "open_space",
146147
floor: "Lower Level",
147148
indoor: true,
148-
pictureUrl: 'assets/east_quad_open_space.webp',
149149
),
150150
Area(
151151
title: "Study Rooms",
152+
id: "study_rooms",
152153
floor: "Lower Level",
153154
indoor: true,
154-
pictureUrl: 'assets/image_coming_soon.webp',
155+
hasImage: false,
155156
),
156157
],
157158
)

lib/studySpacePage.dart

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ class OpeningHourCard extends StatelessWidget {
7474
}
7575

7676
class AreasCard extends StatelessWidget {
77-
const AreasCard({Key? key, required this.areas}) : super(key: key);
77+
const AreasCard({Key? key, required this.buildingId, required this.areas})
78+
: super(key: key);
7879

80+
final String buildingId;
7981
final List<Area> areas;
8082

8183
@override
@@ -88,44 +90,50 @@ class AreasCard extends StatelessWidget {
8890
clipBehavior: Clip.none,
8991
scrollDirection: Axis.horizontal,
9092
itemCount: areas.length,
91-
itemBuilder: (BuildContext context, int index) => Card(
92-
margin: EdgeInsets.zero,
93-
child: Padding(
94-
padding: EdgeInsets.all(
95-
Theme.of(context).textTheme.bodyLarge!.fontSize!),
96-
child: Column(
97-
crossAxisAlignment: CrossAxisAlignment.start,
98-
children: [
99-
Text(
100-
areas[index].title,
101-
style: Theme.of(context).textTheme.headlineSmall,
102-
textAlign: TextAlign.left,
103-
),
104-
SizedBox(
105-
height:
106-
Theme.of(context).textTheme.bodyMedium!.fontSize! /
107-
2),
108-
Text(
109-
"Floor: ${areas[index].floor}",
110-
style: Theme.of(context).textTheme.bodyMedium,
111-
),
112-
SizedBox(
113-
height:
114-
Theme.of(context).textTheme.headlineSmall!.fontSize! /
115-
2),
116-
SizedBox(
117-
width: cardContentWidth,
118-
child: AspectRatio(
119-
aspectRatio: 1.5,
120-
child: Container(
121-
decoration: BoxDecoration(
122-
image: DecorationImage(
123-
fit: BoxFit.fitHeight,
124-
image: AssetImage(
125-
areas[index].pictureUrl)))))),
126-
],
127-
),
128-
)),
93+
itemBuilder: (BuildContext context, int index) {
94+
var area = areas[index];
95+
return Card(
96+
margin: EdgeInsets.zero,
97+
child: Padding(
98+
padding: EdgeInsets.all(
99+
Theme.of(context).textTheme.bodyLarge!.fontSize!),
100+
child: Column(
101+
crossAxisAlignment: CrossAxisAlignment.start,
102+
children: [
103+
Text(
104+
area.title,
105+
style: Theme.of(context).textTheme.headlineSmall,
106+
textAlign: TextAlign.left,
107+
),
108+
SizedBox(
109+
height:
110+
Theme.of(context).textTheme.bodyMedium!.fontSize! /
111+
2),
112+
Text(
113+
"Floor: ${area.floor}",
114+
style: Theme.of(context).textTheme.bodyMedium,
115+
),
116+
SizedBox(
117+
height: Theme.of(context)
118+
.textTheme
119+
.headlineSmall!
120+
.fontSize! /
121+
2),
122+
SizedBox(
123+
width: cardContentWidth,
124+
child: AspectRatio(
125+
aspectRatio: 1.5,
126+
child: Container(
127+
decoration: BoxDecoration(
128+
image: DecorationImage(
129+
fit: BoxFit.fitHeight,
130+
image: AssetImage(getImageUrl(
131+
id: getAreaId(buildingId, area.id),
132+
hasImage: area.hasImage))))))),
133+
],
134+
),
135+
));
136+
},
129137
separatorBuilder: (context, index) => SizedBox(
130138
width: Theme.of(context).textTheme.bodySmall!.fontSize! / 2,
131139
),
@@ -226,7 +234,8 @@ class StudySpacePage extends StatelessWidget {
226234
),
227235
Visibility(
228236
visible: studySpace.areas.isNotEmpty,
229-
child: AreasCard(areas: studySpace.areas)),
237+
child: AreasCard(
238+
buildingId: studySpace.id, areas: studySpace.areas)),
230239
Visibility(
231240
visible: studySpace.areas.isNotEmpty,
232241
child: SizedBox(

0 commit comments

Comments
 (0)