@ -1,4 +1,5 @@
import ' package:Envelope/models/friends.dart ' ;
import ' package:Envelope/utils/encryption/crypto_utils.dart ' ;
import ' package:Envelope/views/main/conversation/create_add_users.dart ' ;
import ' package:flutter/material.dart ' ;
@ -31,111 +32,113 @@ class _ConversationSettingsState extends State<ConversationSettings> {
@ override
Widget build ( BuildContext context ) {
return Scaffold (
appBar: AppBar (
elevation: 0 ,
automaticallyImplyLeading: false ,
flexibleSpace: SafeArea (
child: Container (
padding: const EdgeInsets . only ( right: 16 ) ,
child: Row (
children: < Widget > [
IconButton (
onPressed: ( ) {
Navigator . pop ( context ) ;
} ,
icon: const Icon ( Icons . arrow_back ) ,
) ,
const SizedBox ( width: 2 , ) ,
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisAlignment: MainAxisAlignment . center ,
children: < Widget > [
Text (
widget . conversation . name + " Settings " ,
style: const TextStyle (
fontSize: 16 ,
fontWeight: FontWeight . w600
) ,
) ,
] ,
) ,
) ,
] ,
) ,
appBar: AppBar (
elevation: 0 ,
automaticallyImplyLeading: false ,
flexibleSpace: SafeArea (
child: Container (
padding: const EdgeInsets . only ( right: 16 ) ,
child: Row (
children: < Widget > [
IconButton (
onPressed: ( ) {
Navigator . pop ( context ) ;
} ,
icon: const Icon ( Icons . arrow_back ) ,
) ,
const SizedBox ( width: 2 , ) ,
Expanded (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisAlignment: MainAxisAlignment . center ,
children: < Widget > [
Text (
widget . conversation . name + " Settings " ,
style: const TextStyle (
fontSize: 16 ,
fontWeight: FontWeight . w600
) ,
) ,
] ,
) ,
) ,
] ,
) ,
) ,
) ,
body: Padding (
padding: const EdgeInsets . all ( 15 ) ,
child: Column (
children: < Widget > [
const SizedBox ( height: 30 ) ,
conversationName ( ) ,
const SizedBox ( height: 25 ) ,
widget . conversation . admin ?
sectionTitle ( ' Settings ' ) :
const SizedBox . shrink ( ) ,
widget . conversation . admin ?
settings ( ) :
const SizedBox . shrink ( ) ,
widget . conversation . admin ?
const SizedBox ( height: 25 ) :
const SizedBox . shrink ( ) ,
sectionTitle ( ' Members ' , showUsersAdd: true ) ,
usersList ( ) ,
const SizedBox ( height: 25 ) ,
myAccess ( ) ,
] ,
) ,
body: Padding (
padding: const EdgeInsets . all ( 15 ) ,
child: SingleChildScrollView (
child: Column (
children: < Widget > [
const SizedBox ( height: 30 ) ,
conversationName ( ) ,
const SizedBox ( height: 25 ) ,
widget . conversation . admin ?
sectionTitle ( ' Settings ' ) :
const SizedBox . shrink ( ) ,
widget . conversation . admin ?
settings ( ) :
const SizedBox . shrink ( ) ,
widget . conversation . admin ?
const SizedBox ( height: 25 ) :
const SizedBox . shrink ( ) ,
sectionTitle ( ' Members ' , showUsersAdd: true ) ,
usersList ( ) ,
const SizedBox ( height: 25 ) ,
myAccess ( ) ,
] ,
) ,
) ,
) ,
) ;
}
Widget conversationName ( ) {
return Row (
children: < Widget > [
const CustomCircleAvatar (
icon: Icon ( Icons . people , size: 40 ) ,
imagePath: null , / / TODO: Add image here
radius: 30 ,
) ,
const SizedBox ( width: 10 ) ,
Text (
widget . conversation . name ,
style: const TextStyle (
fontSize: 25 ,
fontWeight: FontWeight . w500 ,
) ,
children: < Widget > [
const CustomCircleAvatar (
icon: Icon ( Icons . people , size: 40 ) ,
imagePath: null , / / TODO: Add image here
radius: 30 ,
) ,
const SizedBox ( width: 10 ) ,
Text (
widget . conversation . name ,
style: const TextStyle (
fontSize: 25 ,
fontWeight: FontWeight . w500 ,
) ,
widget . conversation . admin ? IconButton (
iconSize: 20 ,
icon: const Icon ( Icons . edit ) ,
padding: const EdgeInsets . all ( 5.0 ) ,
splashRadius: 25 ,
onPressed: ( ) {
Navigator . of ( context ) . push (
MaterialPageRoute ( builder: ( context ) = > ConversationEditDetails (
saveCallback: ( String conversationName ) async {
widget . conversation . name = conversationName ;
) ,
widget . conversation . admin ? IconButton (
iconSize: 20 ,
icon: const Icon ( Icons . edit ) ,
padding: const EdgeInsets . all ( 5.0 ) ,
splashRadius: 25 ,
onPressed: ( ) {
Navigator . of ( context ) . push (
MaterialPageRoute ( builder: ( context ) = > ConversationEditDetails (
saveCallback: ( String conversationName ) async {
widget . conversation . name = conversationName ;
final db = await getDatabaseConnection ( ) ;
db . update (
' conversations ' ,
widget . conversation . toMap ( ) ,
where: ' id = ? ' ,
whereArgs: [ widget . conversation . id ] ,
) ;
final db = await getDatabaseConnection ( ) ;
db . update (
' conversations ' ,
widget . conversation . toMap ( ) ,
where: ' id = ? ' ,
whereArgs: [ widget . conversation . id ] ,
) ;
await updateConversation ( widget . conversation , includeUsers: true ) ;
setState ( ( ) { } ) ;
Navigator . pop ( context ) ;
} ,
conversation: widget . conversation ,
) ) ,
) . then ( onGoBack ) ;
} ,
) : const SizedBox . shrink ( ) ,
await updateConversation ( widget . conversation , includeUsers: true ) ;
setState ( ( ) { } ) ;
Navigator . pop ( context ) ;
} ,
conversation: widget . conversation ,
) ) ,
) . then ( onGoBack ) ;
} ,
) : const SizedBox . shrink ( ) ,
] ,
) ;
}
@ -155,24 +158,24 @@ class _ConversationSettingsState extends State<ConversationSettings> {
Widget myAccess ( ) {
return Align (
alignment: Alignment . centerLeft ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . stretch ,
children: [
TextButton . icon (
label: const Text (
' Leave Conversation ' ,
style: TextStyle ( fontSize: 16 )
) ,
icon: const Icon ( Icons . exit_to_app ) ,
style: const ButtonStyle (
alignment: Alignment . centerLeft ,
) ,
onPressed: ( ) {
print ( ' Leave Group ' ) ;
}
alignment: Alignment . centerLeft ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . stretch ,
children: [
TextButton . icon (
label: const Text (
' Leave Conversation ' ,
style: TextStyle ( fontSize: 16 )
) ,
icon: const Icon ( Icons . exit_to_app ) ,
style: const ButtonStyle (
alignment: Alignment . centerLeft ,
) ,
] ,
onPressed: ( ) {
print ( ' Leave Group ' ) ;
}
) ,
] ,
) ,
) ;
}
@ -194,29 +197,29 @@ class _ConversationSettingsState extends State<ConversationSettings> {
) ,
) ,
! showUsersAdd ?
const SizedBox . shrink ( ) :
IconButton (
icon: const Icon ( Icons . add ) ,
padding: const EdgeInsets . all ( 0 ) ,
onPressed: ( ) async {
List < Friend > friends = await unselectedFriends ( ) ;
Navigator . of ( context ) . push (
MaterialPageRoute ( builder: ( context ) = > ConversationAddFriendsList (
friends: friends ,
saveCallback: ( List < Friend > selectedFriends ) async {
addUsersToConversation (
widget . conversation ,
selectedFriends ,
) ;
const SizedBox . shrink ( ) :
IconButton (
icon: const Icon ( Icons . add ) ,
padding: const EdgeInsets . all ( 0 ) ,
onPressed: ( ) async {
List < Friend > friends = await unselectedFriends ( ) ;
Navigator . of ( context ) . push (
MaterialPageRoute ( builder: ( context ) = > ConversationAddFriendsList (
friends: friends ,
saveCallback: ( List < Friend > selectedFriends ) async {
addUsersToConversation (
widget . conversation ,
selectedFriends ,
) ;
await updateConversation ( widget . conversation , includeUsers: true ) ;
await getUsers ( ) ;
Navigator . pop ( context ) ;
} ,
) )
) ;
} ,
) ,
await updateConversation ( widget . conversation , includeUsers: true ) ;
await getUsers ( ) ;
Navigator . pop ( context ) ;
} ,
) )
) ;
} ,
) ,
] ,
)
)
@ -225,64 +228,65 @@ class _ConversationSettingsState extends State<ConversationSettings> {
Widget settings ( ) {
return Align (
alignment: Alignment . centerLeft ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . stretch ,
children: [
const SizedBox ( height: 5 ) ,
TextButton . icon (
label: const Text (
' Disappearing Messages ' ,
style: TextStyle ( fontSize: 16 )
) ,
icon: const Icon ( Icons . timer ) ,
style: ButtonStyle (
alignment: Alignment . centerLeft ,
foregroundColor: MaterialStateProperty . resolveWith < Color > (
( Set < MaterialState > states ) {
return Theme . of ( context ) . colorScheme . onBackground ;
} ,
)
) ,
onPressed: ( ) {
print ( ' Disappearing Messages ' ) ;
}
alignment: Alignment . centerLeft ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . stretch ,
children: [
const SizedBox ( height: 5 ) ,
TextButton . icon (
label: const Text (
' Disappearing Messages ' ,
style: TextStyle ( fontSize: 16 )
) ,
TextButton . icon (
label: const Text (
' Permissions ' ,
style: TextStyle ( fontSize: 16 )
) ,
icon: const Icon ( Icons . lock ) ,
style: ButtonStyle (
alignment: Alignment . centerLeft ,
foregroundColor: MaterialStateProperty . resolveWith < Color > (
( Set < MaterialState > states ) {
return Theme . of ( context ) . colorScheme . onBackground ;
} ,
)
) ,
onPressed: ( ) {
print ( ' Permissions ' ) ;
}
icon: const Icon ( Icons . timer ) ,
style: ButtonStyle (
alignment: Alignment . centerLeft ,
foregroundColor: MaterialStateProperty . resolveWith < Color > (
( Set < MaterialState > states ) {
return Theme . of ( context ) . colorScheme . onBackground ;
} ,
)
) ,
] ,
onPressed: ( ) {
print ( ' Disappearing Messages ' ) ;
}
) ,
TextButton . icon (
label: const Text (
' Permissions ' ,
style: TextStyle ( fontSize: 16 )
) ,
icon: const Icon ( Icons . lock ) ,
style: ButtonStyle (
alignment: Alignment . centerLeft ,
foregroundColor: MaterialStateProperty . resolveWith < Color > (
( Set < MaterialState > states ) {
return Theme . of ( context ) . colorScheme . onBackground ;
} ,
)
) ,
onPressed: ( ) {
print ( ' Permissions ' ) ;
}
) ,
] ,
) ,
) ;
}
Widget usersList ( ) {
return ListView . builder (
itemCount: users . length ,
shrinkWrap: true ,
padding: const EdgeInsets . only ( top: 5 , bottom: 0 ) ,
itemBuilder: ( context , i ) {
return ConversationSettingsUserListItem (
user: users [ i ] ,
isAdmin: widget . conversation . admin ,
profile: profile ! , / / TODO: Fix this
) ;
}
itemCount: users . length ,
shrinkWrap: true ,
padding: const EdgeInsets . only ( top: 5 , bottom: 0 ) ,
physics: const NeverScrollableScrollPhysics ( ) ,
itemBuilder: ( context , i ) {
return ConversationSettingsUserListItem (
user: users [ i ] ,
isAdmin: widget . conversation . admin ,
profile: profile ! , / / TODO: Fix this
) ;
}
) ;
}
@ -291,8 +295,8 @@ class _ConversationSettingsState extends State<ConversationSettings> {
List < String > notInArgs = [ ] ;
for ( var user in users ) {
notInArgs . add ( user . userId ) ;
}
notInArgs . add ( user . userId ) ;
}
final List < Map < String , dynamic > > maps = await db . query (
' friends ' ,
@ -307,7 +311,7 @@ class _ConversationSettingsState extends State<ConversationSettings> {
userId: maps [ i ] [ ' user_id ' ] ,
friendId: maps [ i ] [ ' friend_id ' ] ,
friendSymmetricKey: maps [ i ] [ ' symmetric_key ' ] ,
asymmetricPublicKey: maps [ i ] [ ' asymmetric_public_key ' ] ,
publicKey: CryptoUtils . rsaPublicKeyFromPem ( maps [ i ] [ ' asymmetric_public_key ' ] ) ,
acceptedAt: maps [ i ] [ ' accepted_at ' ] ,
username: maps [ i ] [ ' username ' ] ,
) ;