From b750d603b57120a0267e68d686963630183d2f59 Mon Sep 17 00:00:00 2001 From: Aliaksei Tratseuski Date: Mon, 5 Feb 2024 14:16:26 +0400 Subject: [PATCH] refactor: service_page build cleanup --- lib/ui/pages/services/service_page.dart | 109 +++++++++--------------- 1 file changed, 40 insertions(+), 69 deletions(-) diff --git a/lib/ui/pages/services/service_page.dart b/lib/ui/pages/services/service_page.dart index 37f9515c..b51edb31 100644 --- a/lib/ui/pages/services/service_page.dart +++ b/lib/ui/pages/services/service_page.dart @@ -170,83 +170,54 @@ class ServiceStatusCard extends StatelessWidget { @override Widget build(final BuildContext context) { + late IconData icon; + late String buttonTitle; + switch (status) { case ServiceStatus.active: - return FilledCard( - child: ListTile( - leading: const Icon( - Icons.check_circle_outline, - size: 24, - ), - title: Text('service_page.status.active'.tr()), - ), - ); + icon = Icons.check_circle_outline; + buttonTitle = 'service_page.status.active'; + break; + case ServiceStatus.inactive: - return FilledCard( - tertiary: true, - child: ListTile( - leading: const Icon( - Icons.stop_circle_outlined, - size: 24, - ), - title: Text('service_page.status.inactive'.tr()), - ), - ); + icon = Icons.stop_circle_outlined; + buttonTitle = 'service_page.status.inactive'; + break; + case ServiceStatus.failed: - return FilledCard( - error: true, - child: ListTile( - leading: const Icon( - Icons.error_outline, - size: 24, - ), - title: Text('service_page.status.failed'.tr()), - ), - ); + icon = Icons.error_outline; + buttonTitle = 'service_page.status.failed'; + break; + case ServiceStatus.off: - return FilledCard( - tertiary: true, - child: ListTile( - leading: const Icon( - Icons.power_settings_new, - size: 24, - ), - title: Text('service_page.status.off'.tr()), - ), - ); + icon = Icons.power_settings_new; + buttonTitle = 'service_page.status.off'; + break; + case ServiceStatus.activating: - return FilledCard( - tertiary: true, - child: ListTile( - leading: const Icon( - Icons.restart_alt_outlined, - size: 24, - ), - title: Text('service_page.status.activating'.tr()), - ), - ); + icon = Icons.restart_alt_outlined; + buttonTitle = 'service_page.status.activating'; + break; + case ServiceStatus.deactivating: - return FilledCard( - tertiary: true, - child: ListTile( - leading: const Icon( - Icons.restart_alt_outlined, - size: 24, - ), - title: Text('service_page.status.deactivating'.tr()), - ), - ); + icon = Icons.restart_alt_outlined; + buttonTitle = 'service_page.status.deactivating'; + break; + case ServiceStatus.reloading: - return FilledCard( - tertiary: true, - child: ListTile( - leading: const Icon( - Icons.restart_alt_outlined, - size: 24, - ), - title: Text('service_page.status.reloading'.tr()), - ), - ); + icon = Icons.restart_alt_outlined; + buttonTitle = 'service_page.status.reloading'; } + + return FilledCard( + tertiary: true, + child: ListTile( + leading: Icon( + icon, + size: 24, + ), + title: Text(buttonTitle.tr()), + ), + ); } }