Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Last active March 26, 2024 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodydavis/589d6745648040aa7c0b4a5feb237097 to your computer and use it in GitHub Desktop.
Save rodydavis/589d6745648040aa7c0b4a5feb237097 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
class ChatBubble extends StatelessWidget {
const ChatBubble({
super.key,
this.child,
this.text,
required this.isUser,
});
final Widget? child;
final String? text;
final bool isUser;
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: isUser ? MainAxisAlignment.end : MainAxisAlignment.start,
children: [
Flexible(
child: Container(
constraints: const BoxConstraints(maxWidth: 520),
decoration: BoxDecoration(
color: isUser
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.surfaceVariant,
borderRadius: BorderRadius.circular(18),
),
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 20,
),
margin: const EdgeInsets.only(bottom: 8),
child: Column(children: [
if (text case final text?) MarkdownBody(data: text),
if (child case final child?) child,
],
),
),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment