Files
Regroup/lib/Main_Screens/Chats/View/chatsmainscreen.dart
2024-07-31 16:08:23 +05:30

871 lines
27 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:regroup/Common/CommonBottomNavigationBar.dart';
import 'package:regroup/Common/controller/MainScreen.dart';
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
import 'package:regroup/Utils/texts.dart';
import 'package:regroup/resources/routes/route_name.dart';
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
class ChatsMainScreen extends StatefulWidget {
const ChatsMainScreen({super.key});
@override
State<ChatsMainScreen> createState() => _ChatsMainScreenState();
}
class _ChatsMainScreenState extends State<ChatsMainScreen> {
TextEditingController searchcontroller = TextEditingController();
final GlobalKey<ScaffoldState> _scaffoldKey1 = GlobalKey<ScaffoldState>();
List chatcontents = [
{
'image': "assets/images/png/Ellipse 52.png",
'tittle': "Ryan Dorwart",
'subtittle': "Lorem Ipsum is simply dummy text . . .",
'messageread': true,
'actstatus': true,
'pinned': true,
},
{
'image': "assets/images/png/Ellipse 48.png",
'tittle': "Alfonso Rosser",
'subtittle': "Lorem Ipsum is simply dummy text . . .",
'messageread': true,
'actstatus': true,
'pinned': false,
},
{
'image': "assets/images/png/Ellipse 52.png",
'tittle': "Tatiana Kenter",
'subtittle': "Lorem Ipsum is simply dummy text . . .",
'messageread': true,
'actstatus': true,
'pinned': false,
},
{
'image': "assets/images/png/Ellipse 48.png",
'tittle': "Ahmad Rhiel Madsen",
'subtittle': "Lorem Ipsum is simply dummy text . . .",
'messageread': false,
'actstatus': false,
'pinned': false,
},
{
'image': "assets/images/png/Ellipse 52.png",
'tittle': "Liverpool FC",
'subtittle': "Lorem Ipsum is simply dummy text . . .",
'messageread': false,
'actstatus': false,
'pinned': false,
},
{
'image': "assets/images/png/Ellipse 48.png",
'tittle': "Abram Westervelt",
'subtittle': "Lorem Ipsum is simply dummy text . . .",
'messageread': false,
'actstatus': false,
'pinned': false,
}
];
List clubcontents = [
{
'image': "assets/images/png/Ellipse 52.png",
'tittle': "Wellness warriors collective",
'subtittle': "Maria Herwitz : Hello Guys",
'messageread': true,
},
{
'image': "assets/images/png/Ellipse 48.png",
'tittle': "Body blitz brigade",
'subtittle': "Maria Herwitz : Hello Guys",
'messageread': true,
},
{
'image': "assets/images/png/Ellipse 52.png",
'tittle': "Wellness warriors collective",
'subtittle': "Maria Herwitz : Hello Guys",
'messageread': true,
},
];
List teamcontents = [
{
'image': "assets/images/png/Ellipse 52.png",
'tittle': "Cardio crusaders circle",
'subtittle': "Maria Herwitz : Hello Guys",
'messageread': true,
},
{
'image': "assets/images/png/Ellipse 48.png",
'tittle': "Strength squad syndicate",
'subtittle': "Maria Herwitz : Hello Guys",
'messageread': true,
},
{
'image': "assets/images/png/Ellipse 52.png",
'tittle': "Flexibility faction force",
'subtittle': "Maria Herwitz : Hello Guys",
'messageread': true,
},
];
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
resizeToAvoidBottomInset: false,
key: _scaffoldKey1,
backgroundColor: const Color(0xFF222935),
appBar: AppBar(
scrolledUnderElevation: 0.0,
backgroundColor: const Color(0xff222935),
elevation: 0,
automaticallyImplyLeading: false,
titleSpacing: 0,
title: Padding(
padding: EdgeInsets.only(left: 16.w),
child: Text(
'Chats',
style: TextStyle(
fontSize: 23.sp,
fontFamily: 'Helvetica',
color: Colors.white,
fontWeight: FontWeight.w700),
),
),
actions: [
Padding(
padding: EdgeInsets.only(right: 16.w),
child: InkWell(
onTap: () {
Get.toNamed(RouteName.newchatpage);
},
child: Image.asset('assets/images/png/editicon.png')),
)
],
// bottom: PreferredSize(
// preferredSize: Size.fromHeight(90),
// child:
// ),
),
body: Stack(
children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/png/Ellipse 1496.png"),
fit: BoxFit.fill)),
),
Column(children: [
Column(
children: [
sizedBoxHeight(25.h),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: CustomTextFormField(
textEditingController: searchcontroller,
texttype: TextInputType.text,
hintText: "Search chats",
leadingIcon: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: const Icon(
Icons.search,
size: 35,
color: Colors.white,
),
),
// validatorText: "Enter your full name",
inputFormatters: [
// LengthLimitingTextInputFormatter(20),
RemoveEmojiInputFormatter(),
],
),
),
sizedBoxHeight(25.h)
],
),
Expanded(
child: DefaultTabController(
length: 3,
// initialIndex: selectedIndex.value,
child: Column(
children: [
const MyTabBar(),
Expanded(
child: TabBarView(
children: [feedTab(), clubsTab(), teamsTab()],
),
),
],
),
),
),
])
],
),
bottomNavigationBar: bottomnavigationbar(mainController),
),
);
}
Widget feedTab() {
return SingleChildScrollView(
child: Column(
children: [
sizedBoxHeight(25.h),
ListView.separated(
separatorBuilder: (context, index) {
return Divider(
thickness: 0.6.h,
color: const Color(0xffFFFFFF).withOpacity(0.72),
);
},
itemCount: chatcontents.length,
shrinkWrap: true,
padding: const EdgeInsets.only(top: 10.0),
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Get.toNamed(RouteName.userchatpage);
},
child: ChatList(
name: chatcontents[index]['tittle'],
imageurl: chatcontents[index]['image'],
message: chatcontents[index]['subtittle'],
isMessageRead: chatcontents[index]['messageread'],
activestatus: chatcontents[index]['actstatus'],
ispinned: chatcontents[index]['pinned'],
count:
(index == 0 || index == 1 || index == 2 || index == 3)
? true
: false),
);
},
),
],
),
);
}
Widget clubsTab() {
return SingleChildScrollView(
child: Column(
children: [
sizedBoxHeight(25.h),
ListView.separated(
separatorBuilder: (context, index) {
return Divider(
thickness: 0.6.h,
color: const Color(0xffFFFFFF).withOpacity(0.72),
);
},
itemCount: clubcontents.length,
shrinkWrap: true,
padding: const EdgeInsets.only(top: 10.0),
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Get.toNamed(RouteName.groupchatpage);
},
child: SecondChatList(
name: clubcontents[index]['tittle'],
imageurl: clubcontents[index]['image'],
message: clubcontents[index]['subtittle'],
isMessageRead: clubcontents[index]['messageread'],
),
);
},
),
],
),
);
}
Widget teamsTab() {
return SingleChildScrollView(
child: Column(
children: [
sizedBoxHeight(25.h),
ListView.separated(
separatorBuilder: (context, index) {
return Divider(
thickness: 0.6.h,
color: const Color(0xffFFFFFF).withOpacity(0.72),
);
},
itemCount: teamcontents.length,
shrinkWrap: true,
padding: const EdgeInsets.only(top: 10.0),
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Get.toNamed(RouteName.groupchatpage);
},
child: SecondChatList(
name: teamcontents[index]['tittle'],
imageurl: teamcontents[index]['image'],
message: teamcontents[index]['subtittle'],
isMessageRead: teamcontents[index]['messageread'],
),
);
},
),
],
),
);
}
}
class MyTabBar extends StatelessWidget {
const MyTabBar({super.key});
// Set the desired height
@override
Widget build(BuildContext context) {
return TabBar(
dividerColor: const Color(0xFFFFFFFF).withOpacity(0.07),
labelStyle: TextStyle(
fontSize: 14.sp,
color: const Color(0xFFFCFCFC),
fontWeight: FontWeight.w400,
fontFamily: 'Helvetica'),
indicatorSize: TabBarIndicatorSize.tab,
indicatorColor: const Color(0xFFD90B2E),
// labelColor: Colors.white,
indicatorWeight: 2.h,
dividerHeight: 2.h,
unselectedLabelColor: const Color(0xFFFCFCFC),
overlayColor: MaterialStateProperty.all(const Color(0xFFD90B2E)),
tabs: const [
Tab(
text: 'Friends',
),
Tab(
text: 'Clubs',
),
Tab(
text: 'Teams',
),
]);
}
}
// ignore: must_be_immutable
class ChatList extends StatefulWidget {
String name;
String imageurl;
String message;
bool isMessageRead;
bool activestatus;
bool ispinned;
bool count;
ChatList({
Key? key,
required this.name,
required this.imageurl,
required this.message,
required this.isMessageRead,
required this.activestatus,
required this.ispinned,
required this.count,
}) : super(key: key);
@override
State<ChatList> createState() => _ChatListState();
}
class _ChatListState extends State<ChatList> {
void _showContextMenu(BuildContext context, Offset offset) {
showMenu(
color: const Color(0XFf222935),
context: context,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.r)),
position:
RelativeRect.fromLTRB(offset.dx, offset.dy, offset.dx, offset.dy),
items: [
PopupMenuItem<int>(
value: 0,
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Mute chat", style: TextStyle(color: Colors.white)),
Image.asset(
'assets/images/png/mute.png',
width: 19.w,
height: 19.h,
)
],
),
Divider(
thickness: 0.6.h,
color: const Color(0xffFFFFFF).withOpacity(0.72),
)
]),
),
PopupMenuItem<int>(
value: 1,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Pin chat", style: TextStyle(color: Colors.white)),
Image.asset(
'assets/images/png/pin.png',
width: 19.w,
height: 19.h,
)
],
),
Divider(
thickness: 0.6.h,
color: const Color(0xffFFFFFF).withOpacity(0.72),
)
],
),
),
PopupMenuItem<int>(
value: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Delete chat", style: TextStyle(color: Colors.red)),
// Icon(Icons.delete, color: Colors.red),
Image.asset(
'assets/images/png/deletetred.png',
width: 19.w,
height: 19.h,
)
],
),
),
],
).then((value) {
if (value != null) {
_onMenuItemSelected(value);
}
});
}
void _onMenuItemSelected(int value) {
switch (value) {
case 0:
// Mute chat
print('Mute chat selected');
break;
case 1:
// Pin chat
print('Pin chat selected');
break;
case 2:
// Delete chat
print('Delete chat selected');
break;
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onLongPressStart: (details) {
_showContextMenu(context, details.globalPosition);
},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.h),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(children: [
Container(
width: 55.w,
height: 55.h,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.imageurl),
fit: BoxFit.fill,
),
),
),
Positioned(
top: 40.h,
left: 45.w,
child: widget.activestatus == true
? Container(
width: 10.w,
height: 10.h,
decoration: const ShapeDecoration(
color: Color(0xFF32D74B),
shape: OvalBorder(),
),
)
: Container(
width: 10.w,
height: 10.h,
decoration: const ShapeDecoration(
color: Color(0xFFFF453A),
shape: OvalBorder(),
)),
)
]),
sizedBoxWidth(8.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text16400white(widget.name),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
widget.isMessageRead == true
? Image.asset(
'assets/images/png/messagereadcheckmark.png')
: Image.asset('assets/images/png/messagedelivered.png'),
sizedBoxWidth(5.w),
SizedBox(
width: 170.w,
child: Text(
widget.message,
style: TextStyle(
color: const Color(0xCCFCFCFC),
fontSize: 12.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
),
],
),
],
),
const Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
text12400white('Yesterday'),
sizedBoxHeight(5.h),
Row(
children: [
widget.ispinned == true
? Image.asset('assets/images/png/pin.png')
: const SizedBox(
width: 25,
),
sizedBoxWidth(3.w),
widget.count == true
? Container(
width: 18,
height: 18,
decoration: const ShapeDecoration(
color: Color(0xFFD90B2E),
shape: OvalBorder(),
),
child: Text(
'1',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFFFCFCFC),
fontSize: 12.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
)
: const SizedBox()
],
)
],
)
],
),
),
);
}
}
class SecondChatList extends StatefulWidget {
final String name;
final String imageurl;
final String message;
final bool isMessageRead;
const SecondChatList({
Key? key,
required this.name,
required this.imageurl,
required this.message,
required this.isMessageRead,
}) : super(key: key);
@override
State<SecondChatList> createState() => _SecondChatListState();
}
class _SecondChatListState extends State<SecondChatList> {
void _showContextMenu(BuildContext context, Offset offset) {
showMenu(
color: const Color(0XFf222935),
context: context,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.r)),
position:
RelativeRect.fromLTRB(offset.dx, offset.dy, offset.dx, offset.dy),
items: [
PopupMenuItem<int>(
value: 0,
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Mute chat", style: TextStyle(color: Colors.white)),
Image.asset(
'assets/images/png/mute.png',
width: 19.w,
height: 19.h,
)
],
),
Divider(
thickness: 0.6.h,
color: const Color(0xffFFFFFF).withOpacity(0.72),
)
]),
),
PopupMenuItem<int>(
value: 1,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Pin chat", style: TextStyle(color: Colors.white)),
Image.asset(
'assets/images/png/pin.png',
width: 19.w,
height: 19.h,
)
],
),
Divider(
thickness: 0.6.h,
color: const Color(0xffFFFFFF).withOpacity(0.72),
)
],
),
),
PopupMenuItem<int>(
value: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Delete chat", style: TextStyle(color: Colors.red)),
// Icon(Icons.delete, color: Colors.red),
Image.asset(
'assets/images/png/deletetred.png',
width: 19.w,
height: 19.h,
)
],
),
),
],
).then((value) {
if (value != null) {
_onMenuItemSelected(value);
}
});
}
void _onMenuItemSelected(int value) {
switch (value) {
case 0:
// Mute chat
print('Mute chat selected');
break;
case 1:
// Pin chat
print('Pin chat selected');
break;
case 2:
// Delete chat
print('Delete chat selected');
break;
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onLongPressStart: (details) {
_showContextMenu(context, details.globalPosition);
},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.h),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 55.w,
height: 55.h,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.imageurl),
fit: BoxFit.fill,
),
),
),
SizedBox(width: 10.w), // Add some spacing between image and text
Expanded(
child: Padding(
padding: EdgeInsets.only(top: 5.h),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.name,
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
SizedBox(height: 3.h),
Row(
children: [
widget.isMessageRead
? Image.asset(
'assets/images/png/messagereadcheckmark.png')
: Image.asset(
'assets/images/png/messagedelivered.png'),
SizedBox(width: 5.w),
Text(
widget.message,
style: TextStyle(
color: const Color(0xCCFCFCFC),
fontSize: 12.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
],
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.end, // Align to the end of the column
children: [
Text(
'Yesterday',
style: TextStyle(
color: Colors.white,
fontSize: 12.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
],
),
),
],
),
),
);
}
}
// class SecondChatList extends StatefulWidget {
// String name;
// String imageurl;
// String message;
// bool isMessageRead;
// SecondChatList({
// Key? key,
// required this.name,
// required this.imageurl,
// required this.message,
// required this.isMessageRead,
// }) : super(key: key);
// @override
// State<SecondChatList> createState() => _SecondChatListState();
// }
// class _SecondChatListState extends State<SecondChatList> {
// @override
// Widget build(BuildContext context) {
// return Padding(
// padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.h),
// child: Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Container(
// width: 55,
// height: 55,
// decoration: BoxDecoration(
// image: DecorationImage(
// image: AssetImage(widget.imageurl),
// fit: BoxFit.fill,
// ),
// ),
// ),
// Padding(
// padding: EdgeInsets.only(top: 5),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// text16400white(widget.name),
// sizedBoxHeight(3.h),
// Row(
// children: [
// widget.isMessageRead == true
// ? Image.asset(
// 'assets/images/png/messagereadcheckmark.png')
// : Image.asset('assets/images/png/messagedelivered.png'),
// sizedBoxWidth(5.w),
// Text(
// widget.message,
// style: TextStyle(
// color: Color(0xCCFCFCFC),
// fontSize: 12.sp,
// fontFamily: 'Helvetica',
// fontWeight: FontWeight.w400,
// ),
// ),
// ],
// ),
// ],
// ),
// ),
// Padding(
// padding: const EdgeInsets.only(top: 5),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// text12400white('Yesterday'),
// ],
// ),
// )
// ],
// ),
// );
// }
// }