Skip to content

Commit

Permalink
Merge pull request #13 from mazineab/UI_changes
Browse files Browse the repository at this point in the history
Create user list page and replace OBX by GetBuilder in comments and p…
  • Loading branch information
mazineab authored Nov 6, 2024
2 parents ec6ceea + d655fb1 commit 83d1ddf
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/common/widgets/custom_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CustomListTile extends StatelessWidget {
final String userId;
String? uid;
String? profileUrl;
String? statusId;//this add just when this widget used by comment
String? statusId;
CustomListTile(
{super.key,
required this.title,
Expand Down Expand Up @@ -59,7 +59,7 @@ class CustomListTile extends StatelessWidget {
],
),
),
menuCondition()
statusId==null && uid==null?SizedBox() :menuCondition()
],
),
),
Expand Down
10 changes: 10 additions & 0 deletions lib/data/repositories/home_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ class HomeRepo{
throw Exception(e);
}
}

Future<List<my_user.User>> getUsers()async{
try{
QuerySnapshot querySnapshot=await firebaseFireStore.collection('users').get();
List<my_user.User> listUsers=querySnapshot.docs.map((e)=>my_user.User.fromJson(e.data() as Map<String,dynamic>)).toList();
return listUsers;
}catch(e){
throw e;
}
}
}
3 changes: 3 additions & 0 deletions lib/featues/setting/controller/setting_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ class SettingController extends GetxController {
goCommentPage(){
Get.toNamed(RoutesNames.commentPage);
}
goUsersPage(){
Get.toNamed(RoutesNames.usersPage);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class StatusCommentController extends GetxController{
await Future.delayed(const Duration(milliseconds: 30));
isLoad.value=false;
}
update();
}

@override
Expand Down
31 changes: 31 additions & 0 deletions lib/featues/setting/controller/users_list_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:get/get.dart';
import 'package:myapp/data/models/user.dart' as my_user;

import '../../../common/dialogs/custom_snackbar.dart';
import '../../../data/repositories/home_repo.dart';


class UsersListController extends GetxController{
List<my_user.User> listUsers=<my_user.User>[].obs;
var isLoad=true.obs;
HomeRepo homeRepo=Get.put(HomeRepo());

Future<void> fetchUsers()async{
try{
List<my_user.User> list=await homeRepo.getUsers();
listUsers.assignAll(list);
}catch(e){
CustomSnackbar.showErrorSnackbar(Get.context!, "Faild to load Users");
}finally{
await Future.delayed(const Duration(milliseconds: 30));
isLoad.value=false;
}
update();
}

@override
void onInit()async {
await fetchUsers();
super.onInit();
}
}
2 changes: 1 addition & 1 deletion lib/featues/setting/screens/comments_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CommentsList extends StatelessWidget {
backgroundColor: MyColors.appBarColor,
iconTheme: IconThemeData(color: Colors.white),
),
Obx(() {
GetBuilder<StatusCommentController>(builder: (_) {
if (controller.isLoad.value) {
return SliverFillRemaining(
child: Column(
Expand Down
1 change: 1 addition & 0 deletions lib/featues/setting/screens/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Setting extends StatelessWidget {
}),
buildListTile("Notifications Preferences", Icons.notifications_outlined),
buildTitle("Community Setting"),
buildListTile("Users", Icons.groups,onTap: controller.goUsersPage),
buildListTile("Comment List", Icons.comment_outlined,onTap: controller.goCommentPage),
buildListTile("Post List", Icons.list_outlined,onTap: controller.goStatusPage),
buildTitle("Others"),
Expand Down
2 changes: 1 addition & 1 deletion lib/featues/setting/screens/status_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class StatusList extends StatelessWidget {
backgroundColor: MyColors.appBarColor,
iconTheme: IconThemeData(color: Colors.white),
),
Obx(() {
GetBuilder<StatusCommentController>(builder: (_) {
if (controller.isLoad.value) {
return SliverFillRemaining(
child: Column(
Expand Down
61 changes: 61 additions & 0 deletions lib/featues/setting/screens/users_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:myapp/Constants/colors.dart';
import 'package:myapp/common/widgets/custom_list_tile.dart';
import 'package:myapp/featues/setting/controller/users_list_controller.dart';

class UsersList extends StatelessWidget {
UsersList({super.key});

UsersListController controller=Get.put(UsersListController());

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: MyColors.backgroundColor,
body: CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: 40.0,
floating: true,
pinned: false,
flexibleSpace: FlexibleSpaceBar(
title: Text('USERS',style: TextStyle(color: Colors.white),),
),
backgroundColor: MyColors.appBarColor,
iconTheme: IconThemeData(color: Colors.white),
),
GetBuilder<UsersListController>(
builder: (_){
if(controller.isLoad.value){
return SliverFillRemaining(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: CircularProgressIndicator(
backgroundColor: MyColors.colorbl,
),
),
],
),
);
}
return SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
final user = controller.listUsers[index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: CustomListTile(title: user.getFullName(), subtitle: user.email, userId: user.id,profileUrl: user.imageUrl,),
);
},
childCount: controller.listUsers.length,
),
);
})
],
),
);
}
}
4 changes: 3 additions & 1 deletion lib/routes/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:myapp/featues/setting/screens/comments_list.dart';
import 'package:myapp/featues/setting/screens/personal_info.dart';
import 'package:myapp/featues/setting/screens/setting.dart';
import 'package:myapp/featues/setting/screens/status_list.dart';
import 'package:myapp/featues/setting/screens/users_list.dart';
import 'package:myapp/featues/setting/setting_binding.dart';
import 'package:myapp/routes/routes_names.dart';

Expand All @@ -25,6 +26,7 @@ class Routes{
GetPage(name: RoutesNames.personalInfo, page:()=>PersonalInfo(),binding: SettingBinding()),
GetPage(name: RoutesNames.setting, page:()=>Setting(),binding: SettingBinding()),
GetPage(name: RoutesNames.statusPage, page:()=>StatusList()),
GetPage(name: RoutesNames.commentPage, page:()=>CommentsList())
GetPage(name: RoutesNames.commentPage, page:()=>CommentsList()),
GetPage(name: RoutesNames.usersPage, page:()=>UsersList())
];
}
1 change: 1 addition & 0 deletions lib/routes/routes_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class RoutesNames {
static const String setting = "/setting";
static const String statusPage="/statusPage";
static const String commentPage="/commentPage";
static const String usersPage="/userPage";
}

0 comments on commit 83d1ddf

Please sign in to comment.