refactor: check null

This commit is contained in:
Rongjian Zhang 2022-10-04 04:09:36 +08:00
parent 9b339c6cdf
commit 057bad71fe
3 changed files with 8 additions and 12 deletions

View File

@ -106,7 +106,7 @@ class _User extends StatelessWidget {
CommonStyle.border, CommonStyle.border,
AntList( AntList(
children: [ children: [
if (isNotNullOrEmpty(p.company)) if (p.company != null)
AntListItem( AntListItem(
prefix: const Icon(Octicons.organization), prefix: const Icon(Octicons.organization),
child: TextWithAt( child: TextWithAt(
@ -117,7 +117,7 @@ class _User extends StatelessWidget {
oneLine: true, oneLine: true,
), ),
), ),
if (isNotNullOrEmpty(p.location)) if (p.location != null)
AntListItem( AntListItem(
prefix: const Icon(Octicons.location), prefix: const Icon(Octicons.location),
child: Text(p.location!), child: Text(p.location!),
@ -125,7 +125,7 @@ class _User extends StatelessWidget {
MapsLauncher.launchQuery(p.location!); MapsLauncher.launchQuery(p.location!);
}, },
), ),
if (isNotNullOrEmpty(p.email)) if (p.email.isNotEmpty)
AntListItem( AntListItem(
prefix: const Icon(Octicons.mail), prefix: const Icon(Octicons.mail),
child: Text(p.email), child: Text(p.email),
@ -133,7 +133,7 @@ class _User extends StatelessWidget {
launchStringUrl('mailto:${p.email}'); launchStringUrl('mailto:${p.email}');
}, },
), ),
if (isNotNullOrEmpty(p.websiteUrl)) if (p.websiteUrl != null)
AntListItem( AntListItem(
prefix: const Icon(Octicons.link), prefix: const Icon(Octicons.link),
child: Text(p.websiteUrl!), child: Text(p.websiteUrl!),
@ -331,7 +331,7 @@ class GhUserScreen extends StatelessWidget {
), ),
AntList( AntList(
children: [ children: [
if (isNotNullOrEmpty(p.location)) if (p.location != null)
AntListItem( AntListItem(
prefix: const Icon(Octicons.location), prefix: const Icon(Octicons.location),
child: Text(p.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+'), '')}'); 'https://www.google.com/maps/place/${p.location!.replaceAll(RegExp(r'\s+'), '')}');
}, },
), ),
if (isNotNullOrEmpty(p.email)) if (p.email != null)
AntListItem( AntListItem(
prefix: const Icon(Octicons.mail), prefix: const Icon(Octicons.mail),
child: Text(p.email!), child: Text(p.email!),
@ -348,7 +348,7 @@ class GhUserScreen extends StatelessWidget {
launchStringUrl('mailto:${p.email!}'); launchStringUrl('mailto:${p.email!}');
}, },
), ),
if (isNotNullOrEmpty(p.websiteUrl)) if (p.websiteUrl != null)
AntListItem( AntListItem(
prefix: const Icon(Octicons.link), prefix: const Icon(Octicons.link),
child: Text(p.websiteUrl!), child: Text(p.websiteUrl!),

View File

@ -108,10 +108,6 @@ List<T> joinAll<T>(T seperator, List<List<T>> xss) {
final numberFormat = NumberFormat(); final numberFormat = NumberFormat();
bool isNotNullOrEmpty(String? text) {
return text != null && text.isNotEmpty;
}
Future<void> launchStringUrl(String? url) async { Future<void> launchStringUrl(String? url) async {
if (url == null) return; if (url == null) return;

View File

@ -18,7 +18,7 @@ class GhBioWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (isNotNullOrEmpty(location)) { if (location != null) {
return Row( return Row(
children: <Widget>[ children: <Widget>[
Icon( Icon(