Skip to content

Commit 9e680b4

Browse files
committed
Show areas as horizontal carousel in study space page
1 parent 0b31ce8 commit 9e680b4

File tree

1 file changed

+117
-39
lines changed

1 file changed

+117
-39
lines changed

lib/studySpacePage.dart

Lines changed: 117 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import 'MaterialIconsSelected.dart';
55
import 'main.dart';
66
import 'utils.dart';
77

8-
class StudySpacePage extends StatelessWidget {
9-
const StudySpacePage({Key? key, required this.studySpace}) : super(key: key);
8+
class OpeningHourCard extends StatelessWidget {
9+
const OpeningHourCard({Key? key, required this.openingHours})
10+
: super(key: key);
1011

11-
final StudySpace studySpace;
12+
final List<OpeningHours> openingHours;
1213

1314
@override
1415
Widget build(BuildContext context) {
15-
DateTime today = DateTime.now();
1616
List<Widget> hoursList = [];
17-
hoursList.addAll(studySpace.openingHours.mapIndexed((index, hours) {
17+
DateTime today = DateTime.now();
18+
hoursList.addAll(openingHours.mapIndexed((index, hours) {
1819
var day = today.add(Duration(days: index));
1920
return Container(
2021
decoration: BoxDecoration(
@@ -44,6 +45,93 @@ class StudySpacePage extends StatelessWidget {
4445
style: Theme.of(context).textTheme.titleLarge)),
4546
]));
4647
}));
48+
return Card(
49+
margin: EdgeInsets.zero,
50+
child: Padding(
51+
padding: EdgeInsets.all(
52+
Theme.of(context).textTheme.bodyLarge!.fontSize!),
53+
child:
54+
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
55+
Text("Opening Hours",
56+
style: Theme.of(context).textTheme.headlineSmall),
57+
SizedBox(
58+
height:
59+
Theme.of(context).textTheme.headlineSmall!.fontSize! / 2),
60+
ListView.separated(
61+
shrinkWrap: true,
62+
itemCount: hoursList.length,
63+
itemBuilder: (BuildContext context, int index) {
64+
return hoursList[index];
65+
},
66+
separatorBuilder: (context, index) => SizedBox(
67+
height: Theme.of(context).textTheme.bodySmall!.fontSize! / 2,
68+
),
69+
70+
// itemExtent: 100,
71+
)
72+
])));
73+
}
74+
}
75+
76+
class AreasCard extends StatelessWidget {
77+
const AreasCard({Key? key, required this.areas}) : super(key: key);
78+
79+
final List<Area> areas;
80+
81+
@override
82+
Widget build(BuildContext context) {
83+
return Expanded(
84+
child: ListView.separated(
85+
scrollDirection: Axis.horizontal,
86+
itemCount: areas.length,
87+
itemBuilder: (BuildContext context, int index) => Card(
88+
margin: EdgeInsets.zero,
89+
child: Padding(
90+
padding: EdgeInsets.all(
91+
Theme.of(context).textTheme.bodyLarge!.fontSize!),
92+
child: Column(
93+
crossAxisAlignment: CrossAxisAlignment.start,
94+
children: [
95+
Text(
96+
areas[index].title,
97+
style: Theme.of(context).textTheme.titleLarge,
98+
textAlign: TextAlign.left,
99+
),
100+
SizedBox(
101+
height:
102+
Theme.of(context).textTheme.bodyMedium!.fontSize! /
103+
2),
104+
Text(
105+
"Floor: ${areas[index].floor}",
106+
style: Theme.of(context).textTheme.bodyLarge,
107+
),
108+
SizedBox(
109+
height:
110+
Theme.of(context).textTheme.headlineSmall!.fontSize! /
111+
2),
112+
Image.asset(
113+
areas[index].pictureUrl,
114+
width: MediaQuery.of(context).size.width * 0.7,
115+
fit: BoxFit.fitHeight,
116+
),
117+
],
118+
),
119+
)),
120+
separatorBuilder: (context, index) => SizedBox(
121+
width: Theme.of(context).textTheme.bodySmall!.fontSize! / 2,
122+
),
123+
),
124+
);
125+
}
126+
}
127+
128+
class StudySpacePage extends StatelessWidget {
129+
const StudySpacePage({Key? key, required this.studySpace}) : super(key: key);
130+
131+
final StudySpace studySpace;
132+
133+
@override
134+
Widget build(BuildContext context) {
47135
return Scaffold(
48136
appBar: AppBar(
49137
leading: TextButton.icon(
@@ -63,7 +151,8 @@ class StudySpacePage extends StatelessWidget {
63151
padding:
64152
EdgeInsets.all(Theme.of(context).textTheme.bodyLarge!.fontSize!),
65153
child: Column(
66-
crossAxisAlignment: CrossAxisAlignment.center,
154+
crossAxisAlignment: CrossAxisAlignment.stretch,
155+
mainAxisSize: MainAxisSize.min,
67156
children: [
68157
Text(
69158
studySpace.title,
@@ -73,39 +162,28 @@ class StudySpacePage extends StatelessWidget {
73162
SizedBox(
74163
height:
75164
Theme.of(context).textTheme.headlineSmall!.fontSize! / 2),
76-
Card(
77-
child: Padding(
78-
padding: EdgeInsets.all(
79-
Theme.of(context).textTheme.bodyLarge!.fontSize!),
80-
child: Column(
81-
crossAxisAlignment: CrossAxisAlignment.start,
82-
children: [
83-
Text("Opening Hours",
84-
style:
85-
Theme.of(context).textTheme.headlineSmall),
86-
SizedBox(
87-
height: Theme.of(context)
88-
.textTheme
89-
.headlineSmall!
90-
.fontSize! /
91-
2),
92-
ListView.separated(
93-
shrinkWrap: true,
94-
itemCount: hoursList.length,
95-
itemBuilder: (BuildContext context, int index) {
96-
return hoursList[index];
97-
},
98-
separatorBuilder: (context, index) => SizedBox(
99-
height: Theme.of(context)
100-
.textTheme
101-
.bodySmall!
102-
.fontSize! /
103-
2,
104-
),
105-
106-
// itemExtent: 100,
107-
)
108-
]))),
165+
OpeningHourCard(openingHours: studySpace.openingHours),
166+
SizedBox(
167+
height:
168+
Theme.of(context).textTheme.headlineSmall!.fontSize! / 2),
169+
Visibility(
170+
visible: studySpace.areas.isNotEmpty,
171+
child: Text(
172+
"Areas",
173+
style: Theme.of(context).textTheme.headlineSmall,
174+
textAlign: TextAlign.start,
175+
),
176+
),
177+
Visibility(
178+
visible: studySpace.areas.isNotEmpty,
179+
child: SizedBox(
180+
height:
181+
Theme.of(context).textTheme.headlineSmall!.fontSize! /
182+
2),
183+
),
184+
Visibility(
185+
visible: studySpace.areas.isNotEmpty,
186+
child: AreasCard(areas: studySpace.areas)),
109187
],
110188
),
111189
));

0 commit comments

Comments
 (0)