129 lines
3.8 KiB
Dart
129 lines
3.8 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/Screens/Devices/change_device_info_modal.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class DeviceElement extends StatefulWidget {
|
|
final DeviceDTO deviceDTO;
|
|
const DeviceElement({
|
|
Key? key,
|
|
required this.deviceDTO,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_DeviceElementState createState() => _DeviceElementState();
|
|
}
|
|
|
|
class _DeviceElementState extends State<DeviceElement> {
|
|
late DeviceDTO deviceDTO;
|
|
|
|
@override
|
|
void initState() {
|
|
deviceDTO = widget.deviceDTO;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
//Size size = MediaQuery.of(context).size;
|
|
return Stack(
|
|
children: [
|
|
Positioned(
|
|
top: 10,
|
|
right: 10,
|
|
child: Container(
|
|
width: 15,
|
|
height: 15,
|
|
decoration: BoxDecoration(
|
|
color: deviceDTO.connected! ? Colors.green : Colors.red,
|
|
shape: BoxShape.rectangle,
|
|
borderRadius: BorderRadius.circular(25.0),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kSecond,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 3,
|
|
offset: Offset(0, 1.5), // changes position of shadow
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 10,
|
|
left: 10,
|
|
child: Row(
|
|
children: [
|
|
AutoSizeText(
|
|
deviceDTO.name!,
|
|
style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w300),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
AutoSizeText(
|
|
deviceDTO.configuration != null ? deviceDTO.configuration! : "Aucune configuration",
|
|
style: new TextStyle(fontSize: 20),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Positioned(
|
|
bottom: 10,
|
|
right: 10,
|
|
child: IconButton(
|
|
icon: Icon(Icons.edit),
|
|
onPressed: () {
|
|
showChangeInfo(
|
|
"Mettre à jour le device",
|
|
deviceDTO,
|
|
(DeviceDTO outputDevice) {
|
|
// For refresh
|
|
setState(() {
|
|
//print("output");
|
|
//print(outputDevice);
|
|
deviceDTO = outputDevice;
|
|
// Update device main info
|
|
updateMainInfos(deviceDTO, appContext);
|
|
});
|
|
},
|
|
1,
|
|
context,
|
|
appContext
|
|
);
|
|
},
|
|
color: kPrimaryColor,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<DeviceDTO?> updateMainInfos(DeviceDTO deviceToUpdate, dynamic appContext) async {
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
//print(deviceToUpdate);
|
|
DeviceDTO? device = await managerAppContext.clientAPI!.deviceApi!.deviceUpdateMainInfos(deviceToUpdate);
|
|
//print(device);
|
|
return device;
|
|
}
|
|
|
|
} |