Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Lazy Loading #2

Merged
merged 19 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/ui/availability/availability_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@ class _AvailabilityCardState extends State<AvailabilityCard> {
}

Widget buildAvailabilityCard(List<AvailabilityModel?> data) {
List<Widget> locationsList = [];
// Filter the models and create a list of only the valid ones
List<AvailabilityModel> filteredData = data
.where((model) =>
model != null &&
_availabilityDataProvider.locationViewState[model!.name]!)
.cast<AvailabilityModel>()
.toList();

// loop through all the models, adding each one to locationsList
for (AvailabilityModel? model in data) {
if (model != null) {
if (_availabilityDataProvider.locationViewState[model.name]!) {
locationsList.add(AvailabilityDisplay(model: model));
}
}
}

// the user chose no location, so instead show "No Location to Display"
if (locationsList.length == 0) {
// If no location is available, show "No Location to Display"
if (filteredData.isEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
Expand All @@ -80,16 +77,19 @@ class _AvailabilityCardState extends State<AvailabilityCard> {
return Column(
children: <Widget>[
Flexible(
child: PageView(
child: PageView.builder(
controller: _controller,
children: locationsList,
itemCount: filteredData.length,
itemBuilder: (context, index) {
return AvailabilityDisplay(model: filteredData[index]);
},
),
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DotsIndicator(
controller: _controller,
itemCount: locationsList.length,
itemCount: filteredData.length,
onPageSelected: (int index) {
_controller.animateToPage(index,
duration: Duration(seconds: 1), curve: Curves.ease);
Expand Down
100 changes: 49 additions & 51 deletions lib/ui/availability/availability_detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,63 @@ class AvailabilityDetailedView extends StatelessWidget {
}

Widget buildLocationsList(BuildContext context, subLocation) {
// Add a tile for the subLocation name
List<Widget> list = [];
list.add(ListTile(
title: Text(
"${subLocation.name}",
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontSize: 24,
fontWeight: FontWeight.bold),
),
));

// Add a tile for every floor in the subLocation list
for (int i = 0; i < subLocation.floors.length; i++) {
Floor floor = subLocation.floors[i];
list.add(
ListTile(
title: Text(
"${floor.name}",
style: TextStyle(
return ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: subLocation.floors.length + 1, // +1 to include the subLocation name tile
itemBuilder: (context, index) {
if (index == 0) {
// Add the subLocation name as the first ListTile
return ListTile(
title: Text(
"${subLocation.name}",
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontSize: LOCATION_FONT_SIZE),
),
subtitle: Column(
children: <Widget>[
Align(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
);
} else {
// Add tiles for each floor in the subLocation
Floor floor = subLocation.floors[index - 1]; // Adjust index for floors
return ListTile(
title: Text(
"${floor.name}",
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontSize: LOCATION_FONT_SIZE,
),
),
subtitle: Column(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
(100 * percentAvailability(floor)).toInt().toString() +
'% Busy',
// style: TextStyle(color: Colors.black),
)),
Align(
alignment: Alignment.centerLeft,
child: SizedBox(
height: PROGRESS_BAR_HEIGHT,
width: PROGRESS_BAR_WIDTH,
child: ClipRRect(
borderRadius: BorderRadius.circular(BORDER_RADIUS),
child: LinearProgressIndicator(
value: percentAvailability(floor) as double?,
backgroundColor: Colors.grey[BACKGROUND_GREY_SHADE],
valueColor: AlwaysStoppedAnimation<Color>(
setIndicatorColor(
percentAvailability(floor),
(100 * percentAvailability(floor)).toInt().toString() + '% Busy',
),
),
Align(
alignment: Alignment.centerLeft,
child: SizedBox(
height: PROGRESS_BAR_HEIGHT,
width: PROGRESS_BAR_WIDTH,
child: ClipRRect(
borderRadius: BorderRadius.circular(BORDER_RADIUS),
child: LinearProgressIndicator(
value: percentAvailability(floor) as double?,
backgroundColor: Colors.grey[BACKGROUND_GREY_SHADE],
valueColor: AlwaysStoppedAnimation<Color>(
setIndicatorColor(percentAvailability(floor)),
),
),
),
),
),
),
],
),
),
);
}
return ListView(
physics: BouncingScrollPhysics(),
children: list,
],
),
);
}
},
);
}

Expand Down
115 changes: 52 additions & 63 deletions lib/ui/availability/availability_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,66 +41,8 @@ class AvailabilityDisplay extends StatelessWidget {
}

Widget buildAvailabilityBars(BuildContext context) {
List<Widget> locations = [];
// add any children the model contains to the listview
if (model.subLocations!.isNotEmpty) {
for (SubLocations subLocation in model.subLocations!) {
locations.add(
ListTile(
onTap: () => subLocation.floors!.length > 0
? Navigator.pushNamed(
context, RoutePaths.AvailabilityDetailedView,
arguments: subLocation)
: print('_handleIconClick: no subLocations'),
visualDensity: VisualDensity.compact,
trailing: subLocation.floors!.length > 0
? Icon(Icons.arrow_forward_ios_rounded)
: null,
title: Text(
subLocation.name!,
style: TextStyle(
fontSize: LOCATION_FONT_SIZE,
),
),
subtitle: Column(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
(100 * percentAvailability(subLocation))
.toInt()
.toString() +
'% Busy',
// style: TextStyle(color: Colors.black),
)),
Align(
alignment: Alignment.centerLeft,
child: SizedBox(
height: PROGRESS_BAR_HEIGHT,
width: PROGRESS_BAR_WIDTH,
child: ClipRRect(
borderRadius: BorderRadius.circular(BORDER_RADIUS),
child: LinearProgressIndicator(
value: percentAvailability(subLocation) as double?,
backgroundColor: Colors.grey[BACKGROUND_GREY_SHADE],
valueColor: AlwaysStoppedAnimation<Color>(
setIndicatorColor(
percentAvailability(subLocation),
),
),
),
),
),
),
],
),
),
);
}
}

// if no children, return an error container
else {
if (model.subLocations!.isEmpty) {
return Container(
alignment: Alignment.center,
child: Text(
Expand All @@ -112,18 +54,65 @@ class AvailabilityDisplay extends StatelessWidget {
),
);
}
locations =
ListTile.divideTiles(tiles: locations, context: context).toList();

return Flexible(
child: Scrollbar(
child: ListView(
children: locations,
child: ListView.builder(
itemCount: model.subLocations!.length,
itemBuilder: (context, index) {
SubLocations subLocation = model.subLocations![index];
return ListTile(
onTap: () => subLocation.floors!.length > 0
? Navigator.pushNamed(
context, RoutePaths.AvailabilityDetailedView,
arguments: subLocation)
: print('_handleIconClick: no subLocations'),
visualDensity: VisualDensity.compact,
trailing: subLocation.floors!.length > 0
? Icon(Icons.arrow_forward_ios_rounded)
: null,
title: Text(
subLocation.name!,
style: TextStyle(
fontSize: LOCATION_FONT_SIZE,
),
),
subtitle: Column(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text(
(100 * percentAvailability(subLocation)).toInt().toString() +
'% Busy',
),
),
Align(
alignment: Alignment.centerLeft,
child: SizedBox(
height: PROGRESS_BAR_HEIGHT,
width: PROGRESS_BAR_WIDTH,
child: ClipRRect(
borderRadius: BorderRadius.circular(BORDER_RADIUS),
child: LinearProgressIndicator(
value: percentAvailability(subLocation) as double?,
backgroundColor: Colors.grey[BACKGROUND_GREY_SHADE],
valueColor: AlwaysStoppedAnimation<Color>(
setIndicatorColor(percentAvailability(subLocation)),
),
),
),
),
),
],
),
);
},
),
),
);
}


num percentAvailability(SubLocations location) => location.percentage!;

setIndicatorColor(num percentage) {
Expand Down
19 changes: 10 additions & 9 deletions lib/ui/classes/upcoming_classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ class UpcomingCoursesList extends StatelessWidget {

Widget buildListOfCourses(
List<SectionData> data, int? selectedCourse, BuildContext context) {
List<Widget> listOfCourses = List.generate(data.length, (int index) {
return buildTile(index, selectedCourse, data[index], context);
});
return Container(
constraints:
BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.3),
child: ListView(
children: listOfCourses,
shrinkWrap: true,
));
constraints:
BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.3),
child: ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
return buildTile(index, selectedCourse, data[index], context);
},
shrinkWrap: true,
),
);
}

Widget buildTile(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/common/card_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CardContainer extends StatelessWidget {
// web cards are still sized with static values
return Container(
width: double.infinity,
constraints: BoxConstraints(minHeight: cardMinHeight, maxHeight: 340),
constraints: BoxConstraints(minHeight: cardMinHeight, maxHeight: 260),
child: child(),
);
} else if (titleText == "Parking") {
Expand Down
28 changes: 13 additions & 15 deletions lib/ui/dining/dining_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,32 @@ class DiningList extends StatelessWidget {
}

Widget buildDiningList(List<DiningModel> listOfDiners, BuildContext context) {
final List<Widget> diningTiles = [];

/// check to see if we want to display only a limited number of elements
/// if no constraint is given on the size of the list then all elements
/// are rendered
/// are rendered Lazily
var size;
if (listSize == null)
size = listOfDiners.length;
else
size = listSize;
for (int i = 0; i < size; i++) {
final DiningModel item = listOfDiners[i];
final tile = buildDiningTile(item, context);
diningTiles.add(tile);
}

return listSize != null
? ListView(
? ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: ListTile.divideTiles(tiles: diningTiles, context: context)
.toList(),
itemCount: size,
itemBuilder: (context, index) {
final DiningModel item = listOfDiners[index];
return buildDiningTile(item, context);
},
)
: ContainerView(
child: ListView(
children:
ListTile.divideTiles(tiles: diningTiles, context: context)
.toList(),
child: ListView.builder(
itemCount: size,
itemBuilder: (context, index) {
final DiningModel item = listOfDiners[index];
return buildDiningTile(item, context);
},
),
);
}
Expand Down
Loading