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

Ability to specify time for BubbleSpecialOne #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
87 changes: 70 additions & 17 deletions lib/bubbles/bubble_special_one.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,77 @@ 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);

///chat bubble builder method
@override
Widget build(BuildContext context) {
bool stateTick = false;
Icon? stateIcon;
Widget? stateIcon;
if (sent) {
stateTick = true;
stateIcon = Icon(
Expand All @@ -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(
Expand All @@ -79,23 +132,23 @@ 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),
child: Stack(
children: <Widget>[
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,
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down