mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-10-21 15:02:21 +02:00
refactor(extensions): share the extension health color and icon helpers
The detail page and the list page carried identical color mappings. Only color and icon move; each screen keeps its own label mapping.
This commit is contained in:
1 parent
fe29f304aa
commit
da2fc2c9c9
5 files changed
+48
-61
No files matched your search
@@ -1,8 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart'
|
||||
show CupertinoColors, CupertinoIcons, CupertinoTextField;
|
||||
import 'package:flutter/cupertino.dart' show CupertinoIcons, CupertinoTextField;
|
||||
import 'package:spotiflac_android/theme/mornye_theme.dart';
|
||||
import 'package:spotiflac_android/theme/mornye_icons.dart';
|
||||
import 'package:spotiflac_android/widgets/app_alert_dialog.dart';
|
||||
@@ -23,6 +22,7 @@ import 'package:spotiflac_android/widgets/app_icon.dart';
|
||||
import 'package:spotiflac_android/widgets/app_icon_button.dart';
|
||||
import 'package:spotiflac_android/widgets/app_loading_indicator.dart';
|
||||
import 'package:spotiflac_android/widgets/app_sliver_header.dart';
|
||||
import 'package:spotiflac_android/widgets/extension_health.dart';
|
||||
|
||||
part 'extension_detail_page_widgets.dart';
|
||||
|
||||
|
||||
@@ -186,43 +186,6 @@ class _CapabilityItem extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Color _healthStatusColor(BuildContext context, String status) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
switch (status) {
|
||||
case 'online':
|
||||
return context.isMornye
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: colorScheme.primary;
|
||||
case 'degraded':
|
||||
return colorScheme.tertiary;
|
||||
case 'offline':
|
||||
return colorScheme.error;
|
||||
default:
|
||||
return colorScheme.onSurfaceVariant;
|
||||
}
|
||||
}
|
||||
|
||||
IconData _healthStatusIcon(BuildContext context, String status) {
|
||||
if (context.isMornye) {
|
||||
return switch (status) {
|
||||
'online' => CupertinoIcons.check_mark_circled_solid,
|
||||
'degraded' => CupertinoIcons.exclamationmark_triangle,
|
||||
'offline' => CupertinoIcons.exclamationmark_circle,
|
||||
_ => CupertinoIcons.question_circle,
|
||||
};
|
||||
}
|
||||
switch (status) {
|
||||
case 'online':
|
||||
return Icons.check_circle;
|
||||
case 'degraded':
|
||||
return Icons.warning_amber_rounded;
|
||||
case 'offline':
|
||||
return Icons.error_outline;
|
||||
default:
|
||||
return Icons.help_outline;
|
||||
}
|
||||
}
|
||||
|
||||
String _healthStatusLabel(BuildContext context, String status) {
|
||||
switch (status) {
|
||||
case 'online':
|
||||
@@ -253,7 +216,7 @@ class _HealthSummaryItem extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final statusValue = status?.status ?? 'unknown';
|
||||
final color = _healthStatusColor(context, statusValue);
|
||||
final color = extensionHealthColor(context, statusValue);
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -262,7 +225,7 @@ class _HealthSummaryItem extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
AppIcon(_healthStatusIcon(context, statusValue), color: color),
|
||||
AppIcon(extensionHealthIcon(context, statusValue), color: color),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
@@ -324,7 +287,7 @@ class _HealthCheckItem extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final color = _healthStatusColor(context, check.status);
|
||||
final color = extensionHealthColor(context, check.status);
|
||||
final detailParts = <String>[
|
||||
_healthStatusLabel(context, check.status),
|
||||
if (check.httpStatus != null) 'HTTP ${check.httpStatus}',
|
||||
@@ -347,7 +310,7 @@ class _HealthCheckItem extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppIcon(_healthStatusIcon(context, check.status), color: color),
|
||||
AppIcon(extensionHealthIcon(context, check.status), color: color),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart' show CupertinoColors;
|
||||
import 'package:spotiflac_android/widgets/app_snack_bar.dart';
|
||||
import 'package:spotiflac_android/widgets/app_switch.dart';
|
||||
import 'package:spotiflac_android/widgets/extension_row.dart';
|
||||
@@ -25,6 +24,7 @@ import 'package:spotiflac_android/widgets/mornye_chrome.dart';
|
||||
import 'package:spotiflac_android/widgets/settings_group.dart';
|
||||
import 'package:spotiflac_android/widgets/home_feed_region_setting.dart';
|
||||
import 'package:spotiflac_android/widgets/app_sliver_header.dart';
|
||||
import 'package:spotiflac_android/widgets/extension_health.dart';
|
||||
|
||||
part 'extensions_page_widgets.dart';
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class _ExtensionItem extends StatelessWidget {
|
||||
: null;
|
||||
final serviceHealthColor = serviceHealthStatus == null
|
||||
? null
|
||||
: _extensionHealthColor(context, serviceHealthStatus);
|
||||
: extensionHealthColor(context, serviceHealthStatus);
|
||||
|
||||
return ExtensionRow(
|
||||
showDivider: showDivider,
|
||||
@@ -75,22 +75,6 @@ class _ExtensionItem extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
Color _extensionHealthColor(BuildContext context, String status) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
switch (status) {
|
||||
case 'online':
|
||||
return context.isMornye
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: colorScheme.primary;
|
||||
case 'degraded':
|
||||
return colorScheme.tertiary;
|
||||
case 'offline':
|
||||
return colorScheme.error;
|
||||
default:
|
||||
return colorScheme.onSurfaceVariant;
|
||||
}
|
||||
}
|
||||
|
||||
String _extensionHealthLabel(BuildContext context, String status) {
|
||||
switch (status) {
|
||||
case 'online':
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:spotiflac_android/theme/mornye_theme.dart';
|
||||
|
||||
Color extensionHealthColor(BuildContext context, String status) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
switch (status) {
|
||||
case 'online':
|
||||
return context.isMornye
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: colorScheme.primary;
|
||||
case 'degraded':
|
||||
return colorScheme.tertiary;
|
||||
case 'offline':
|
||||
return colorScheme.error;
|
||||
default:
|
||||
return colorScheme.onSurfaceVariant;
|
||||
}
|
||||
}
|
||||
|
||||
IconData extensionHealthIcon(BuildContext context, String status) {
|
||||
if (context.isMornye) {
|
||||
return switch (status) {
|
||||
'online' => CupertinoIcons.check_mark_circled_solid,
|
||||
'degraded' => CupertinoIcons.exclamationmark_triangle,
|
||||
'offline' => CupertinoIcons.exclamationmark_circle,
|
||||
_ => CupertinoIcons.question_circle,
|
||||
};
|
||||
}
|
||||
switch (status) {
|
||||
case 'online':
|
||||
return Icons.check_circle;
|
||||
case 'degraded':
|
||||
return Icons.warning_amber_rounded;
|
||||
case 'offline':
|
||||
return Icons.error_outline;
|
||||
default:
|
||||
return Icons.help_outline;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user