86 lines
3.4 KiB
Dart
86 lines
3.4 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Components/common_loader.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/Screens/Devices/device_element.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 AppConfigurationLinkScreen extends StatefulWidget {
|
|
AppConfigurationLinkScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_AppConfigurationLinkScreenState createState() => _AppConfigurationLinkScreenState();
|
|
}
|
|
|
|
class _AppConfigurationLinkScreenState extends State<AppConfigurationLinkScreen> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
Size size = MediaQuery.of(context).size;
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
return Container(
|
|
child: Align(
|
|
alignment: AlignmentDirectional.topCenter,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
FutureBuilder(
|
|
future: getAppConfigurationLink(appContext),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
return GridView.builder(
|
|
shrinkWrap: true,
|
|
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6),
|
|
itemCount: snapshot.data.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(15),
|
|
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
|
|
child: Align(
|
|
alignment: Alignment.center,
|
|
child: DeviceElement(deviceDTO: snapshot.data[index]), //getElement()
|
|
),
|
|
);
|
|
}
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
return Text("No data");
|
|
} else {
|
|
return Center(
|
|
child: Container(
|
|
height: size.height * 0.2,
|
|
child: CommonLoader()
|
|
)
|
|
);
|
|
}
|
|
}
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> updateMainInfos(DeviceDTO deviceToUpdate, dynamic appContext) async {
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
await managerAppContext.clientAPI!.deviceApi!.deviceUpdateMainInfos(deviceToUpdate);
|
|
}
|
|
|
|
Future<List<AppConfigurationLinkDTO>?> getAppConfigurationLink(AppContext appContext) async {
|
|
List<DeviceDTO>? devices = await (appContext.getContext() as ManagerAppContext).clientAPI!.apiApi!.deviceGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId);
|
|
//print("number of devices " + devices.length.toString());
|
|
|
|
if(devices != null) {
|
|
devices.forEach((element) {
|
|
//print(element);
|
|
});
|
|
}
|
|
|
|
return devices;
|
|
}
|