Skip to content

Instantly share code, notes, and snippets.

@davidmigloz
Created December 5, 2023 23:04
Show Gist options
  • Save davidmigloz/dde860d46bd22a6502f37d8992e32c4b to your computer and use it in GitHub Desktop.
Save davidmigloz/dde860d46bd22a6502f37d8992e32c4b 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(
useMaterial3: true,
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%20of%20Tyler%20Benil'),
),
SizedBox(width: 8),
Text('Tyler Benil'),
],
),
actions: [
IconButton(
icon: Icon(Icons.videocam),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.call),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.more_vert),
onPressed: () {},
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Expanded(
child: ListView(
children: [
_buildMessage("I'm in a meeting at the moment.\nWon't take more than 20 min.", "11:45", false),
_buildMessage("I’ll Wait near the Skyler coffee shop", "11:50", true),
_buildMessage("Try their hazelnut Mocha. It's the best.", "12:00", false),
_buildMessage("It's 12:20. I’m leaving.", "12:20", true),
_buildMessage("Rachel gave me some paperwork.\nGive me 5 more minutes. Please.", "12:25", false),
_buildDeletedMessage("You deleted this message.", "12:28"),
_buildMessage("Hey, I’m here. where are you?", "12:25", false),
_buildMessage("I’m near the piano wearing red.", "12:30", true),
],
),
),
_buildMessageInput(),
],
),
),
);
}
Widget _buildMessage(String text, String time, bool isSentByMe) {
return Align(
alignment: isSentByMe ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
margin: EdgeInsets.symmetric(vertical: 4),
decoration: BoxDecoration(
color: isSentByMe ? Colors.blue.shade100 : Colors.grey.shade200,
borderRadius: BorderRadius.circular(20),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(text),
SizedBox(height: 4),
Text(
time,
style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
),
],
),
),
);
}
Widget _buildDeletedMessage(String text, String time) {
return Align(
alignment: Alignment.centerLeft,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
margin: EdgeInsets.symmetric(vertical: 4),
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: BorderRadius.circular(20),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
text,
style: TextStyle(color: Colors.grey.shade600),
),
SizedBox(height: 4),
Text(
time,
style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
),
],
),
),
);
}
Widget _buildMessageInput() {
return Row(
children: [
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: Colors.grey.shade200,
borderRadius: BorderRadius.circular(40),
),
child: Row(
children: [
Icon(Icons.emoji_emotions_outlined, color: Colors.grey.shade600),
SizedBox(width: 16),
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: 'Type a message',
border: InputBorder.none,
),
),
),
Icon(Icons.attach_file, color: Colors.grey.shade600),
SizedBox(width: 8),
Icon(Icons.camera_alt, color: Colors.grey.shade600),
],
),
),
),
SizedBox(width: 8),
CircleAvatar(
backgroundColor: Colors.blue,
child: Icon(Icons.mic, color: Colors.white),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment