Initial Commit
This commit is contained in:
219
lib/widgets/service_card.dart
Normal file
219
lib/widgets/service_card.dart
Normal file
@@ -0,0 +1,219 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart' hide Colors, Divider, VerticalDivider;
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:proto_portal/scraper.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
|
||||
class ServiceCard extends StatelessWidget {
|
||||
final String type;
|
||||
final String time;
|
||||
final String diagram;
|
||||
final String customer;
|
||||
final String destination;
|
||||
final String operator;
|
||||
final String vrm;
|
||||
final GtiService? service;
|
||||
final GtiStation? station;
|
||||
final bool showActions;
|
||||
|
||||
// Constructor for individual fields
|
||||
ServiceCard({
|
||||
required this.type,
|
||||
required this.time,
|
||||
required this.diagram,
|
||||
required this.customer,
|
||||
required this.destination,
|
||||
required this.operator,
|
||||
required this.vrm,
|
||||
this.service,
|
||||
this.station,
|
||||
this.showActions = false,
|
||||
});
|
||||
|
||||
// Constructor that takes a GtiService
|
||||
ServiceCard.fromService({
|
||||
required GtiService service,
|
||||
GtiStation? station,
|
||||
bool showActions = false,
|
||||
}) : this.service = service,
|
||||
this.station = station,
|
||||
this.showActions = showActions,
|
||||
type = service.type,
|
||||
time = service.time,
|
||||
diagram = service.coach,
|
||||
customer = service.customer,
|
||||
destination = service.destination,
|
||||
operator = service.operator,
|
||||
vrm = service.vrm;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Convert type code to full word
|
||||
String typeLabel = type;
|
||||
if (type == 'D') {
|
||||
typeLabel = 'Departure';
|
||||
} else if (type == 'A') {
|
||||
typeLabel = 'Arrival';
|
||||
}
|
||||
|
||||
return OutlinedContainer(
|
||||
width: double.infinity,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 10,
|
||||
spreadRadius: 2)
|
||||
],
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
IntrinsicHeight(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(typeLabel,
|
||||
style: TextStyle(fontSize: 22))
|
||||
.textLarge,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
VerticalDivider(),
|
||||
SizedBox(
|
||||
width: 94,
|
||||
child: _keyvalueRow(
|
||||
key: "Time",
|
||||
value: time,
|
||||
),
|
||||
),
|
||||
VerticalDivider(),
|
||||
SizedBox(
|
||||
width: 130,
|
||||
child: _keyvalueRow(
|
||||
key: "Diagram",
|
||||
value: diagram,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Divider(),
|
||||
|
||||
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: _keyvalueRow(
|
||||
key: "Customer",
|
||||
value: customer,
|
||||
),
|
||||
),
|
||||
Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: _keyvalueRow(
|
||||
key: "Destination",
|
||||
value: destination,
|
||||
),
|
||||
),
|
||||
Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: IntrinsicHeight(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _keyvalueRow(
|
||||
key: "Operator",
|
||||
value: operator,
|
||||
),
|
||||
),
|
||||
VerticalDivider(),
|
||||
SizedBox(
|
||||
width: 120,
|
||||
child: _keyvalueRow(
|
||||
key: "VRM",
|
||||
value: vrm.isNotEmpty ? vrm : "N/A",
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (showActions) ...[
|
||||
Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ButtonGroup(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlineButton(
|
||||
onPressed: service != null && station != null
|
||||
? () {
|
||||
// Encode service as base64
|
||||
final serviceJson = jsonEncode(service!.toJson());
|
||||
final serviceBase64 = base64Encode(utf8.encode(serviceJson));
|
||||
|
||||
final stationJson = jsonEncode({
|
||||
'label': station!.label,
|
||||
'crs': station!.crs,
|
||||
});
|
||||
final stationBase64 = base64Encode(utf8.encode(stationJson));
|
||||
|
||||
GoRouter.of(context).push(
|
||||
Uri(
|
||||
path: '/audit',
|
||||
queryParameters: {
|
||||
'service': serviceBase64,
|
||||
'station': stationBase64,
|
||||
},
|
||||
).toString(),
|
||||
);
|
||||
}
|
||||
: null,
|
||||
child: Text("Audit"),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
onPressed: () {},
|
||||
child: Text("Depart"),
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _keyvalueRow({
|
||||
required String key,
|
||||
required String value,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(key).h4,
|
||||
|
||||
Text(value).small
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user