Skip to content

Commit

Permalink
build: sonar high issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
cevheri committed Nov 20, 2024
1 parent deaa276 commit a165dec
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 73 deletions.
12 changes: 6 additions & 6 deletions lib/data/http_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class HttpUtils {
body: messageBody,
encoding: Encoding.getByName(UTF8),
)
.timeout(Duration(seconds: timeout));
.timeout(const Duration(seconds: timeout));

checkUnauthorizedAccess(endpoint, response);
} on SocketException catch (se) {
Expand All @@ -143,7 +143,7 @@ class HttpUtils {
Uri.parse('${ProfileConstants.api}$endpoint'),
headers: headers,
)
.timeout(Duration(seconds: timeout));
.timeout(const Duration(seconds: timeout));
checkUnauthorizedAccess(endpoint, response);
return response;
} on SocketException {
Expand All @@ -159,7 +159,7 @@ class HttpUtils {
// try {
// var result = await http
// .get(Uri.parse('${ProfileConstants.api}$endpoint'), headers: headers)
// .timeout(Duration(seconds: timeout));
// .timeout(cont Duration(seconds: timeout));
// debugPrint(result.headers.toString());
// if (result.statusCode == 401) {
// throw UnauthorizedException(result.headers.toString());
Expand Down Expand Up @@ -191,7 +191,7 @@ class HttpUtils {
try {
response = await http
.put(Uri.parse('${ProfileConstants.api}$endpoint'), headers: headers, body: json, encoding: Encoding.getByName(UTF8))
.timeout(Duration(seconds: timeout));
.timeout(const Duration(seconds: timeout));
checkUnauthorizedAccess(endpoint, response);
} on SocketException {
throw FetchDataException(noInternetConnectionError);
Expand All @@ -217,7 +217,7 @@ class HttpUtils {
try {
response = await http
.patch(Uri.parse('${ProfileConstants.api}$endpoint'), headers: headers, body: json, encoding: Encoding.getByName(UTF8))
.timeout(Duration(seconds: timeout));
.timeout(const Duration(seconds: timeout));
checkUnauthorizedAccess(endpoint, response);
} on SocketException {
throw FetchDataException(noInternetConnectionError);
Expand All @@ -231,7 +231,7 @@ class HttpUtils {
if (!ProfileConstants.isProduction) return await mockRequest('DELETE', endpoint);
var headers = await HttpUtils.headers();
try {
var response = await http.delete(Uri.parse('${ProfileConstants.api}$endpoint'), headers: headers).timeout(Duration(seconds: timeout));
var response = await http.delete(Uri.parse('${ProfileConstants.api}$endpoint'), headers: headers).timeout(const Duration(seconds: timeout));
checkUnauthorizedAccess(endpoint, response);
return response;
} on SocketException {
Expand Down
126 changes: 59 additions & 67 deletions lib/presentation/common_widgets/drawer/drawer_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,81 +71,73 @@ class ApplicationDrawer extends StatelessWidget {
physics: ClampingScrollPhysics(),
itemBuilder: (context, index) {
if (SecurityUtils.isCurrentUserAdmin() && parentMenus[index].name == 'userManagement') {
List<Menu> sublistMenu = state.menus.where((element) => element.parent?.id == parentMenus[index].id).toList();
sublistMenu.sort((a, b) => a.orderPriority.compareTo(b.orderPriority));
return ExpansionTileCard(
trailing: sublistMenu.isNotEmpty
? Icon(
Icons.keyboard_arrow_down,
)
: Icon(
Icons.keyboard_arrow_right,
),
onExpansionChanged: (value) {
if (value) {
if (sublistMenu.isEmpty) {
Navigator.pop(context);
Navigator.pushNamed(context, parentMenus[index].url);
}
}
},
elevation: 0,
isThreeLine: false,
initiallyExpanded: false,
leading: Icon(
String2Icon.getIconDataFromString(parentMenus[index].icon),
),
title: Text(
S.of(context).translate_menu_title(parentMenus[index].name),
style: Theme.of(context).textTheme.bodyLarge,
),
children: [
Padding(
padding: EdgeInsets.only(left: 20),
child: ListView.builder(
itemCount: sublistMenu.length,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemBuilder: (context, index) {
return ListTile(
leading: Icon(
String2Icon.getIconDataFromString(sublistMenu[index].icon),
),
title: Text(
S.of(context).translate_menu_title(sublistMenu[index].name),
style: Theme.of(context).textTheme.bodyMedium,
),
onTap: () {
Navigator.pop(context);
Navigator.pushNamed(context, sublistMenu[index].url);
},
);
},
),
),
],
);
return _bildMenuListUserManagement(state, parentMenus, index, context);
} else if (SecurityUtils.isCurrentUserAdmin() && parentMenus[index].name == 'userManagement') {
return Container();
} else {
return ListTile(
leading: Icon(
String2Icon.getIconDataFromString(parentMenus[index].icon),
),
title: Text(
S.of(context).translate_menu_title(parentMenus[index].name),
style: Theme.of(context).textTheme.bodyMedium,
),
onTap: () {
Navigator.pop(context);
Navigator.pushNamed(context, parentMenus[index].url);
},
);
return _buildMenuListListTile(parentMenus, index, context);
}
},
);
}

ListTile _buildMenuListListTile(List<dynamic> parentMenus, int index, BuildContext context) {
return ListTile(
leading: Icon(String2Icon.getIconDataFromString(parentMenus[index].icon)),
title: Text(S.of(context).translate_menu_title(parentMenus[index].name), style: Theme.of(context).textTheme.bodyMedium),
onTap: () {
Navigator.pop(context);
Navigator.pushNamed(context, parentMenus[index].url);
},
);
}

ExpansionTileCard _bildMenuListUserManagement(DrawerState state, List<dynamic> parentMenus, int index, BuildContext context) {
List<Menu> sublistMenu = state.menus.where((element) => element.parent?.id == parentMenus[index].id).toList();
sublistMenu.sort((a, b) => a.orderPriority.compareTo(b.orderPriority));
return ExpansionTileCard(
trailing: sublistMenu.isNotEmpty ? Icon(Icons.keyboard_arrow_down) : Icon(Icons.keyboard_arrow_right),
onExpansionChanged: (value) {
if (value) {
if (sublistMenu.isEmpty) {
Navigator.pop(context);
Navigator.pushNamed(context, parentMenus[index].url);
}
}
},
elevation: 0,
isThreeLine: false,
initiallyExpanded: false,
leading: Icon(String2Icon.getIconDataFromString(parentMenus[index].icon)),
title: Text(S.of(context).translate_menu_title(parentMenus[index].name), style: Theme.of(context).textTheme.bodyLarge),
children: [
Padding(
padding: EdgeInsets.only(left: 20),
child: ListView.builder(
itemCount: sublistMenu.length,
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemBuilder: (context, index) {
return ListTile(
leading: Icon(
String2Icon.getIconDataFromString(sublistMenu[index].icon),
),
title: Text(
S.of(context).translate_menu_title(sublistMenu[index].name),
style: Theme.of(context).textTheme.bodyMedium,
),
onTap: () {
Navigator.pop(context);
Navigator.pushNamed(context, sublistMenu[index].url);
},
);
},
),
),
],
);
}

_buildBlocListener(BuildContext context) {
return [
BlocListener<DrawerBloc, DrawerState>(
Expand Down

0 comments on commit a165dec

Please sign in to comment.