Skip to content

Instantly share code, notes, and snippets.

@davidmigloz
Created November 30, 2023 10:45
Show Gist options
  • Save davidmigloz/36a9f3b3afc9bf019905c3588ab0be14 to your computer and use it in GitHub Desktop.
Save davidmigloz/36a9f3b3afc9bf019905c3588ab0be14 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'),
),
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: Column(
children: [
Expanded(
child: ListView(
padding: EdgeInsets.all(16),
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(
margin: EdgeInsets.symmetric(vertical: 4),
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: isSentByMe ? Colors.blue : Colors.grey[200],
borderRadius: BorderRadius.circular(16),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
text,
style: TextStyle(
color: isSentByMe ? Colors.white : Colors.black,
),
),
SizedBox(height: 4),
Text(
time,
style: TextStyle(
color: isSentByMe ? Colors.white70 : Colors.black54,
fontSize: 12,
),
),
],
),
),
);
}
Widget _buildDeletedMessage(String text, String time) {
return Align(
alignment: Alignment.centerRight,
child: Container(
margin: EdgeInsets.symmetric(vertical: 4),
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(16),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
text,
style: TextStyle(
fontStyle: FontStyle.italic,
color: Colors.black54,
),
),
SizedBox(height: 4),
Text(
time,
style: TextStyle(
color: Colors.black54,
fontSize: 12,
),
),
],
),
),
);
}
Widget _buildMessageInput() {
return 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.mic),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.send),
onPressed: () {},
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment