Skip to content

Commit

Permalink
refactor: check null
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Oct 3, 2022
1 parent 9b339c6 commit 057bad7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
14 changes: 7 additions & 7 deletions lib/screens/gh_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class _User extends StatelessWidget {
CommonStyle.border,
AntList(
children: [
if (isNotNullOrEmpty(p.company))
if (p.company != null)
AntListItem(
prefix: const Icon(Octicons.organization),
child: TextWithAt(
Expand All @@ -117,23 +117,23 @@ class _User extends StatelessWidget {
oneLine: true,
),
),
if (isNotNullOrEmpty(p.location))
if (p.location != null)
AntListItem(
prefix: const Icon(Octicons.location),
child: Text(p.location!),
onClick: () {
MapsLauncher.launchQuery(p.location!);
},
),
if (isNotNullOrEmpty(p.email))
if (p.email.isNotEmpty)
AntListItem(
prefix: const Icon(Octicons.mail),
child: Text(p.email),
onClick: () {
launchStringUrl('mailto:${p.email}');
},
),
if (isNotNullOrEmpty(p.websiteUrl))
if (p.websiteUrl != null)
AntListItem(
prefix: const Icon(Octicons.link),
child: Text(p.websiteUrl!),
Expand Down Expand Up @@ -331,7 +331,7 @@ class GhUserScreen extends StatelessWidget {
),
AntList(
children: [
if (isNotNullOrEmpty(p.location))
if (p.location != null)
AntListItem(
prefix: const Icon(Octicons.location),
child: Text(p.location!),
Expand All @@ -340,15 +340,15 @@ class GhUserScreen extends StatelessWidget {
'https://www.google.com/maps/place/${p.location!.replaceAll(RegExp(r'\s+'), '')}');
},
),
if (isNotNullOrEmpty(p.email))
if (p.email != null)
AntListItem(
prefix: const Icon(Octicons.mail),
child: Text(p.email!),
onClick: () {
launchStringUrl('mailto:${p.email!}');
},
),
if (isNotNullOrEmpty(p.websiteUrl))
if (p.websiteUrl != null)
AntListItem(
prefix: const Icon(Octicons.link),
child: Text(p.websiteUrl!),
Expand Down
4 changes: 0 additions & 4 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ List<T> joinAll<T>(T seperator, List<List<T>> xss) {

final numberFormat = NumberFormat();

bool isNotNullOrEmpty(String? text) {
return text != null && text.isNotEmpty;
}

Future<void> launchStringUrl(String? url) async {
if (url == null) return;

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/user_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GhBioWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (isNotNullOrEmpty(location)) {
if (location != null) {
return Row(
children: <Widget>[
Icon(
Expand Down

0 comments on commit 057bad7

Please sign in to comment.