Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 21
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 21
22_23-J 21
Commits
f539d154
Commit
f539d154
authored
May 10, 2023
by
Kaushan H.K.R
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin home
parent
43e4386b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
235 additions
and
0 deletions
+235
-0
FrontEnd/lib/screens/admin_home.dart
FrontEnd/lib/screens/admin_home.dart
+235
-0
No files found.
FrontEnd/lib/screens/admin_home.dart
0 → 100644
View file @
f539d154
import
'package:flutter/material.dart'
;
import
'package:govimithura/constants/post_status.dart'
;
import
'package:govimithura/models/entity_model.dart'
;
import
'package:govimithura/models/post_model.dart'
;
import
'package:govimithura/providers/authentication_provider.dart'
;
import
'package:govimithura/providers/post_provider.dart'
;
import
'package:govimithura/utils/screen_size.dart'
;
import
'package:provider/provider.dart'
;
import
'../models/insect_model.dart'
;
import
'../utils/loading_overlay.dart'
;
import
'../utils/utils.dart'
;
import
'../widgets/utils/common_widget.dart'
;
import
'login.dart'
;
import
'my_post.dart'
;
class
AdminHome
extends
StatefulWidget
{
const
AdminHome
({
super
.
key
});
@override
State
<
AdminHome
>
createState
()
=>
_AdminHomeState
();
}
class
_AdminHomeState
extends
State
<
AdminHome
>
{
late
AuthenticationProvider
pAuthentication
;
late
PostProvider
pPost
;
List
<
PostModel
<
InsectModel
>>
initialPosts
=
const
[];
List
<
PostModel
<
InsectModel
>>
posts
=
[];
List
<
EntityModel
>
statusList
=
[];
EntityModel
selectedStatus
=
EntityModel
();
@override
void
initState
()
{
super
.
initState
();
pAuthentication
=
Provider
.
of
<
AuthenticationProvider
>(
context
,
listen:
false
);
pPost
=
Provider
.
of
<
PostProvider
>(
context
,
listen:
false
);
Future
.
delayed
(
Duration
.
zero
,
()
=>
initialize
());
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
leading:
const
Icon
(
Icons
.
home
),
title:
const
Text
(
"Admin Home"
),
actions:
[
IconButton
(
onPressed:
()
{
showDialog
(
context:
context
,
builder:
(
_
)
=>
confirmationDialog
(
context
,
title:
"Logout from Govi Mithura"
,
yesFunction:
()
async
{
await
pAuthentication
.
signOut
();
if
(
context
.
mounted
)
{
Navigator
.
pushReplacement
(
context
,
MaterialPageRoute
(
builder:
(
_
)
=>
const
LoginScreen
()),
);
}
},
),
);
},
icon:
const
Icon
(
Icons
.
logout
),
),
],
),
body:
SingleChildScrollView
(
child:
Container
(
padding:
const
EdgeInsets
.
all
(
20
),
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
[
const
Text
(
"Post Approval"
,
style:
TextStyle
(
fontSize:
20
,
fontWeight:
FontWeight
.
bold
),
),
Row
(
children:
[
DropdownButton
(
items:
statusList
.
map
((
status
)
{
return
DropdownMenuItem
(
value:
status
.
id
,
child:
Text
(
status
.
description
),
);
}).
toList
(),
value:
selectedStatus
.
id
,
onChanged:
(
int
?
value
)
{
selectedStatus
=
statusList
.
firstWhere
((
element
)
=>
element
.
id
==
value
);
filterPosts
();
},
),
spacingWidget
(
10
,
SpaceDirection
.
horizontal
),
IconButton
(
onPressed:
()
async
{
await
initialize
();
},
icon:
const
Icon
(
Icons
.
refresh
),
),
],
)
],
),
spacingWidget
(
15
,
SpaceDirection
.
vertical
),
if
(
posts
.
isNotEmpty
)
...
List
.
generate
(
posts
.
length
,
(
index
)
=>
Container
(
margin:
const
EdgeInsets
.
only
(
bottom:
10
),
padding:
const
EdgeInsets
.
all
(
10
),
decoration:
BoxDecoration
(
color:
Colors
.
white
,
borderRadius:
BorderRadius
.
circular
(
10
),
),
child:
Column
(
children:
[
ListTile
(
onTap:
()
{
Navigator
.
push
(
context
,
SlidePageRoute
(
page:
MyPost
(
postId:
posts
[
index
].
id
,
isAdmin:
true
,
)));
},
title:
Text
(
'
${posts[index].refModel!.name}
-
${posts[index].title}
'
,
style:
const
TextStyle
(
fontWeight:
FontWeight
.
bold
),
),
subtitle:
Row
(
children:
[
Text
(
Utils
.
getAgoTime
(
posts
[
index
].
createdAt
!)),
spacingWidget
(
10
,
SpaceDirection
.
horizontal
),
],
),
trailing:
const
Icon
(
Icons
.
chevron_right_rounded
,
size:
30
,
),
),
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
15
),
child:
Row
(
children:
[
postStatus
(
posts
[
index
].
status
),
if
(
posts
[
index
].
status
==
PostStatus
.
pending
)
Flexible
(
child:
ButtonBar
(
children:
[
FloatingActionButton
.
small
(
elevation:
0
,
backgroundColor:
Colors
.
red
,
heroTag:
'reject
$index
'
,
onPressed:
()
async
{
PostModel
post
=
posts
[
index
];
post
.
status
=
PostStatus
.
rejected
;
await
LoadingOverlay
.
of
(
context
)
.
during
(
pPost
.
changePostStatus
(
post
));
await
initialize
();
},
child:
const
Icon
(
Icons
.
close
)),
FloatingActionButton
.
small
(
elevation:
0
,
backgroundColor:
Colors
.
green
,
heroTag:
'approve
$index
'
,
onPressed:
()
async
{
PostModel
post
=
posts
[
index
];
post
.
status
=
PostStatus
.
approved
;
await
LoadingOverlay
.
of
(
context
)
.
during
(
pPost
.
changePostStatus
(
post
));
await
initialize
();
},
child:
const
Icon
(
Icons
.
done
),
),
],
),
)
],
),
)
],
),
),
)
else
SizedBox
(
height:
ScreenSize
.
height
-
(
ScreenSize
.
height
*
0.25
),
child:
Center
(
child:
Text
(
"No
${selectedStatus.description == PostStatus.all ? '' : selectedStatus.description}
posts found !"
,
),
),
)
],
),
),
),
);
}
Future
<
void
>
initialize
()
async
{
posts
=
await
LoadingOverlay
.
of
(
context
).
during
(
pPost
.
getAllPost
());
initialPosts
=
posts
;
statusList
=
[
EntityModel
(
id:
1
,
description:
PostStatus
.
all
),
EntityModel
(
id:
2
,
description:
PostStatus
.
pending
),
EntityModel
(
id:
3
,
description:
PostStatus
.
approved
),
EntityModel
(
id:
4
,
description:
PostStatus
.
rejected
),
];
selectedStatus
=
statusList
.
first
;
filterPosts
();
setState
(()
{});
}
void
filterPosts
()
{
posts
=
initialPosts
.
where
((
element
)
{
if
(
selectedStatus
.
description
==
PostStatus
.
all
)
{
return
true
;
}
else
{
return
element
.
status
==
selectedStatus
.
description
;
}
}).
toList
();
setState
(()
{});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment