diff --git a/example/pubspec.lock b/example/pubspec.lock index f994b6c..92c4d46 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" audioplayers: dependency: "direct dev" description: @@ -230,7 +230,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -265,7 +265,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: diff --git a/lib/bubbles/bubble_special_one.dart b/lib/bubbles/bubble_special_one.dart index a87c8e0..33e0d42 100644 --- a/lib/bubbles/bubble_special_one.dart +++ b/lib/bubbles/bubble_special_one.dart @@ -10,28 +10,69 @@ import 'package:flutter/material.dart'; ///message sender can be changed using [isSender] ///chat bubble [TextStyle] can be customized using [textStyle] -class BubbleSpecialOne extends StatelessWidget { +class BubbleSpecialOne extends FlexibleBubbleSpecialOne { + BubbleSpecialOne({ + bool isSender: true, + required String text, + String? time, + bool tail: true, + Color color: Colors.white70, + bool sent: false, + bool delivered: false, + bool seen: false, + TextStyle textStyle: const TextStyle( + color: Colors.black87, + fontSize: 16, + ), + TextStyle timeTextStyle: const TextStyle( + color: Colors.black87, + fontSize: 10, + ), + }) : super( + isSender: isSender, + widget: Text( + text, + style: textStyle, + textAlign: TextAlign.left, + ), + timeWidget: time != null ? Text( + time, + style: timeTextStyle, + textAlign: TextAlign.right, + ) : null, + tail: tail, + color: color, + sent: sent, + delivered: delivered, + seen: seen, + timeTextStyle: timeTextStyle, + ); +} + +class FlexibleBubbleSpecialOne extends StatelessWidget { final bool isSender; - final String text; + final Widget widget; + final Widget? timeWidget; final bool tail; final Color color; final bool sent; final bool delivered; final bool seen; - final TextStyle textStyle; + final TextStyle timeTextStyle; - const BubbleSpecialOne({ + const FlexibleBubbleSpecialOne({ Key? key, this.isSender = true, - required this.text, + required this.widget, + this.timeWidget, this.color = Colors.white70, this.tail = true, this.sent = false, this.delivered = false, this.seen = false, - this.textStyle = const TextStyle( + this.timeTextStyle = const TextStyle( color: Colors.black87, - fontSize: 16, + fontSize: 10, ), }) : super(key: key); @@ -39,7 +80,7 @@ class BubbleSpecialOne extends StatelessWidget { @override Widget build(BuildContext context) { bool stateTick = false; - Icon? stateIcon; + Widget? stateIcon; if (sent) { stateTick = true; stateIcon = Icon( @@ -65,6 +106,18 @@ class BubbleSpecialOne extends StatelessWidget { ); } + if (timeWidget != null) { + if (stateIcon != null) { + stateIcon = Row(children: [ + timeWidget!, + SizedBox(width: 3), + stateIcon, + ]); + } else { + stateIcon = timeWidget; + } + } + return Align( alignment: isSender ? Alignment.topRight : Alignment.topLeft, child: Padding( @@ -79,7 +132,7 @@ class BubbleSpecialOne extends StatelessWidget { maxWidth: MediaQuery.of(context).size.width * .7, ), margin: isSender - ? stateTick + ? stateTick || timeWidget != null ? EdgeInsets.fromLTRB(7, 7, 14, 7) : EdgeInsets.fromLTRB(7, 7, 17, 7) : EdgeInsets.fromLTRB(17, 7, 7, 7), @@ -87,15 +140,15 @@ class BubbleSpecialOne extends StatelessWidget { children: [ Padding( padding: stateTick - ? EdgeInsets.only(right: 20) - : EdgeInsets.symmetric(vertical: 0, horizontal: 0), - child: Text( - text, - style: textStyle, - textAlign: TextAlign.left, - ), + ? timeWidget != null + ? EdgeInsets.only(right: 50) + : EdgeInsets.only(right: 20) + : timeWidget != null + ? EdgeInsets.only(right: 30) + : EdgeInsets.symmetric(vertical: 0, horizontal: 0), + child: Column(children: [widget]), ), - stateIcon != null && stateTick + stateIcon != null && (stateTick || timeWidget != null) ? Positioned( bottom: 0, right: 0, diff --git a/pubspec.lock b/pubspec.lock index a38f32a..cda6e0d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.6.1" boolean_selector: dependency: transitive description: @@ -99,7 +99,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -134,7 +134,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.3.0" typed_data: dependency: transitive description: