Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 121 additions & 89 deletions lib/screens/HomePage.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: file_names

import 'package:flutter/material.dart';
import 'package:test_app/screens/ChatPage.dart';

Expand All @@ -19,142 +17,176 @@ class _HomePageState extends State<HomePage> {
"Payment",
"Settings"
];
List chats = [
List<Map<String, dynamic>> chats = [
{
"name": "Ram",
"Message": "I have reached Lanka",
"time": "11:11",
"readStatus": true,
"sent": false
"sent": false,
"pinned": false
},
{
"name": "Lakshman",
"Message": "Bhrata, mujhe aadesh dein, sabko mai akele maar dunga!",
"time": "11:11",
"readStatus": true,
"sent": false
"sent": false,
"pinned": false
},
{
"name": "Bharat",
"Message": "Kila fateh karke aaiye! Rajya aapka intezar kar raha hai!",
"time": "11:15",
"readStatus": true,
"sent": false
"sent": false,
"pinned": false
},
{
"name": "Shatrughna",
"Message": "ALl the best bhrata shree!",
"Message": "All the best bhrata shree!",
"time": "11:12",
"readStatus": true,
"sent": false
"sent": false,
"pinned": false
},
{
"name": "Hanuman",
"Message": "Jai Shree Ram. On your command, my lord!",
"time": "11:11",
"readStatus": true,
"sent": false
"sent": false,
"pinned": false
},
{
"name": "Sita",
"Message": "I am waiting, Come soon!",
"time": "11:11",
"readStatus": true,
"sent": false
"sent": false,
"pinned": false
},
{
"name": "Dashrath",
"Message": "All the best!",
"time": "11:20",
"readStatus": true,
"sent": true
"sent": true,
"pinned": false
},
];

void togglePin(int index) {
setState(() {
chats[index]['pinned'] = !chats[index]['pinned'];
chats.sort((a, b) {
if (a['pinned'] && !b['pinned']) {
return -1;
} else if (!a['pinned'] && b['pinned']) {
return 1;
}
return 0;
});
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("What's UP"),
Row(
children: [
Icon(Icons.search),
PopupMenuButton<String>(
onSelected: (value) => {print(value)},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
PopupMenuItem(
value: "New Group",
child: Text("New Group"),
),
PopupMenuItem(
value: "New Broadcast",
child: Text("New Broadcast"),
),
PopupMenuItem(
value: "Linked devices",
child: Text("Linked devices"),
),
PopupMenuItem(
value: "Starred message",
child: Text("Starred message"),
),
PopupMenuItem(
value: "Payment",
child: Text("Payment"),
),
PopupMenuItem(
value: "Settings",
child: Text("Settings"),
),
])
],
),
],
),
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("What's UP"),
Row(
children: [
Icon(Icons.search),
PopupMenuButton<String>(
onSelected: (value) => {print(value)},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
PopupMenuItem(
value: "New Group",
child: Text("New Group"),
),
PopupMenuItem(
value: "New Broadcast",
child: Text("New Broadcast"),
),
PopupMenuItem(
value: "Linked devices",
child: Text("Linked devices"),
),
PopupMenuItem(
value: "Starred message",
child: Text("Starred message"),
),
PopupMenuItem(
value: "Payment",
child: Text("Payment"),
),
PopupMenuItem(
value: "Settings",
child: Text("Settings"),
),
],
)
],
),
],
),
body: ListView.builder(
itemCount: chats.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(chats[index]["name"]),
subtitle: chats[index]["sent"]
? Row(
children: [
const Icon(Icons.done_all),
Text(
chats[index]["Message"],
style: const TextStyle(
overflow: TextOverflow.ellipsis),
),
],
)
: Text(
),
body: ListView.builder(
itemCount: chats.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(chats[index]["name"]),
subtitle: chats[index]["sent"]
? Row(
children: [
const Icon(Icons.done_all),
Text(
chats[index]["Message"],
style: const TextStyle(overflow: TextOverflow.ellipsis),
style: const TextStyle(
overflow: TextOverflow.ellipsis,
),
),
leading: ClipRRect(
borderRadius: BorderRadius.circular(40),
child: index % 2 == 0
? Image.asset("assets/srk.png")
: Image.asset("assets/srk1.png"),
),
trailing: Text(chats[index]["time"]),
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (context) {
return ChatPage(
name: chats[index]["name"],
image:
index % 2 == 0 ? "assets/srk.png" : "assets/srk1.png",
);
})),
],
)
: Text(
chats[index]["Message"],
style: const TextStyle(overflow: TextOverflow.ellipsis),
),
leading: ClipRRect(
borderRadius: BorderRadius.circular(40),
child: index % 2 == 0
? Image.asset("assets/srk.png")
: Image.asset("assets/srk1.png"),
),
trailing: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(chats[index]["time"]),
if (chats[index]['pinned'])
Icon(
Icons.push_pin,
color: Colors.blue,
size: 16,
),
],
),
onLongPress: () => togglePin(index),
onTap: () =>
Navigator.push(context, MaterialPageRoute(builder: (context) {
return ChatPage(
name: chats[index]["name"],
image: index % 2 == 0 ? "assets/srk.png" : "assets/srk1.png",
);
}));
})),
);
},
),
);
}
}