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

Performance Enhancements #2089

Open
wants to merge 35 commits into
base: experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f13f384
implemented cached network image
klortiz13 Sep 14, 2024
1087f7b
finished implementing imagecacheloading
klortiz13 Sep 20, 2024
ae9de03
fixed some small ui
klortiz13 Sep 20, 2024
93f76e2
cached the image of events, scanner, and myCHart
klortiz13 Sep 20, 2024
6ef2b92
Merge pull request #1 from parthshindee/kristhian-cached-image-packag…
parthshindee Sep 20, 2024
542be64
implemented ListView.builder in the media card. Also removed unused v…
klortiz13 Sep 21, 2024
e8dc7db
implemented listview builder in weather card
klortiz13 Sep 21, 2024
87bc706
implemented cachedNetworkImage to weather card
klortiz13 Sep 21, 2024
0fd24ca
implemented cache image to student id
klortiz13 Sep 21, 2024
e0314ae
implemented pageView.builder in shuttle card
klortiz13 Sep 21, 2024
0cbe57b
implemented pageVIew.builder in parking card
klortiz13 Sep 21, 2024
b763805
implemented cached image to notices card
klortiz13 Sep 21, 2024
8f25540
implemented listview builder to the news card and imageLoader to the …
klortiz13 Sep 22, 2024
0cfa9e2
fixed employee_id card and finals card
klortiz13 Sep 22, 2024
476b0d3
resized shuttle card
klortiz13 Sep 22, 2024
22f634f
implemented lazy loading in dinning card
klortiz13 Sep 22, 2024
d31b64f
fixed loading indicator in student id
klortiz13 Sep 22, 2024
81d6991
fixed loading indicator in wheather card
klortiz13 Sep 22, 2024
ad3e7f2
fixed media card
klortiz13 Sep 22, 2024
a9bdade
implemented listview builder in classes card
klortiz13 Sep 22, 2024
84647ec
implemented list view builder in availability display .dart
klortiz13 Sep 22, 2024
d88a86f
refactored availability detail view to implement listview builder
klortiz13 Sep 22, 2024
2ac5e20
implemented pageview builder in availability card
klortiz13 Sep 22, 2024
ee3e22d
Merge pull request #2 from parthshindee/kristhian-lazy-loading
klortiz13 Sep 22, 2024
6bee42b
converted student_id_card into a stateless widget card
klortiz13 Sep 22, 2024
aec972a
converted employee id to stateless
klortiz13 Sep 22, 2024
f69db57
fixed typo in student id card
klortiz13 Sep 22, 2024
cef26c6
Merge pull request #3 from parthshindee/kristhian-stateless-conversion
klortiz13 Sep 29, 2024
e59a1ad
merged with upstream
klortiz13 Sep 29, 2024
038a06e
updated
parthshindee Oct 14, 2024
b39a732
updated
parthshindee Oct 14, 2024
21ea0a4
Merge remote-tracking branch 'origin/experimental' into experimental
parthshindee Oct 14, 2024
144ea70
updated
parthshindee Nov 7, 2024
f52041a
updated pubspeck
parthshindee Dec 15, 2024
bf1657a
pulled from upstream
parthshindee Dec 15, 2024
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
2 changes: 1 addition & 1 deletion lib/ui/common/card_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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
61 changes: 26 additions & 35 deletions lib/ui/employee_id/employee_id_card.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:barcode_widget/barcode_widget.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:campus_mobile_experimental/app_constants.dart';
import 'package:campus_mobile_experimental/app_styles.dart';
import 'package:campus_mobile_experimental/core/models/employee_id.dart';
Expand All @@ -8,30 +9,18 @@ import 'package:campus_mobile_experimental/core/utils/webview.dart';
import 'package:campus_mobile_experimental/ui/common/card_container.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:provider/provider.dart';

class EmployeeIdCard extends StatefulWidget {
@override
_EmployeeIdCardState createState() => _EmployeeIdCardState();
}

class _EmployeeIdCardState extends State<EmployeeIdCard> {
String cardId = "employee_id";
final placeholderPhotoUrl = dotenv.get('PLACEHOLDER_PERSON_PHOTO');
bool isValidId = false;
class EmployeeIdCard extends StatelessWidget {
final String cardId = "employee_id";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-evaluate if this and others like it can be made into const variables.

final String placeholderPhotoUrl =
"https://mobile.ucsd.edu/replatform/v1/qa/webview/resources/img/placeholderPerson.png";

@override
Widget build(BuildContext context) {
ScalingUtility().getCurrentMeasurements(context);

EmployeeIdModel? employeeModel =
Provider.of<EmployeeIdDataProvider>(context).employeeIdModel;
isValidId = employeeModel != null &&
(employeeModel.barcode != null) &&
(employeeModel.employeePreferredDisplayName != null &&
employeeModel.employeeId != null);

return CardContainer(
active: Provider.of<CardsDataProvider>(context).cardStates[cardId],
hide: () => Provider.of<CardsDataProvider>(context, listen: false)
Expand All @@ -41,7 +30,10 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
isLoading: Provider.of<EmployeeIdDataProvider>(context).isLoading,
titleText: CardTitleConstants.titleMap[cardId]!,
errorText: Provider.of<EmployeeIdDataProvider>(context).error,
child: () => isValidId
child: () => (employeeModel != null &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting this into a static private method unless it is only used in this function just once.

(employeeModel.barcode != null) &&
(employeeModel.employeePreferredDisplayName != null &&
employeeModel.employeeId != null))
? buildCardContent(
Provider.of<EmployeeIdDataProvider>(context).employeeIdModel,
context)
Expand All @@ -59,7 +51,6 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
bottom: 32.0,
),
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
Expand Down Expand Up @@ -103,8 +94,8 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
left: cardMargin * 1.5, right: cardMargin * 1.5)),
Column(
children: <Widget>[
Image.network(
employeeIdModel!.photo.contains("https")
CachedNetworkImage(
imageUrl: employeeIdModel!.photo.contains("https")
? employeeIdModel.photo
: placeholderPhotoUrl,
fit: BoxFit.contain,
Expand Down Expand Up @@ -240,8 +231,8 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
Container(
child: Column(
children: <Widget>[
Image.network(
employeeIdModel!.photo.contains("https")
CachedNetworkImage(
imageUrl: employeeIdModel!.photo.contains("https")
? employeeIdModel.photo
: placeholderPhotoUrl,
fit: BoxFit.contain,
Expand All @@ -266,7 +257,7 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
employeeIdModel.employeePreferredDisplayName,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: tabletFontSize(
fontSize: tabletFontSize(context,
employeeIdModel.employeePreferredDisplayName,
"name")),
textAlign: TextAlign.left,
Expand All @@ -283,7 +274,7 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
style: TextStyle(
color: Colors.grey,
fontSize:
tabletFontSize(employeeIdModel.department, "")),
tabletFontSize(context, employeeIdModel.department, "")),
textAlign: TextAlign.left,
softWrap: false,
maxLines: 1,
Expand All @@ -295,7 +286,7 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
child: Text(
"Employee ID " + employeeIdModel.employeeId,
style: TextStyle(
fontSize: tabletFontSize(
fontSize: tabletFontSize(context,
"Employee ID " + employeeIdModel.employeeId, "")),
textAlign: TextAlign.left,
softWrap: false,
Expand Down Expand Up @@ -443,8 +434,8 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
cardNumber,
style: TextStyle(
color: Colors.black,
fontSize: fontSizeForTablet(),
letterSpacing: letterSpacingForTablet()),
fontSize: fontSizeForTablet(context),
letterSpacing: letterSpacingForTablet(context)),
)
],
),
Expand Down Expand Up @@ -472,14 +463,14 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
}
}

double letterSpacingForTablet() {
double letterSpacingForTablet(BuildContext context) {
if (MediaQuery.of(context).orientation == Orientation.landscape) {
return ScalingUtility.horizontalSafeBlock * 1;
}
return ScalingUtility.horizontalSafeBlock * 3;
}

double fontSizeForTablet() {
double fontSizeForTablet(BuildContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions that use BuildContext do not need to pass it as a parameter. Use the context instance variable from the class itself.

if (MediaQuery.of(context).orientation == Orientation.landscape) {
return ScalingUtility.horizontalSafeBlock * 2;
}
Expand Down Expand Up @@ -539,8 +530,8 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
cardNumber,
style: TextStyle(
color: Colors.black,
fontSize: getRotatedPopUpFontSize(),
letterSpacing: letterSpacing()),
fontSize: getRotatedPopUpFontSize(context),
letterSpacing: letterSpacing(context)),
)
],
),
Expand Down Expand Up @@ -574,12 +565,12 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
}
}

double letterSpacing() =>
double letterSpacing(BuildContext context) =>
MediaQuery.of(context).orientation == Orientation.landscape
? SizeConfig.safeBlockHorizontal * 1
: SizeConfig.safeBlockHorizontal * 3;

double getRotatedPopUpFontSize() =>
double getRotatedPopUpFontSize(BuildContext context) =>
MediaQuery.of(context).orientation == Orientation.landscape
? SizeConfig.safeBlockHorizontal * 2
: SizeConfig.safeBlockHorizontal * 4;
Expand All @@ -603,9 +594,9 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> {
return base;
}

double tabletFontSize(String input, String textField) {
double tabletFontSize(BuildContext context, String input, String textField) {
/// Base font size
double base = letterSpacingForTablet();
double base = letterSpacingForTablet(context);

/// If threshold is passed, shrink text
// if (input.length >= 21) {
Expand Down
25 changes: 11 additions & 14 deletions lib/ui/events/event_tile.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:campus_mobile_experimental/app_constants.dart';
import 'package:campus_mobile_experimental/core/models/events.dart';
import 'package:campus_mobile_experimental/core/providers/events.dart';
Expand All @@ -23,7 +24,7 @@ class EventTile extends StatelessWidget
Widget buildEventTile(BuildContext context) {
return Container(
width: tileWidth,
height: 300,
height: 285,
margin: EdgeInsets.zero,
child: InkWell(
onTap: () {
Expand Down Expand Up @@ -79,28 +80,24 @@ class EventTile extends StatelessWidget
? Container(
child: Image(
image: AssetImage('assets/images/UCSDMobile_sharp.png'),
height: 150,
height: 125,
width: tileWidth,
fit: BoxFit.fill,
))
: Image.network(
url,
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
: CachedNetworkImage(
imageUrl: url,
height: 125,
width: tileWidth,
fit: BoxFit.fill,
progressIndicatorBuilder: (context, url, downloadProgress) {
return Center(
child: CircularProgressIndicator(
color: Theme.of(context).colorScheme.secondary,
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
value: downloadProgress.progress,
),
);
},
fit: BoxFit.fill,
height: 150,
width: tileWidth,
errorWidget: (context, url, error) => Icon(Icons.error),
);
}

Expand Down
4 changes: 0 additions & 4 deletions lib/ui/events/events_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,5 @@ class EventsList extends StatelessWidget {
: EventsAll(),
);
}
// ListView(
// children:
// ListTile.divideTiles(tiles: eventTiles, context: context)
// .toList(),
}
}
4 changes: 1 addition & 3 deletions lib/ui/events/events_view_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ class EventsAll extends StatelessWidget {
if (listOfEvents.length > 0) {
return GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 1,
mainAxisSpacing: 8,
children: eventTiles,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 1.4),
(MediaQuery.of(context).size.height / 1.6),
);
} else {
return ContainerView(
Expand Down
10 changes: 8 additions & 2 deletions lib/ui/finals/finals_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class FinalsCard extends StatelessWidget {
Widget buildFinalsCard(Map<String, List<SectionData>> finalsData,
DateTime lastUpdated, String? nextDayWithClasses, BuildContext context) {
try {
// Flatten the data into a single list of ListTile widgets
List<Widget> listToReturn = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be converted into functional-style methods.

finalsData.forEach((key, value) {
for (SectionData data in value) {
Expand All @@ -81,6 +82,7 @@ class FinalsCard extends StatelessWidget {
));
}
});

listToReturn =
ListTile.divideTiles(tiles: listToReturn, context: context).toList();
listToReturn.add(
Expand All @@ -89,9 +91,13 @@ class FinalsCard extends StatelessWidget {
child: LastUpdatedWidget(time: lastUpdated),
),
);
return ListView(

return ListView.builder(
physics: NeverScrollableScrollPhysics(),
children: listToReturn,
itemCount: listToReturn.length,
itemBuilder: (context, index) {
return listToReturn[index];
},
shrinkWrap: true,
);
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions lib/ui/mystudentchart/mystudentchart_card.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:campus_mobile_experimental/app_constants.dart';
import 'package:campus_mobile_experimental/core/providers/cards.dart';
import 'package:campus_mobile_experimental/ui/common/card_container.dart';
Expand Down
7 changes: 5 additions & 2 deletions lib/ui/parking/parking_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ class _ParkingCardState extends State<ParkingCard> {
return Column(
children: <Widget>[
Expanded(
child: PageView(
child: PageView.builder(
controller: _controller,
children: selectedLotsViews,
itemCount: selectedLotsViews.length,
itemBuilder: (context, index) {
return selectedLotsViews[index];
},
),
),
DotsIndicator(
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/scanner/native_scanner_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class NativeScannerCard extends StatelessWidget
child: Row(
children: <Widget>[
Container(
child: Image.asset(
'assets/images/QRScanIcon.png',
child: Image(
image: AssetImage('assets/images/QRScanIcon.png'),
fit: BoxFit.contain,
height: 56,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/shuttle/shuttle_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ShuttleDisplay extends StatelessWidget {

Widget whetherNextArrivals() {
if (arrivingShuttles!.length <= 1) {
return Text("");
return Text("No future arrivals.");
} else {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
Expand Down
6 changes: 2 additions & 4 deletions lib/ui/wifi/wifi_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:campus_mobile_experimental/app_constants.dart';
import 'package:campus_mobile_experimental/app_styles.dart';
import 'package:campus_mobile_experimental/core/providers/cards.dart';
import 'package:campus_mobile_experimental/core/providers/speed_test.dart';
import 'package:campus_mobile_experimental/core/providers/user.dart';
import 'package:campus_mobile_experimental/ui/common/card_container.dart';
import 'package:flutter/material.dart';
import 'package:liquid_progress_indicator_v2/liquid_progress_indicator.dart';
Expand All @@ -23,7 +22,6 @@ class _WiFiCardState extends State<WiFiCard> with AutomaticKeepAliveClientMixin
late bool goodSpeed;
bool timedOut = false;
SpeedTestProvider _speedTestProvider = SpeedTestProvider();
UserDataProvider? _userDataProvider;
bool _buttonEnabled = true;
Timer? buttonTimer;
static const int SPEED_TEST_TIMEOUT_CONST = 30;
Expand Down Expand Up @@ -502,7 +500,7 @@ class _WiFiCardState extends State<WiFiCard> with AutomaticKeepAliveClientMixin
child: Text(
"Connect to a UCSD Network",
style: TextStyle(
fontSize: 25,
fontSize: 22,
),
textAlign: TextAlign.center,
),
Expand All @@ -511,7 +509,7 @@ class _WiFiCardState extends State<WiFiCard> with AutomaticKeepAliveClientMixin
padding: EdgeInsets.all(4.0),
elevation: 0.0,
onPressed: () => tryAgain(),
minWidth: 350,
minWidth: 300,
height: 40,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
Expand Down