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; }