Skip to content

Instantly share code, notes, and snippets.

@davidmigloz
Created November 28, 2023 16:41
Show Gist options
  • Save davidmigloz/27649795620d204546c7802bc68bb5fc to your computer and use it in GitHub Desktop.
Save davidmigloz/27649795620d204546c7802bc68bb5fc to your computer and use it in GitHub Desktop.
Generated code from Pixels2Flutter
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Chat UI',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ChatScreen(),
);
}
}
class ChatScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: BackButton(),
title: Row(
children: [
CircleAvatar(
backgroundImage: NetworkImage('https://placehold.co/40x40?description=Profile%20Image'),
),
SizedBox(width: 10),
Text('Tyler Benil'),
],
),
actions: [
IconButton(
icon: Icon(Icons.videocam),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.call),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.more_vert),
onPressed: () {},
),
],
),
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: [
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: 'Type a message',
border: InputBorder.none,
),
),
),
IconButton(
icon: Icon(Icons.send),
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) {
return Align(
alignment: isSender ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
margin: EdgeInsets.symmetric(vertical: 4),
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: isSender ? Colors.blue[100] : Colors.grey[200],
borderRadius: BorderRadius.circular(16),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
text,
style: TextStyle(
color: isDeleted ? Colors.grey : Colors.black,
fontSize: 16,
),
),
SizedBox(height: 8),
Text(
time,
style: TextStyle(
color: Colors.grey,
fontSize: 12,
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment