You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/views/widgets/equipment/device_button.dart

100 lines
4.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/models/device/device.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart';
import 'package:test_sa/views/widgets/equipment/single_device_picker.dart';
class DeviceButton extends StatelessWidget {
final Function(Device) onDevicePick;
final Device device;
const DeviceButton({Key key, this.device, this.onDevicePick}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 0,
padding: EdgeInsets.symmetric(horizontal: 16, vertical: device == null ? 12 : 8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
),
foregroundColor: AColors.primaryColor,
backgroundColor: AColors.inputFieldBackgroundColor,
),
child: Row(
children: [
FaIcon(
FontAwesomeIcons.hardDrive,
size: 28,
color: AColors.black,
),
device == null
? Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6),
child: Text(
context.translation.pickDevice,
style: Theme.of(context).textTheme.subtitle1,
textScaleFactor: AppStyle.getScaleFactor(context),
textDirection: TextDirection.rtl,
textAlign: TextAlign.left,
),
),
)
: Expanded(
child: ListTile(
contentPadding: EdgeInsets.all(0),
title: Text(
"${context.translation.sn} : " + device.serialNumber,
style: Theme.of(context).textTheme.subtitle1,
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Divider(
color: Theme.of(context).textTheme.subtitle1.color,
),
Text(
"${context.translation.assetNumber} : ${device.number}",
style: Theme.of(context).textTheme.subtitle2,
),
Divider(
color: Theme.of(context).textTheme.subtitle1.color,
),
Text(
"${context.translation.assetName} : ${device.modelDefinition.assetName}",
style: Theme.of(context).textTheme.subtitle2,
),
Divider(
color: Theme.of(context).textTheme.subtitle1.color,
),
Text(
"${context.translation.brand} : ${device.modelDefinition.manufacturerName}",
style: Theme.of(context).textTheme.subtitle2,
),
Divider(
color: Theme.of(context).textTheme.subtitle1.color,
),
Text(
"${context.translation.model} : ${device.modelDefinition.modelName}",
style: Theme.of(context).textTheme.subtitle2,
),
],
),
)),
const Icon(Icons.keyboard_arrow_down, size: 28, color: AColors.grey3A),
],
),
onPressed: () async {
Device _device = await Navigator.of(context).pushNamed(SingleDevicePicker.id) as Device;
onDevicePick(_device);
});
}
}