Skip to content

Commit

Permalink
fix image provider builder (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex authored May 16, 2023
1 parent d134ebf commit a6a0f3d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- **BREAKING CHANGE**: `nameBuilder` now passes the whole user class, instead of just an id. Thanks @vintage for the PR!
- Add typing indicator. See `typingIndicatorOptions`. Thanks @gtalha07 for the PR! Huge one!
- Add `imageProviderBuilder`. Thanks @marinkobabic for the PR!
- Add `autocorrect` and `enableSuggestions` to the `InputOptions`. By default, both values will be true. Thanks @g0dzillaa for the PR!
- Add `keyboardType` to the `InputOptions`. Thanks @Gramatton for the PR!
- Add Swedish localization. Thanks @OlleEkberg for the PR!
Expand Down
17 changes: 9 additions & 8 deletions lib/src/widgets/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,20 @@ class Chat extends StatefulWidget {
/// Headers passed to all network images used in the chat.
final Map<String, String>? imageHeaders;

/// Option to have a custom image provider. This is helpful when user wants to use some caching.
/// or wants to handle image loading manually. Usage of cached_network_image is also possible
/// but when it comes to caching, then consumer want's to decide this specific per message
/// Also using this provider consumer can decide based on url to send specific headers or not
/// See [Message.imageMessageBuilder].
final Widget Function(types.ImageMessage, {required int messageWidth})?
imageMessageBuilder;

/// This feature allows you to use a custom image provider.
/// This is useful if you want to manage image loading yourself, or if you need to cache images.
/// You can also use the `cached_network_image` feature, but when it comes to caching, you might want to decide on a per-message basis.
/// Plus, by using this provider, you can choose whether or not to send specific headers based on the URL.
final ImageProvider Function({
required String uri,
required Map<String, String>? imageHeaders,
required Conditional conditional,
})? imageProviderBuilder;

/// See [Message.imageMessageBuilder].
final Widget Function(types.ImageMessage, {required int messageWidth})?
imageMessageBuilder;

/// See [Input.options].
final InputOptions inputOptions;

Expand Down Expand Up @@ -449,6 +449,7 @@ class ChatState extends State<Chat> {
hideBackgroundOnEmojiMessages: widget.hideBackgroundOnEmojiMessages,
imageHeaders: widget.imageHeaders,
imageMessageBuilder: widget.imageMessageBuilder,
imageProviderBuilder: widget.imageProviderBuilder,
message: message,
messageWidth: messageWidth,
nameBuilder: widget.nameBuilder,
Expand Down
10 changes: 10 additions & 0 deletions lib/src/widgets/message/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import 'package:visibility_detector/visibility_detector.dart';

import '../../conditional/conditional.dart';
import '../../models/bubble_rtl_alignment.dart';
import '../../models/emoji_enlargement_behavior.dart';
import '../../util.dart';
Expand Down Expand Up @@ -31,6 +32,7 @@ class Message extends StatelessWidget {
required this.hideBackgroundOnEmojiMessages,
this.imageHeaders,
this.imageMessageBuilder,
this.imageProviderBuilder,
required this.message,
required this.messageWidth,
this.nameBuilder,
Expand Down Expand Up @@ -104,6 +106,13 @@ class Message extends StatelessWidget {
final Widget Function(types.ImageMessage, {required int messageWidth})?
imageMessageBuilder;

/// See [Chat.imageProviderBuilder].
final ImageProvider Function({
required String uri,
required Map<String, String>? imageHeaders,
required Conditional conditional,
})? imageProviderBuilder;

/// Any message type.
final types.Message message;

Expand Down Expand Up @@ -235,6 +244,7 @@ class Message extends StatelessWidget {
? imageMessageBuilder!(imageMessage, messageWidth: messageWidth)
: ImageMessage(
imageHeaders: imageHeaders,
imageProviderBuilder: imageProviderBuilder,
message: imageMessage,
messageWidth: messageWidth,
);
Expand Down

0 comments on commit a6a0f3d

Please sign in to comment.