Skip to content

Commit

Permalink
Chat screen Ui completed
Browse files Browse the repository at this point in the history
  • Loading branch information
rudramistry001 committed Feb 7, 2024
1 parent b774d48 commit 0fcb4a7
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 42 deletions.
15 changes: 14 additions & 1 deletion login/lib/api/apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ class APIs {
}

static Stream<QuerySnapshot<Map<String, dynamic>>> getAllUsers() {
return firestore.collection('Users').snapshots();
return firestore
.collection('Users')
.where('Id',
isNotEqualTo: user.uid) //because empty list throws an error
// .where('id', isNotEqualTo: user.uid)
.snapshots();
}

// for updating user information
Expand Down Expand Up @@ -92,4 +97,12 @@ class APIs {
.doc(user.uid)
.update({'image': me.Image});
}

// CHAT SCREEN RELATED APIS
static Stream<QuerySnapshot<Map<String, dynamic>>> getAllMessages(
ChatUser user) {
return firestore.collection('messages').snapshots();
}

static getUserInfo(ChatUser user) {}
}
38 changes: 23 additions & 15 deletions login/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:login/auth/loginscreen.dart';
import 'package:login/screens/homescreen.dart';
import 'package:login/screens/onboard_screen.dart';
import 'package:login/screens/splashscreen.dart';
import 'firebase_options.dart';
Expand All @@ -20,22 +22,28 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
'/home': (context) => const HomeScreen(),
'/login': (context) => const LoginPage(),
'/onboard': (context) => const OnBoardScreen(),
return ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: (_, child) {
return MaterialApp(
routes: {
'/home': (context) => const HomePage(),
'/login': (context) => const LoginPage(),
'/onboard': (context) => const OnBoardScreen(),

// other routes...
},
debugShowCheckedModeBanner: false,
title: 'Apna Chat',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const SplashScreen(),
);
// other routes...
},
debugShowCheckedModeBanner: false,
title: 'Apna Chat',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const SplashScreen(),
);
});
}
}

Expand Down
1 change: 0 additions & 1 deletion login/lib/screens/homescreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:login/api/apis.dart';
import 'package:login/constants/strings.dart';
import 'package:login/main.dart';
import 'package:login/model/chat_user_model.dart';
import 'package:login/screens/chat_screen.dart';
import 'package:login/screens/contact_list.dart';
import 'package:login/screens/profile_screen.dart';
import 'package:login/widgets/chat_user_card.dart';
Expand Down
16 changes: 0 additions & 16 deletions login/lib/screens/onboard_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,3 @@ class _OnBoardScreenState extends State<OnBoardScreen> {
);
}
}

class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Home Screen"),
),
body: const Center(
child: Text("Welcome to your app!"),
),
);
}
}
31 changes: 23 additions & 8 deletions login/lib/screens/splashscreen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:login/api/apis.dart';
import 'package:login/auth/loginscreen.dart';
import 'package:login/main.dart';
import 'package:login/screens/homescreen.dart';
import 'package:login/screens/onboard_screen.dart';

class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
Expand All @@ -12,14 +17,24 @@ class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
Future.delayed(
const Duration(
milliseconds: 1500,
),
() {
Navigator.pushReplacementNamed(context, '/onboard');
},
);
Future.delayed(const Duration(seconds: 2), () {
//exit full-screen
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.white,
statusBarColor: Colors.white));

if (APIs.auth.currentUser != null) {
print('\nUser: ${APIs.auth.currentUser}');
//navigate to home screen
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (_) => const HomePage()));
} else {
//navigate to login screen
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (_) => const LoginPage()));
}
});
}

@override
Expand Down
184 changes: 184 additions & 0 deletions login/lib/screens/user_chat_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:login/api/apis.dart';
import 'package:login/main.dart';
import 'package:login/model/chat_user_model.dart';
import 'package:login/screens/profile_screen.dart';

class UserChatScreen extends StatefulWidget {
final ChatUser user;
const UserChatScreen({super.key, required this.user});

@override
State<UserChatScreen> createState() => _UserChatScreenState();
}

class _UserChatScreenState extends State<UserChatScreen> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfileScreen(user: APIs.me)),
);
},
child: Row(
children: [
IconButton(
onPressed: () => Navigator.pop(context),
icon: const Icon(Icons.arrow_back, color: Colors.black54),
),
10.horizontalSpace,
ClipRRect(
borderRadius: BorderRadius.circular(mq.height * .03),
child: CachedNetworkImage(
width: mq.height * .05,
height: mq.height * .05,
imageUrl: widget.user.Image,
errorWidget: (context, url, error) => const CircleAvatar(
child: Icon(CupertinoIcons.person)),
),
),
10.horizontalSpace,
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.user.Name,
style: TextStyle(
fontSize: 16.sp, fontWeight: FontWeight.w400),
),
Text(
"last seen not avaiable till now",
style: TextStyle(
fontSize: 16.sp, fontWeight: FontWeight.w400),
),
],
)
],
),
)),
backgroundColor: const Color.fromARGB(255, 234, 248, 255),
body: Column(
children: [
Expanded(
child: StreamBuilder(
stream: APIs.getAllUsers(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
// if data s loading
case ConnectionState.waiting:
case ConnectionState.none:
return const Center(
child: CircularProgressIndicator(),
);

//if some or all data is loaded then show it
case ConnectionState.active:
case ConnectionState.done:
// final data = snapshot.data?.docs;
// _list = data
// ?.map((e) => ChatUser.fromJson(e.data()))
// .toList() ??
// [];

final _list = ['hii', 'hello'];
if (_list.isNotEmpty) {
return ListView.builder(
itemCount: _list.length, // Use the length of the list
padding: EdgeInsets.only(top: mq.height * .01),
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
return Text('Message: ${_list[index]}');
},
);
} else {
return Center(
child: Text(
"Say Hii 👋",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.sp, fontWeight: FontWeight.w400),
),
);
}
}
},
),
),
_chatInput(),
],
),
),
);
}

Widget _chatInput() {
return Padding(
padding: EdgeInsets.symmetric(
vertical: mq.height * .01, horizontal: mq.width * .025),
child: Row(
children: [
Expanded(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Row(
children: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.emoji_emotions,
color: Colors.blueAccent),
),
Expanded(
child: TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Type Something...",
hintStyle: TextStyle(
color: Colors.blueAccent,
fontSize: 16.sp,
fontWeight: FontWeight.w300)),
),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.image, color: Colors.blueAccent),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.camera_enhance_outlined,
color: Colors.blueAccent),
),
],
),
),
//send message button
),
MaterialButton(
onPressed: () {},
minWidth: 1,
padding: EdgeInsets.only(
top: 5.sp, bottom: 5.sp, right: 5.sp, left: 5.sp),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
color: Colors.blueAccent,
child: IconButton(onPressed: () {}, icon: const Icon(Icons.send)),
),
],
),
);
}
}
9 changes: 8 additions & 1 deletion login/lib/widgets/chat_user_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:login/main.dart';
import 'package:login/model/chat_user_model.dart';
import 'package:login/screens/user_chat_screen.dart';

class ChatUserCard extends StatefulWidget {
final ChatUser user;
Expand All @@ -20,7 +21,13 @@ class _ChatUserCardState extends State<ChatUserCard> {
margin: EdgeInsets.symmetric(horizontal: mq.width * .04, vertical: 4),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: InkWell(
onTap: () {},
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UserChatScreen(user: widget.user)),
);
},
child: ListTile(
// leading: const CircleAvatar(
// child: Icon(CupertinoIcons.person),
Expand Down
1 change: 1 addition & 0 deletions login/lib/widgets/message_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 8 additions & 0 deletions login/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.17"
flutter_screenutil:
dependency: "direct main"
description:
name: flutter_screenutil
sha256: "8cf100b8e4973dc570b6415a2090b0bfaa8756ad333db46939efc3e774ee100d"
url: "https://pub.dev"
source: hosted
version: "5.9.0"
flutter_svg:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions login/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
chat_bubbles: ^1.5.0
image_picker: ^1.0.7
firebase_storage: ^11.6.0
flutter_screenutil: ^5.9.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 0fcb4a7

Please sign in to comment.