Skip to content

Commit 08da145

Browse files
jonasbadstuebneraditya-css
authored andcommitted
fix: 🐛 correct usage of provide after unmount
1 parent b982ec5 commit 08da145

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
to hide user name in chat.
4949
* **Fix**: [182](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/issues/182) Fix
5050
send message not working when user start texting after newLine.
51+
* **Fix**: [191](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/191) Fix
52+
error when using `BuildContext` or `State` extensions when not mounted.
5153

5254
## [1.3.1]
5355

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
4. Make sure your code lints.
77
5. Push your work back up to your fork.
88
6. Create the pull request!
9+
7. Include the PR in the CHANGELOG.md

lib/src/extensions/extensions.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,18 @@ extension ChatViewStateTitleExtension on String? {
129129

130130
/// Extension on State for accessing inherited widget.
131131
extension StatefulWidgetExtension on State {
132-
ChatViewInheritedWidget? get provide => ChatViewInheritedWidget.of(context);
132+
ChatViewInheritedWidget? get provide =>
133+
mounted ? ChatViewInheritedWidget.of(context) : null;
133134

134135
ReplySuggestionsConfig? get suggestionsConfig =>
135-
SuggestionsConfigIW.of(context)?.suggestionsConfig;
136+
mounted ? SuggestionsConfigIW.of(context)?.suggestionsConfig : null;
136137
}
137138

138139
/// Extension on State for accessing inherited widget.
139140
extension BuildContextExtension on BuildContext {
140-
ChatViewInheritedWidget? get provide => ChatViewInheritedWidget.of(this);
141+
ChatViewInheritedWidget? get provide =>
142+
mounted ? ChatViewInheritedWidget.of(this) : null;
141143

142144
ReplySuggestionsConfig? get suggestionsConfig =>
143-
SuggestionsConfigIW.of(this)?.suggestionsConfig;
145+
mounted ? SuggestionsConfigIW.of(this)?.suggestionsConfig : null;
144146
}

0 commit comments

Comments
 (0)