Skip to content

Commit

Permalink
[MOD] Some theming options added for carousel and image (&documented)
Browse files Browse the repository at this point in the history
&some dep. updates.
  • Loading branch information
EnesKaraosman committed Nov 8, 2021
1 parent 8b5c7bb commit 124f3cc
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 90 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.0

* Some new theming options added & Carousel UI updated a bit.
* Internal dependency packages updated.

## 1.0.0

* Initial version, see what this package can do for you in [README.md](README.md)
31 changes: 26 additions & 5 deletions Theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@

### Theming

Visit the helper `ChatTheme` [abstract class](lib/src/theme/chat_theme.dart) in example folder.
Visit `ChatTheme` [abstract class file](lib/src/theme/chat_theme.dart).

* scaffoldBackgroundColor: main background color
* cardTheme: text container background color
* textTheme: text theme for messages (MessageKind.text)
* outlinedButtonTheme: quick reply button theme (MessageKind.quickReply)
* `Color primaryColor`: Used as a background of outgoing messages
* `Color secondaryColor`: Used as a background of incoming messages
* `EdgeInsets messageInset` Can be used to have padding between messages
* `Color backgroundColor`: Used as a background color of a chat widget

#### Text Message Widget
* `double textMessagePadding`
* `TextStyle incomingMessageBodyTextStyle`
* `TextStyle outgoingMessageBodyTextStyle`

#### Carousel Message Widget
* `BoxDecoration carouselBoxDecoration`
* `TextStyle carouselTitleTextStyle`
* `TextStyle carouselSubtitleTextStyle`
* `ButtonStyle carouselButtonStyle`

#### Image Message Widget
* `BorderRadius imageBorderRadius`

#### Quick Reply Message Widget
* `ButtonStyle quickReplyButtonStyle`

#### HTML Message Widget
* `Color htmlTextColor`: Color on p, h1, h2, h3, h4, h5 elements.
* `String? htmlTextFontFamily`: FontFamily on p, h1, h2, h3, h4, h5 elements.
61 changes: 0 additions & 61 deletions example/lib/theme/app_theme.dart

This file was deleted.

2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "1.0.4"
swifty_chat_data:
dependency: transitive
description:
Expand Down
32 changes: 17 additions & 15 deletions lib/src/chat-message-list-items/carousel_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,29 @@ class CarouselWidget extends StatelessWidget with HasAvatar {
Message get message => chatMessage;

@override
Widget build(BuildContext context) =>
CarouselSlider.builder(
Widget build(BuildContext context) => CarouselSlider.builder(
itemCount: items.length,
itemBuilder: (context, index, _) => _carouselItem(context, items[index]),
itemBuilder: (context, index, _) =>
_carouselItem(context, items[index]),
options: CarouselOptions(
height: _carouselItemHeight(context),
disableCenter: true,
enableInfiniteScroll: false,
),
);

Widget _carouselItem(BuildContext context, CarouselItem item) =>
Container(
color: context.theme.secondaryColor,
Widget _carouselItem(BuildContext context, CarouselItem item) => Container(
decoration: context.theme.carouselBoxDecoration,
margin: const EdgeInsets.symmetric(horizontal: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (item.imageProvider != null)
Image(
image: item.imageProvider!,
).flexible(),
Flexible(
child: Image(
image: item.imageProvider!,
),
),
Text(
item.title,
style: context.theme.carouselTitleTextStyle,
Expand All @@ -52,22 +54,22 @@ class CarouselWidget extends StatelessWidget with HasAvatar {
Wrap(
children: item.buttons
.map(
(button) =>
ElevatedButton(
onPressed: () => ChatStateContainer.of(context).onCarouselButtonItemPressed?.call(button),
(button) => ElevatedButton(
onPressed: () => ChatStateContainer.of(context)
.onCarouselButtonItemPressed
?.call(button),
style: context.theme.carouselButtonStyle,
child: Text(button.title),
),
)
)
.toList(),
).padding(all: 8),
],
),
);

double _carouselItemHeight(BuildContext context) {
final height = ChatStateContainer
.of(context)
final height = ChatStateContainer.of(context)
.messageCellSizeConfigurator
.carouselCellMaxHeightConfiguration(context.mq.size.height);
return height;
Expand Down
10 changes: 7 additions & 3 deletions lib/src/chat-message-list-items/image_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:swifty_chat_data/swifty_chat_data.dart';

import '../chat.dart';
import '../extensions/theme_context.dart';
import '../protocols/has_avatar.dart';
import '../protocols/incoming_outgoing_message_widgets.dart';

Expand Down Expand Up @@ -31,9 +32,12 @@ class ImageMessageWidget extends StatelessWidget
],
);

Widget imageContainer(BuildContext context) => Image(
width: _imageWidth(context),
image: message.messageKind.imageProvider!,
Widget imageContainer(BuildContext context) => ClipRRect(
borderRadius: context.theme.imageBorderRadius,
child: Image(
width: _imageWidth(context),
image: message.messageKind.imageProvider!
),
);

@override
Expand Down
7 changes: 7 additions & 0 deletions lib/src/theme/chat_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ abstract class ChatTheme {
/// of sent messages
TextStyle get outgoingMessageBodyTextStyle;

// Image Message Styles
/// Image borderRadius
BorderRadius get imageBorderRadius;

// Carousel Message Styles
/// Carousel container decoration
BoxDecoration get carouselBoxDecoration;

/// Title text style used for displaying text on Carousel widget
TextStyle get carouselTitleTextStyle;

Expand Down
18 changes: 18 additions & 0 deletions lib/src/theme/default_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ class DefaultChatTheme extends ChatTheme {
@override
ButtonStyle get carouselButtonStyle => const ButtonStyle();

@override
BoxDecoration get carouselBoxDecoration => BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: secondaryColor,
);

@override
BorderRadius get imageBorderRadius => BorderRadius.circular(16);

@override
ButtonStyle get quickReplyButtonStyle => ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(neutral2),
Expand Down Expand Up @@ -135,6 +144,15 @@ class DarkChatTheme extends ChatTheme {
@override
ButtonStyle get carouselButtonStyle => const ButtonStyle();

@override
BoxDecoration get carouselBoxDecoration => BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: primaryColor,
);

@override
BorderRadius get imageBorderRadius => BorderRadius.circular(16);

@override
ButtonStyle get quickReplyButtonStyle => ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(secondaryDark),
Expand Down
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: swifty_chat
description: >-
A Flutter package to quickly get started building Chat UIs
with different kind of message kinds.
version: 1.0.3
version: 1.1.0
homepage: https://github.com/EnesKaraosman/swifty_chat
repository: https://github.com/EnesKaraosman/swifty_chat

Expand All @@ -12,17 +12,17 @@ environment:

dependencies:
carousel_slider: ^4.0.0
dart_extensions: ^2.1.3
dart_extensions: ^2.2.0
flutter:
sdk: flutter

flutter_html: ^2.1.2
styled_widget: ^0.4.0
flutter_html: ^2.1.5
styled_widget: ^0.4.0+3

swifty_chat_data: ^0.0.1

dev_dependencies:
flutter_lints: ^1.0.0
flutter_lints: ^1.0.4

flutter_test:
sdk: flutter
Expand Down

0 comments on commit 124f3cc

Please sign in to comment.