From 057bad71fe60139b3bc28a7bf5fc8dcc131aa901 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Tue, 4 Oct 2022 04:09:36 +0800 Subject: [PATCH] refactor: check null --- lib/screens/gh_user.dart | 14 +++++++------- lib/utils/utils.dart | 4 ---- lib/widgets/user_item.dart | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/screens/gh_user.dart b/lib/screens/gh_user.dart index 04bb2c2..5bfeeb4 100644 --- a/lib/screens/gh_user.dart +++ b/lib/screens/gh_user.dart @@ -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( @@ -117,7 +117,7 @@ class _User extends StatelessWidget { oneLine: true, ), ), - if (isNotNullOrEmpty(p.location)) + if (p.location != null) AntListItem( prefix: const Icon(Octicons.location), child: Text(p.location!), @@ -125,7 +125,7 @@ class _User extends StatelessWidget { MapsLauncher.launchQuery(p.location!); }, ), - if (isNotNullOrEmpty(p.email)) + if (p.email.isNotEmpty) AntListItem( prefix: const Icon(Octicons.mail), child: Text(p.email), @@ -133,7 +133,7 @@ class _User extends StatelessWidget { launchStringUrl('mailto:${p.email}'); }, ), - if (isNotNullOrEmpty(p.websiteUrl)) + if (p.websiteUrl != null) AntListItem( prefix: const Icon(Octicons.link), child: Text(p.websiteUrl!), @@ -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!), @@ -340,7 +340,7 @@ 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!), @@ -348,7 +348,7 @@ class GhUserScreen extends StatelessWidget { launchStringUrl('mailto:${p.email!}'); }, ), - if (isNotNullOrEmpty(p.websiteUrl)) + if (p.websiteUrl != null) AntListItem( prefix: const Icon(Octicons.link), child: Text(p.websiteUrl!), diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index c5f59ee..9821204 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -108,10 +108,6 @@ List joinAll(T seperator, List> xss) { final numberFormat = NumberFormat(); -bool isNotNullOrEmpty(String? text) { - return text != null && text.isNotEmpty; -} - Future launchStringUrl(String? url) async { if (url == null) return; diff --git a/lib/widgets/user_item.dart b/lib/widgets/user_item.dart index 8ddaf52..20ce69e 100644 --- a/lib/widgets/user_item.dart +++ b/lib/widgets/user_item.dart @@ -18,7 +18,7 @@ class GhBioWidget extends StatelessWidget { @override Widget build(BuildContext context) { - if (isNotNullOrEmpty(location)) { + if (location != null) { return Row( children: [ Icon(