Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 🔨 updated config dependencies using inherited widget #215

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/src/extensions/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* SOFTWARE.
*/
import 'package:chatview/chatview.dart';
import 'package:chatview/src/inherited_widgets/configurations_inherited_widgets.dart';
import 'package:chatview/src/widgets/chat_view_inherited_widget.dart';
import 'package:chatview/src/widgets/profile_image_widget.dart';
import 'package:chatview/src/widgets/suggestions/suggestions_config_inherited_widget.dart';
Expand Down Expand Up @@ -129,18 +130,34 @@ extension ChatViewStateTitleExtension on String? {

/// Extension on State for accessing inherited widget.
extension StatefulWidgetExtension on State {
ChatViewInheritedWidget? get provide =>
ChatViewInheritedWidget? get chatViewIW =>
mounted ? ChatViewInheritedWidget.of(context) : null;

ReplySuggestionsConfig? get suggestionsConfig =>
mounted ? SuggestionsConfigIW.of(context)?.suggestionsConfig : null;

ConfigurationsInheritedWidget get chatListConfig =>
mounted && ConfigurationsInheritedWidget.of(context) != null
? ConfigurationsInheritedWidget.of(context)!
: const ConfigurationsInheritedWidget(
chatBackgroundConfig: ChatBackgroundConfiguration(),
child: SizedBox.shrink(),
);
}

/// Extension on State for accessing inherited widget.
extension BuildContextExtension on BuildContext {
ChatViewInheritedWidget? get provide =>
ChatViewInheritedWidget? get chatViewIW =>
mounted ? ChatViewInheritedWidget.of(this) : null;

ReplySuggestionsConfig? get suggestionsConfig =>
mounted ? SuggestionsConfigIW.of(this)?.suggestionsConfig : null;

ConfigurationsInheritedWidget get chatListConfig =>
mounted && ConfigurationsInheritedWidget.of(this) != null
? ConfigurationsInheritedWidget.of(this)!
: const ConfigurationsInheritedWidget(
chatBackgroundConfig: ChatBackgroundConfiguration(),
child: SizedBox.shrink(),
);
}
59 changes: 59 additions & 0 deletions lib/src/inherited_widgets/configurations_inherited_widgets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:chatview/src/models/models.dart';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:flutter/material.dart';

class ConfigurationsInheritedWidget extends InheritedWidget {
const ConfigurationsInheritedWidget({
Key? key,
required Widget child,
required this.chatBackgroundConfig,
this.reactionPopupConfig,
this.messageConfig,
this.chatBubbleConfig,
this.profileCircleConfig,
this.swipeToReplyConfig,
this.repliedMessageConfig,
this.typeIndicatorConfig,
this.replyPopupConfig,
this.emojiPickerSheetConfig,
}) : super(key: key, child: child);

/// Provides configuration for background of chat.
final ChatBackgroundConfiguration chatBackgroundConfig;

/// Provides configuration for reaction pop up appearance.
final ReactionPopupConfiguration? reactionPopupConfig;

/// Provides configuration for customisation of different types
/// messages.
final MessageConfiguration? messageConfig;

/// Provides configuration of chat bubble's appearance.
final ChatBubbleConfiguration? chatBubbleConfig;

/// Provides configuration for profile circle avatar of user.
final ProfileCircleConfiguration? profileCircleConfig;

/// Provides configuration for when user swipe to chat bubble.
final SwipeToReplyConfiguration? swipeToReplyConfig;

/// Provides configuration for replied message view which is located upon chat
/// bubble.
final RepliedMessageConfiguration? repliedMessageConfig;

/// Provides configuration of typing indicator's appearance.
final TypeIndicatorConfiguration? typeIndicatorConfig;

/// Provides configuration for reply snack bar's appearance and options.
final ReplyPopupConfiguration? replyPopupConfig;

/// Configuration for emoji picker sheet
final Config? emojiPickerSheetConfig;

static ConfigurationsInheritedWidget? of(BuildContext context) => context
.dependOnInheritedWidgetOfExactType<ConfigurationsInheritedWidget>();

@override
bool updateShouldNotify(covariant ConfigurationsInheritedWidget oldWidget) =>
oldWidget != this;
}
Loading