selfprivacy.org.app/lib/ui/components/jobs_content/server_job_card.dart

96 lines
3 KiB
Dart
Raw Normal View History

2022-08-26 02:34:25 +00:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/logic/models/json/server_job.dart';
import 'package:selfprivacy/ui/components/brand_linear_indicator/brand_linear_indicator.dart';
class ServerJobCard extends StatelessWidget {
const ServerJobCard({
required this.serverJob,
super.key,
2022-08-26 02:34:25 +00:00
});
final ServerJob serverJob;
@override
2022-09-18 17:56:55 +00:00
Widget build(final BuildContext context) {
Color color;
IconData icon;
switch (serverJob.status) {
case JobStatusEnum.created:
color = Theme.of(context).colorScheme.secondary;
icon = Icons.query_builder_outlined;
break;
case JobStatusEnum.running:
color = Theme.of(context).colorScheme.tertiary;
icon = Icons.pending_outlined;
break;
case JobStatusEnum.finished:
color = Theme.of(context).colorScheme.primary;
icon = Icons.check_circle_outline;
break;
case JobStatusEnum.error:
color = Theme.of(context).colorScheme.error;
icon = Icons.error_outline;
break;
}
final String? statusString =
serverJob.error ?? serverJob.result ?? serverJob.statusText;
return GestureDetector(
child: Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
2022-08-26 02:34:25 +00:00
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2022-09-18 17:56:55 +00:00
Row(
crossAxisAlignment: CrossAxisAlignment.start,
2022-09-18 22:11:26 +00:00
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2022-09-18 17:56:55 +00:00
children: [
2022-09-18 22:11:26 +00:00
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
serverJob.name,
style: Theme.of(context).textTheme.bodyMedium,
),
Text(
serverJob.description,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
2022-09-18 17:56:55 +00:00
),
Icon(
icon,
color: color,
),
],
2022-08-26 02:34:25 +00:00
),
const SizedBox(height: 8),
BrandLinearIndicator(
value: serverJob.progress == null
? 0.0
: serverJob.progress! / 100.0,
2022-09-18 17:56:55 +00:00
color: color,
2022-08-26 02:34:25 +00:00
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
height: 7.0,
),
const SizedBox(height: 8),
2022-09-18 17:56:55 +00:00
if (statusString != null)
Text(
statusString,
style: Theme.of(context).textTheme.labelSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
),
2022-08-26 02:34:25 +00:00
],
),
),
2022-09-18 17:56:55 +00:00
),
);
}
2022-08-26 02:34:25 +00:00
}