From 7d1f06634626d2405e58b9aa0420930fc1ce28f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Badst=C3=BCbner?= Date: Mon, 17 Jun 2024 23:07:23 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20correct=20usage=20of=20pr?= =?UTF-8?q?ovide=20after=20unmount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ CONTRIBUTING.md | 1 + lib/src/extensions/extensions.dart | 10 ++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edfd4ddb..3838768c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,8 @@ to hide user name in chat. * **Fix**: [182](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/182) Fix send message not working when user start texting after newLine. +* **Fix**: [191](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/191) Fix + error when using `BuildContext` or `State` extensions when not mounted. ## [1.3.1] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1608aad7..a01a3fe7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,3 +6,4 @@ 4. Make sure your code lints. 5. Push your work back up to your fork. 6. Create the pull request! +7. Include the PR in the CHANGELOG.md diff --git a/lib/src/extensions/extensions.dart b/lib/src/extensions/extensions.dart index 99c0a53f..aa5000c4 100644 --- a/lib/src/extensions/extensions.dart +++ b/lib/src/extensions/extensions.dart @@ -129,16 +129,18 @@ extension ChatViewStateTitleExtension on String? { /// Extension on State for accessing inherited widget. extension StatefulWidgetExtension on State { - ChatViewInheritedWidget? get provide => ChatViewInheritedWidget.of(context); + ChatViewInheritedWidget? get provide => + mounted ? ChatViewInheritedWidget.of(context) : null; ReplySuggestionsConfig? get suggestionsConfig => - SuggestionsConfigIW.of(context)?.suggestionsConfig; + mounted ? SuggestionsConfigIW.of(context)?.suggestionsConfig : null; } /// Extension on State for accessing inherited widget. extension BuildContextExtension on BuildContext { - ChatViewInheritedWidget? get provide => ChatViewInheritedWidget.of(this); + ChatViewInheritedWidget? get provide => + mounted ? ChatViewInheritedWidget.of(this) : null; ReplySuggestionsConfig? get suggestionsConfig => - SuggestionsConfigIW.of(this)?.suggestionsConfig; + mounted ? SuggestionsConfigIW.of(this)?.suggestionsConfig : null; }