Skip to content

Instantly share code, notes, and snippets.

@davidmigloz
Created November 30, 2023 10:52
Show Gist options
  • Save davidmigloz/9c548f6d3d1c47285269b41ae3351135 to your computer and use it in GitHub Desktop.
Save davidmigloz/9c548f6d3d1c47285269b41ae3351135 to your computer and use it in GitHub Desktop.
Generated code from pixels2flutter.dev
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: ChatScreen(),
);
}
}
class ChatScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
title: Row(
children: [
CircleAvatar(
backgroundImage: NetworkImage('https://placehold.co/40x40?description=Profile%20Image'),
),
SizedBox(width: 8),
Text('Tyler Benil'),
],
),
actions: [
IconButton(
icon: Icon(Icons.videocam, color: Colors.white),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.call, color: Colors.white),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.more_vert, color: Colors.white),
onPressed: () {},
),
],
backgroundColor: Colors.blue,
),
body: Column(
children: [
Expanded(
child: ListView(
padding: EdgeInsets.all(16),
children: [
ChatBubble(
text: "I'm in a meeting at the moment.\nWon't take more than 20 min.",
time: "11:45",
isSender: false,
),
ChatBubble(
text: "I'll Wait near the Skyler coffee shop",
time: "11:50",
isSender: true,
),
ChatBubble(
text: "Try their hazelnut Mocha. It's the best.",
time: "12:00",
isSender: false,
),
ChatBubble(
text: "It's 12:20. I'm leaving.",
time: "12:20",
isSender: true,
),
ChatBubble(
text: "Rachel gave me some paperwork.\nGive me 5 more minutes. Please.",
time: "12:25",
isSender: false,
),
ChatBubble(
text: "You deleted this message.",
time: "12:28",
isSender: true,
isDeleted: true,
),
ChatBubble(
text: "Hey, I’m here. where are you?",
time: "12:25",
isSender: false,
),
ChatBubble(
text: "I'm near the piano wearing red.",
time: "12:30",
isSender: true,
),
],
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: Colors.white,
child: Row(
children: [
IconButton(
icon: Icon(Icons.mic, color: Colors.blue),
onPressed: () {},
),
Expanded(
child: TextField(
decoration: InputDecoration.collapsed(
hintText: 'Type a message',
),
),
),
IconButton(
icon: Icon(Icons.send, color: Colors.blue),
onPressed: () {},
),
],
),
),
],
),
);
}
}
class ChatBubble extends StatelessWidget {
final String text;
final String time;
final bool isSender;
final bool isDeleted;
const ChatBubble({
Key? key,
required this.text,
required this.time,
this.isSender = false,
this.isDeleted = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final borderRadius = BorderRadius.circular(16);
final alignment = isSender ? CrossAxisAlignment.end : CrossAxisAlignment.start;
final color = isSender ? Colors.blue : Colors.grey.shade200;
final textColor = isDeleted ? Colors.black54 : Colors.black87;
return Column(
crossAxisAlignment: alignment,
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
margin: EdgeInsets.only(bottom: 8),
decoration: BoxDecoration(
color: color,
borderRadius: isSender
? borderRadius.subtract(BorderRadius.only(bottomRight: Radius.circular(16)))
: borderRadius.subtract(BorderRadius.only(bottomLeft: Radius.circular(16))),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text,
style: TextStyle(color: textColor),
),
SizedBox(height: 8),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
time,
style: TextStyle(color: textColor, fontSize: 12),
),
if (isSender) ...[
SizedBox(width: 4),
Icon(Icons.check, size: 16, color: textColor),
],
],
),
],
),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment