Last active
March 26, 2024 18:24
-
-
Save rodydavis/589d6745648040aa7c0b4a5feb237097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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