Bugs fixed

This commit is contained in:
Juan Gilsanz Polo 2023-11-15 18:16:43 +01:00
parent c1950fdc2b
commit 1ea71265e2
6 changed files with 54 additions and 36 deletions

View file

@ -76,7 +76,7 @@ class DhcpStatus {
v6: json["v6"] != null ? IpVersion.fromJson(json["v6"]) : null, v6: json["v6"] != null ? IpVersion.fromJson(json["v6"]) : null,
leases: List<Lease>.from(json["leases"].map((x) => Lease.fromJson(x))), leases: List<Lease>.from(json["leases"].map((x) => Lease.fromJson(x))),
staticLeases: List<Lease>.from(json["static_leases"].map((x) => Lease.fromJson(x))), staticLeases: List<Lease>.from(json["static_leases"].map((x) => Lease.fromJson(x))),
enabled: json["enabled"], enabled: json["enabled"] ?? false,
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {

View file

@ -132,7 +132,7 @@ class _FiltersListState extends State<FiltersList> {
TextButton.icon( TextButton.icon(
onPressed: () async { onPressed: () async {
final result = await filteringProvider.fetchFilters(); final result = await filteringProvider.fetchFilters();
if (result == false) { if (result == false && mounted) {
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.errorLoadFilters, label: AppLocalizations.of(context)!.errorLoadFilters,

View file

@ -70,7 +70,7 @@ class _ClientsListState extends State<ClientsList> {
Future refetchClients() async { Future refetchClients() async {
final result = await clientsProvider.fetchClients(); final result = await clientsProvider.fetchClients();
if (result == false) { if (result == false && mounted) {
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.clientsNotLoaded, label: AppLocalizations.of(context)!.clientsNotLoaded,

View file

@ -24,6 +24,7 @@ class AdvancedSettings extends StatelessWidget {
required Future Function(bool) function required Future Function(bool) function
}) async { }) async {
final result = await function(newStatus); final result = await function(newStatus);
if (!context.mounted) return;
if (result == true) { if (result == true) {
showSnacbkar( showSnacbkar(
appConfigProvider: appConfigProvider, appConfigProvider: appConfigProvider,

View file

@ -1330,55 +1330,68 @@ class ApiClient {
} }
Future getDhcpData() async { Future getDhcpData() async {
final result = await Future.wait([ try {
apiRequest( final result = await Future.wait([
urlPath: '/dhcp/interfaces', apiRequest(
method: 'get', urlPath: '/dhcp/interfaces',
server: server, method: 'get',
type: 'get_dhcp_data' server: server,
), type: 'get_dhcp_data'
apiRequest( ),
urlPath: '/dhcp/status', apiRequest(
method: 'get', urlPath: '/dhcp/status',
server: server, method: 'get',
type: 'get_dhcp_data' server: server,
), type: 'get_dhcp_data'
]); ),
]);
if (result[0]['hasResponse'] == true && result[1]['hasResponse'] == true) { if (result[0]['hasResponse'] == true && result[1]['hasResponse'] == true) {
if (result[0]['statusCode'] == 200 && result[1]['statusCode'] == 200) { if (result[0]['statusCode'] == 200 && result[1]['statusCode'] == 200) {
List<NetworkInterface> interfaces = List<NetworkInterface>.from(jsonDecode(result[0]['body']).entries.map((entry) => NetworkInterface.fromJson(entry.value))); List<NetworkInterface> interfaces = List<NetworkInterface>.from(jsonDecode(result[0]['body']).entries.map((entry) => NetworkInterface.fromJson(entry.value)));
return { return {
'result': 'success', 'result': 'success',
'data': DhcpModel( 'data': DhcpModel(
networkInterfaces: interfaces, networkInterfaces: interfaces,
dhcpStatus: DhcpStatus.fromJson(jsonDecode(result[1]['body'])) dhcpStatus: DhcpStatus.fromJson(jsonDecode(result[1]['body']))
) )
}; };
}
else {
return {
'result': 'error',
'log': AppLog(
type: 'get_dhcp_data',
dateTime: DateTime.now(),
message: 'error_code_not_expected',
statusCode: result.map((res) => res['statusCode'] ?? 'null').toString(),
resBody: result.map((res) => res['body'] ?? 'null').toString(),
)
};
}
} }
else { else {
return { return {
'result': 'error', 'result': 'error',
'log': AppLog( 'log': AppLog(
type: 'get_dhcp_data', type: 'get_dhpc_data',
dateTime: DateTime.now(), dateTime: DateTime.now(),
message: 'error_code_not_expected', message: [result[0]['log'].message, result[1]['log'].message].toString(),
statusCode: result.map((res) => res['statusCode'] ?? 'null').toString(), statusCode: result.map((res) => res['statusCode'] ?? 'null').toString(),
resBody: result.map((res) => res['body'] ?? 'null').toString(), resBody: result.map((res) => res['body'] ?? 'null').toString(),
) )
}; };
} }
} } catch (e) {
else { Sentry.captureException(e);
return { return {
'result': 'error', 'result': 'error',
'log': AppLog( 'log': AppLog(
type: 'get_dhpc_data', type: 'get_dhpc_data',
dateTime: DateTime.now(), dateTime: DateTime.now(),
message: [result[0]['log'].message, result[1]['log'].message].toString(), message: 'error_code_not_expected',
statusCode: result.map((res) => res['statusCode'] ?? 'null').toString(), resBody: e.toString(),
resBody: result.map((res) => res['body'] ?? 'null').toString(),
) )
}; };
} }

View file

@ -153,7 +153,9 @@ class _LayoutState extends State<Layout> with WidgetsBindingObserver {
child: child, child: child,
) )
), ),
child: screens[appConfigProvider.selectedScreen].child, child: appConfigProvider.selectedScreen < screens.length
? screens[appConfigProvider.selectedScreen].child
: screens[0].child,
), ),
), ),
], ],
@ -177,7 +179,9 @@ class _LayoutState extends State<Layout> with WidgetsBindingObserver {
child: child, child: child,
) )
), ),
child: screens[appConfigProvider.selectedScreen].child, child: appConfigProvider.selectedScreen < screens.length
? screens[appConfigProvider.selectedScreen].child
: screens[0].child,
), ),
bottomNavigationBar: NavigationBar( bottomNavigationBar: NavigationBar(
selectedIndex: (serversProvider.selectedServer == null || serversProvider.apiClient == null) && appConfigProvider.selectedScreen > 1 selectedIndex: (serversProvider.selectedServer == null || serversProvider.apiClient == null) && appConfigProvider.selectedScreen > 1