-
Notifications
You must be signed in to change notification settings - Fork 100
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
base: experimental
Are you sure you want to change the base?
Performance Enhancements #2089
Changes from all commits
f13f384
1087f7b
ae9de03
93f76e2
6ef2b92
542be64
e8dc7db
87bc706
0fd24ca
e0314ae
0cbe57b
b763805
8f25540
0cfa9e2
476b0d3
22f634f
d31b64f
81d6991
ad3e7f2
a9bdade
84647ec
d88a86f
2ac5e20
ee3e22d
6bee42b
aec972a
f69db57
cef26c6
e59a1ad
038a06e
b39a732
21ea0a4
144ea70
f52041a
bf1657a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
|
@@ -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"; | ||
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) | ||
|
@@ -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 && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -59,7 +51,6 @@ class _EmployeeIdCardState extends State<EmployeeIdCard> { | |
bottom: 32.0, | ||
), | ||
child: Column( | ||
// mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
Center( | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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)), | ||
) | ||
], | ||
), | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -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)), | ||
) | ||
], | ||
), | ||
|
@@ -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; | ||
|
@@ -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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -81,6 +82,7 @@ class FinalsCard extends StatelessWidget { | |
)); | ||
} | ||
}); | ||
|
||
listToReturn = | ||
ListTile.divideTiles(tiles: listToReturn, context: context).toList(); | ||
listToReturn.add( | ||
|
@@ -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) { | ||
|
There was a problem hiding this comment.
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.