Skip to content

Commit

Permalink
Simplification of LeaveOrg and OrgSetting Button
Browse files Browse the repository at this point in the history
  • Loading branch information
anand-aman committed May 24, 2021
1 parent 22e5a55 commit 69378aa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 52 deletions.
7 changes: 1 addition & 6 deletions lib/view_models/page_view_model/profile_page_viewModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ class ProfilePageViewModel extends BaseModel {
bool get isCreator => _isCreator;
AuthController get authController => _authController;

initialize({BuildContext context}) {
// if (isCreator != null && test != null) {
// _userDetails = test;
// _isCreator = isCreator;
// _org = _userDetails[0].joinedOrganizations;
// }
initialize({@required BuildContext context}) {
_context = context;
fetchUserDetails();
}
Expand Down
100 changes: 54 additions & 46 deletions lib/views/pages/organization/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,54 @@ import 'switch_org_page.dart';

class ProfilePage extends StatelessWidget {
const ProfilePage();

Widget showOrgSettingsButton({@required BuildContext context, @required ProfilePageViewModel model}) {
return ListTile(
key: const Key('Organization Settings'),
title: const Text(
'Organization Settings',
style: TextStyle(fontSize: 18.0),
),
leading: const Icon(
Icons.settings,
color: UIData.secondaryColor,
),
onTap: () {
pushNewScreen(
context,
screen: OrganizationSettings(
creator: model.creator == model.userID, public: model.isPublic, organization: model.curOrganization),
);
});
}

Widget showLeaveOrgButton({@required BuildContext context, @required ProfilePageViewModel model}) {
return model.org.isEmpty
? const SizedBox()
: ListTile(
key: const Key('Leave This Organization'),
title: const Text(
'Leave This Organization',
style: TextStyle(fontSize: 18.0),
),
leading: const Icon(
Icons.exit_to_app,
color: UIData.secondaryColor,
),
onTap: () async {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertBox(
message: "Are you sure you want to leave this organization?",
function: model.leaveOrg,
);
},
);
},
);
}

//main build starts from here
@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -153,52 +201,12 @@ class ProfilePage extends StatelessWidget {
),
);
}),
model.isCreator == null
? const SizedBox()
: model.isCreator == true
? ListTile(
key: const Key('Organization Settings'),
title: const Text(
'Organization Settings',
style: TextStyle(fontSize: 18.0),
),
leading: const Icon(
Icons.settings,
color: UIData.secondaryColor,
),
onTap: () {
pushNewScreen(
context,
screen: OrganizationSettings(
creator: model.creator == model.userID,
public: model.isPublic,
organization: model.curOrganization),
);
})
: model.org.isEmpty
? const SizedBox()
: ListTile(
key: const Key('Leave This Organization'),
title: const Text(
'Leave This Organization',
style: TextStyle(fontSize: 18.0),
),
leading: const Icon(
Icons.exit_to_app,
color: UIData.secondaryColor,
),
onTap: () async {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertBox(
message: "Are you sure you want to leave this organization?",
function: model.leaveOrg,
);
},
);
},
),
///Only Creator of the Org can access Organisation settings
///If the user is the creator, Organisation Setting button is display
///Else Leave Organisation button is displayed for the members of Organisation
model.isCreator
? showOrgSettingsButton(context: context, model: model)
: showLeaveOrgButton(context: context, model: model),
ListTile(
key: const Key('Logout'),
title: const Text(
Expand Down

0 comments on commit 69378aa

Please sign in to comment.