From f585122f579854fd04c4dda0071a79db58edeeaa Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Sun, 11 Dec 2022 09:18:18 -0800 Subject: [PATCH] Fix NPE Exception in Double Col View During Notification Swtiching --- lib/views/doublecolview.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/views/doublecolview.dart b/lib/views/doublecolview.dart index 60714fcf..3d9ae778 100644 --- a/lib/views/doublecolview.dart +++ b/lib/views/doublecolview.dart @@ -18,6 +18,7 @@ class _DoubleColumnViewState extends State { @override Widget build(BuildContext context) { var flwtch = Provider.of(context); + var selectedConversation = flwtch.selectedConversation; var cols = Provider.of(context).uiColumns(true); return Flex( direction: Axis.horizontal, @@ -30,7 +31,7 @@ class _DoubleColumnViewState extends State { ), Flexible( flex: cols[1], - child: flwtch.selectedConversation == null + child: selectedConversation == null ? Container( color: Provider.of(context).theme.backgroundMainColor, child: Card( @@ -40,9 +41,10 @@ class _DoubleColumnViewState extends State { : //dev MultiProvider(providers: [ ChangeNotifierProvider.value(value: Provider.of(context)), - ChangeNotifierProvider.value( - value: flwtch.selectedConversation != null ? Provider.of(context).contactList.getContact(flwtch.selectedConversation!)! : ContactInfoState("", -1, "")), - ], child: Container(key: Key(flwtch.selectedConversation!.toString()), child: MessageView())), + // there is a potential timing issue here where selectConversation is changes as we move profiles, this will result + // in getContact being null, in that case we replace with an empty Contact Info State + ChangeNotifierProvider.value(value: Provider.of(context).contactList.getContact(selectedConversation) ?? ContactInfoState("", -1, "")), + ], child: Container(key: Key(selectedConversation.toString()), child: MessageView())), ), ], );