Skip to content

Commit d1d1558

Browse files
authored
Merge pull request #3 from naidu199/web-screen-layout
web screen layout
2 parents cc0d884 + 70c1bd1 commit d1d1558

19 files changed

+680
-132
lines changed

lib/backend/authentication/auth_signup.dart

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class AuthSignUp {
3636
.uploadImageToStorage('profilepic', profilepic!, false);
3737
//adding user to database
3838
UserDetails userDetails = UserDetails(
39+
bio: '',
3940
uid: cred.user!.uid,
4041
username: username,
4142
email: email,

lib/backend/storage/firebase_post_storage.dart

+28
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class FireStorePostStorage {
7272
'profileUrl': profileUrl,
7373
'commentText': commentText,
7474
'userId': uid,
75+
'likes': [],
7576
'commentId': commentId,
7677
'timestamp': DateTime.now()
7778
});
@@ -83,6 +84,33 @@ class FireStorePostStorage {
8384
}
8485
}
8586

87+
Future<void> likesComment(
88+
String postId, String uid, List likes, String commentId) async {
89+
try {
90+
if (likes.contains(uid)) {
91+
await _firebaseFirestore
92+
.collection('posts')
93+
.doc(postId)
94+
.collection('comments')
95+
.doc(commentId)
96+
.update({
97+
'likes': FieldValue.arrayRemove([uid]),
98+
});
99+
} else {
100+
await _firebaseFirestore
101+
.collection('posts')
102+
.doc(postId)
103+
.collection('comments')
104+
.doc(commentId)
105+
.update({
106+
'likes': FieldValue.arrayUnion([uid]),
107+
});
108+
}
109+
} catch (e) {
110+
print(e.toString());
111+
}
112+
}
113+
86114
//post deleting
87115
Future<void> deletePost(String postId, BuildContext context) async {
88116
try {

lib/main.dart

+26-35
Original file line numberDiff line numberDiff line change
@@ -42,42 +42,33 @@ class MyApp extends StatelessWidget {
4242
// mobileScreenLayout: MobileScreenLayout(),
4343
// ),
4444
routes: AppRoutes.routes,
45-
home: const WebScreenLayout(),
46-
// home: StreamBuilder(
47-
// stream: FirebaseAuth.instance.authStateChanges(),
48-
// builder: (context, snapshot) {
49-
// if (snapshot.connectionState == ConnectionState.active) {
50-
// if (snapshot.hasData) {
51-
// // print("main page");
52-
// return const ResponsiveLayout(
53-
// webScreenLayout: WebScreenLayout(),
54-
// mobileScreenLayout: MobileScreenLayout(),
55-
// );
56-
// } else if (snapshot.hasError) {
57-
// return const Center(
58-
// child: Text('error while loading '),
59-
// );
60-
// }
61-
// }
62-
// if (snapshot.connectionState == ConnectionState.waiting) {
63-
// return const Center(
64-
// child: CircularProgressIndicator(
65-
// color: primaryColor,
66-
// ),
67-
// );
68-
// }
69-
// return const LoginScreen();
70-
// }),
45+
// home: const WebScreenLayout(),
46+
home: StreamBuilder(
47+
stream: FirebaseAuth.instance.authStateChanges(),
48+
builder: (context, snapshot) {
49+
if (snapshot.connectionState == ConnectionState.active) {
50+
if (snapshot.hasData) {
51+
// print("main page");
52+
return const ResponsiveLayout(
53+
webScreenLayout: WebScreenLayout(),
54+
mobileScreenLayout: MobileScreenLayout(),
55+
);
56+
} else if (snapshot.hasError) {
57+
return const Center(
58+
child: Text('error while loading '),
59+
);
60+
}
61+
}
62+
if (snapshot.connectionState == ConnectionState.waiting) {
63+
return const Center(
64+
child: CircularProgressIndicator(
65+
color: primaryColor,
66+
),
67+
);
68+
}
69+
return const LoginScreen();
70+
}),
7171
),
7272
);
7373
}
7474
}
75-
76-
// class MyHomePage extends StatelessWidget {
77-
// const MyHomePage({super.key});
78-
79-
// @override
80-
// Widget build(BuildContext context) {
81-
// return const Placeholder();
82-
// }
83-
// }

lib/model/user.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class UserDetails {
99
final String profileUrl;
1010
final List followers;
1111
final List following;
12-
// final String bio;
12+
final String bio;
1313

1414
UserDetails(
15-
// this.bio,
16-
{required this.uid,
15+
{required this.bio,
16+
required this.uid,
1717
required this.username,
1818
required this.email,
1919
required this.profileUrl,
@@ -33,7 +33,7 @@ class UserDetails {
3333
static UserDetails fromSnapshot(DocumentSnapshot documentSnapshot) {
3434
var snapshot = documentSnapshot.data() as Map<String, dynamic>;
3535
return UserDetails(
36-
// snapshot['bio'] ?? "",
36+
bio: snapshot['bio'] ?? "",
3737
uid: snapshot['uid'],
3838
username: snapshot['username'],
3939
email: snapshot['email'],

lib/responsive/responsive_layout.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ class _ResponsiveLayoutState extends State<ResponsiveLayout> {
2828
});
2929
UserProvider userProvider = Provider.of(context, listen: false);
3030
await userProvider.refreshUserDetails();
31-
setState(() {
32-
isloading = false;
33-
});
31+
if (mounted) {
32+
setState(() {
33+
isloading = false;
34+
});
35+
}
3436
// print(3);
3537
// print(userProvider.getUser.profileUrl);
3638
}

lib/responsive/webscreen_layout.dart

+73-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
// import 'package:flutter/material.dart';
2+
import 'package:firebase_auth/firebase_auth.dart';
23
import 'package:flutter/material.dart';
34
import 'package:flutter_side_menu/flutter_side_menu.dart';
45
import 'package:flutter_svg/svg.dart';
6+
import 'package:instagram_clone/backend/providers/user_providers.dart';
7+
import 'package:instagram_clone/model/user.dart';
8+
import 'package:instagram_clone/screens/add_post.dart';
9+
import 'package:instagram_clone/screens/feed_screen.dart';
10+
import 'package:instagram_clone/screens/profile.dart';
11+
import 'package:instagram_clone/screens/search_screen.dart';
12+
import 'package:instagram_clone/screens/suggestion_user.dart';
513
import 'package:instagram_clone/utils/colors.dart';
14+
import 'package:instagram_clone/widgets/post_feed.dart';
15+
import 'package:provider/provider.dart';
616

717
class WebScreenLayout extends StatefulWidget {
818
const WebScreenLayout({super.key});
@@ -12,11 +22,28 @@ class WebScreenLayout extends StatefulWidget {
1222
}
1323

1424
class _WebScreenLayoutState extends State<WebScreenLayout> {
25+
final SideMenuController _controller = SideMenuController();
26+
int _currentIndex = 0;
27+
28+
final List<Widget> pages = [
29+
const PostFeed(),
30+
const SearchScreen(),
31+
Container(color: Colors.yellow),
32+
Container(
33+
color: Colors.purple,
34+
),
35+
Container(
36+
color: Colors.green,
37+
),
38+
const AddPost(),
39+
ProfileScreen(
40+
uid: FirebaseAuth.instance.currentUser!.uid,
41+
),
42+
];
43+
1544
@override
1645
Widget build(BuildContext context) {
17-
final SideMenuController _controller = SideMenuController();
18-
int _currentIndex = 0;
19-
46+
UserDetails userDetails = Provider.of<UserProvider>(context).getUser;
2047
return Scaffold(
2148
body: Row(
2249
children: [
@@ -56,7 +83,9 @@ class _WebScreenLayoutState extends State<WebScreenLayout> {
5683
),
5784
selectedIcon: const Icon(Icons.home),
5885
selectedTitleStyle: const TextStyle(
59-
fontWeight: FontWeight.bold, color: primaryColor),
86+
fontSize: 18,
87+
fontWeight: FontWeight.bold,
88+
color: primaryColor),
6089
// badgeContent: const Text(
6190
// '23',
6291
// style: TextStyle(
@@ -72,7 +101,9 @@ class _WebScreenLayoutState extends State<WebScreenLayout> {
72101
title: 'Search',
73102
hoverColor: Colors.white38,
74103
selectedTitleStyle: const TextStyle(
75-
fontWeight: FontWeight.bold, color: primaryColor),
104+
fontSize: 18,
105+
fontWeight: FontWeight.bold,
106+
color: primaryColor),
76107
icon: const Icon(
77108
Icons.search_outlined,
78109
color: secondaryColor,
@@ -92,7 +123,9 @@ class _WebScreenLayoutState extends State<WebScreenLayout> {
92123
hoverColor: Colors.white38,
93124
itemHeight: 40,
94125
selectedTitleStyle: const TextStyle(
95-
fontWeight: FontWeight.bold, color: primaryColor),
126+
fontSize: 18,
127+
fontWeight: FontWeight.bold,
128+
color: primaryColor),
96129
icon: Padding(
97130
padding: const EdgeInsets.all(8),
98131
child: SvgPicture.asset(
@@ -121,7 +154,9 @@ class _WebScreenLayoutState extends State<WebScreenLayout> {
121154
title: 'Messages',
122155
hoverColor: Colors.white38,
123156
selectedTitleStyle: const TextStyle(
124-
fontWeight: FontWeight.bold, color: primaryColor),
157+
fontSize: 18,
158+
fontWeight: FontWeight.bold,
159+
color: primaryColor),
125160
icon: const Icon(Icons.chat_bubble_outline),
126161
selectedIcon: const Icon(Icons.chat_bubble),
127162
titleStyle:
@@ -134,7 +169,9 @@ class _WebScreenLayoutState extends State<WebScreenLayout> {
134169
title: 'Notifications',
135170
hoverColor: Colors.white38,
136171
selectedTitleStyle: const TextStyle(
137-
fontWeight: FontWeight.bold, color: primaryColor),
172+
fontSize: 18,
173+
fontWeight: FontWeight.bold,
174+
color: primaryColor),
138175
icon: const Icon(Icons.favorite_border),
139176
selectedIcon: const Icon(Icons.favorite),
140177
titleStyle:
@@ -147,48 +184,52 @@ class _WebScreenLayoutState extends State<WebScreenLayout> {
147184
title: 'Create',
148185
hoverColor: Colors.white38,
149186
selectedTitleStyle: const TextStyle(
150-
fontWeight: FontWeight.bold, color: primaryColor),
187+
fontSize: 18,
188+
fontWeight: FontWeight.bold,
189+
color: primaryColor),
151190
icon: const Icon(Icons.add_box_outlined),
152191
selectedIcon: const Icon(Icons.add_box_sharp),
153192
titleStyle:
154193
const TextStyle(color: secondaryColor, fontSize: 18),
155194
),
195+
SideMenuItemDataTile(
196+
margin: const EdgeInsetsDirectional.only(top: 10),
197+
isSelected: _currentIndex == 6,
198+
onTap: () => setState(() => _currentIndex = 6),
199+
title: 'Profile',
200+
hoverColor: Colors.white38,
201+
selectedTitleStyle: const TextStyle(
202+
fontSize: 18,
203+
fontWeight: FontWeight.bold,
204+
color: primaryColor),
205+
icon: const Icon(Icons.person_2_outlined),
206+
selectedIcon: const Icon(Icons.person_2),
207+
titleStyle:
208+
const TextStyle(color: secondaryColor, fontSize: 18),
209+
),
156210
],
157-
footer: const ListTile(
158-
leading: CircleAvatar(),
159-
title: Text("username"),
160-
subtitle: Text("name"),
211+
footer: ListTile(
212+
leading: CircleAvatar(
213+
backgroundImage: NetworkImage(userDetails.profileUrl),
214+
),
215+
title: Text(userDetails.username),
216+
subtitle: Text(userDetails.bio),
161217
),
162218
);
163219
},
164220
),
165221
),
166222
Expanded(
167223
child: Container(
168-
color: Colors.white,
169-
child: Column(
170-
crossAxisAlignment: CrossAxisAlignment.center,
171-
mainAxisAlignment: MainAxisAlignment.center,
172-
children: [
173-
Text(
174-
'body',
175-
style: Theme.of(context).textTheme.displaySmall,
176-
),
177-
ElevatedButton(
178-
onPressed: () {
179-
_controller.toggle();
180-
},
181-
child: const Text('change side menu state'),
182-
)
183-
],
184-
),
224+
color: mobileBackgroundColor,
225+
child: pages[_currentIndex],
185226
),
186227
),
187228
SideMenu(
188-
maxWidth: 300,
229+
maxWidth: 380,
189230
position: SideMenuPosition.right,
190231
builder: (data) => const SideMenuData(
191-
customChild: Text('custom view'),
232+
customChild: SuggestionScreen(),
192233
),
193234
),
194235
],

lib/screens/add_post.dart

+12-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:instagram_clone/backend/providers/user_providers.dart';
66
import 'package:instagram_clone/backend/storage/firebase_post_storage.dart';
77
import 'package:instagram_clone/model/user.dart';
88
import 'package:instagram_clone/utils/colors.dart';
9+
import 'package:instagram_clone/utils/global_consts.dart';
910
import 'package:instagram_clone/utils/image_picker.dart';
1011
import 'package:instagram_clone/utils/snackbars.dart';
1112
import 'package:provider/provider.dart';
@@ -98,19 +99,23 @@ class _AddPostState extends State<AddPost> {
9899

99100
@override
100101
Widget build(BuildContext context) {
102+
final double width = MediaQuery.of(context).size.width;
101103
// final UserDetails userDetails =
102104
// Provider.of<UserProvider>(context).getUserDetails;
103105
// print(userDetails.profileUrl);
104106
return Consumer<UserProvider>(builder: (context, value, child) {
105107
UserDetails userDetails = value.getUser;
106108
return Scaffold(
107109
appBar: AppBar(
110+
automaticallyImplyLeading: false,
108111
backgroundColor: mobileBackgroundColor,
109-
leading: IconButton(
110-
onPressed: () {
111-
clearPickedImage();
112-
},
113-
icon: const Icon(Icons.arrow_back)),
112+
leading: pickedImage != null
113+
? IconButton(
114+
onPressed: () {
115+
clearPickedImage();
116+
},
117+
icon: const Icon(Icons.arrow_back))
118+
: null,
114119
title: const Text("New Post"),
115120
centerTitle: false,
116121
actions: [
@@ -150,7 +155,8 @@ class _AddPostState extends State<AddPost> {
150155
backgroundImage: NetworkImage(userDetails.profileUrl),
151156
),
152157
SizedBox(
153-
width: MediaQuery.of(context).size.width * 0.45,
158+
width:
159+
width > webscreensize ? width * 0.25 : width * 0.45,
154160
child: TextField(
155161
controller: discriptionController,
156162
decoration: const InputDecoration(

lib/screens/comments_screen.dart

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class _CommentsScreenState extends State<CommentsScreen> {
5757
itemCount: snapshot.data!.docs.length,
5858
itemBuilder: (context, index) {
5959
return CommentCard(
60+
postId: widget.snapshot['postId'],
6061
snapshot: snapshot.data!.docs[index].data(),
6162
);
6263
});

0 commit comments

Comments
 (0)