@ -7,14 +7,16 @@ class PermissionsListTile extends StatelessWidget {
final String permissionKey ;
final int permission ;
final String ? category ;
final void Function ( ) ? onTap ;
final void Function ( int ? level ) ? onChanged ;
final bool canEdit ;
const PermissionsListTile ( {
super . key ,
required this . permissionKey ,
required this . permission ,
this . category ,
this . onTap ,
required this . onChanged ,
required this . canEdit ,
} ) ;
String getLocalizedPowerLevelString ( BuildContext context ) {
@ -66,39 +68,32 @@ class PermissionsListTile extends StatelessWidget {
@ override
Widget build ( BuildContext context ) {
return ListTile (
onTap: onTap ,
leading: CircleAvatar (
backgroundColor: Theme . of ( context ) . scaffoldBackgroundColor ,
foregroundColor: Colors . grey ,
child: const Icon ( Icons . edit_attributes_outlined ) ,
) ,
title: Text ( getLocalizedPowerLevelString ( context ) ) ,
subtitle: Row (
children: [
Container (
padding: const EdgeInsets . all ( 4 ) ,
decoration: BoxDecoration (
color: Theme . of ( context ) . secondaryHeaderColor ,
borderRadius: BorderRadius . circular ( 8 ) ,
subtitle: Text (
L10n . of ( context ) ! . minimumPowerLevel ( permission . toString ( ) ) ,
) ,
trailing: DropdownButton < int > (
onChanged: canEdit ? onChanged : null ,
value: { 0 , 50 , 100 } . contains ( permission ) ? permission : null ,
items: [
DropdownMenuItem (
value: 0 ,
child: Text ( L10n . of ( context ) ! . user ) ,
) ,
DropdownMenuItem (
value: 50 ,
child: Text ( L10n . of ( context ) ! . moderator ) ,
) ,
child: Center (
child: Text ( permission . toString ( ) ) ,
DropdownMenuItem (
value: 100 ,
child: Text ( L10n . of ( context ) ! . admin ) ,
) ,
DropdownMenuItem (
value: null ,
child: Text ( L10n . of ( context ) ! . custom ) ,
) ,
const SizedBox ( width: 8 ) ,
Text ( permission . toLocalizedPowerLevelString ( context ) ) ,
] ,
) ,
) ;
}
}
extension on int {
String toLocalizedPowerLevelString ( BuildContext context ) {
return this = = 100
? L10n . of ( context ) ! . admin
: this > = 50
? L10n . of ( context ) ! . moderator
: L10n . of ( context ) ! . participant ;
}
}