342 lines
12 KiB
Dart
342 lines
12 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/l10n/app_localizations.dart';
|
|
import 'package:manager_app/Components/common_loader.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/Screens/Applications/app_configuration_link_screen.dart';
|
|
import 'package:manager_app/Screens/Kiosk_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 KioskScreen extends StatefulWidget {
|
|
final ApplicationInstanceDTO applicationInstanceDTO;
|
|
KioskScreen({Key? key, required this.applicationInstanceDTO}) : super(key: key);
|
|
|
|
@override
|
|
_KioskScreenState createState() => _KioskScreenState();
|
|
}
|
|
|
|
class _KioskScreenState extends State<KioskScreen> {
|
|
@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: [
|
|
if(managerAppContext.pinCode != null)
|
|
Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: AutoSizeText(
|
|
AppLocalizations.of(context)!.pinCode(managerAppContext.pinCode.toString()),
|
|
style: TextStyle(fontSize: 25.0, fontWeight: FontWeight.w300),
|
|
maxLines: 2,
|
|
maxFontSize: 25.0,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
Column(
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(AppLocalizations.of(context)!.tablets),
|
|
)
|
|
),
|
|
FutureBuilder(
|
|
future: getAppConfigurationLink(appContext, widget.applicationInstanceDTO),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
|
|
List<AppConfigurationLinkDTO>? appConfigurationLinks = snapshot.data;
|
|
|
|
if (snapshot.connectionState == ConnectionState.done && appConfigurationLinks != null) {
|
|
return GridView.builder(
|
|
shrinkWrap: true,
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
maxCrossAxisExtent: 220,
|
|
childAspectRatio: 1.5,
|
|
mainAxisSpacing: 10,
|
|
crossAxisSpacing: 10,
|
|
),
|
|
itemCount: appConfigurationLinks.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return _DeviceCard(
|
|
deviceLink: appConfigurationLinks[index],
|
|
);
|
|
}
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none || appConfigurationLinks == null) {
|
|
return Text(AppLocalizations.of(context)!.noData);
|
|
} else {
|
|
return Center(
|
|
child: Container(
|
|
height: size.height * 0.2,
|
|
child: CommonLoader()
|
|
)
|
|
);
|
|
}
|
|
}
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/*getElement(DeviceDTO device, Size size, dynamic appContext) {
|
|
return Stack(
|
|
children: [
|
|
Positioned(
|
|
top: 10,
|
|
right: 10,
|
|
child: Container(
|
|
width: 15,
|
|
height: 15,
|
|
decoration: BoxDecoration(
|
|
color: device.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(
|
|
device.name,
|
|
style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w300),
|
|
maxLines: 1,
|
|
),
|
|
IconButton(
|
|
icon: Icon(Icons.edit),
|
|
onPressed: () {
|
|
showChangeNameModal(
|
|
AppLocalizations.of(context)!.deviceNameLabel,
|
|
device.name,
|
|
(String name) {
|
|
device.name = name;
|
|
|
|
// Update device main info
|
|
updateMainInfos(device, appContext);
|
|
// For refresh
|
|
setState(() {
|
|
});
|
|
},
|
|
1,
|
|
context,
|
|
appContext
|
|
);
|
|
},
|
|
color: kPrimaryColor,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: device.configuration != null ?
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
AutoSizeText(
|
|
device.configuration,
|
|
style: new TextStyle(fontSize: 25),
|
|
maxLines: 1,
|
|
),
|
|
IconButton(
|
|
icon: Icon(Icons.edit),
|
|
onPressed: () {
|
|
showSelectConfigModal(
|
|
AppLocalizations.of(context)!.selectConfiguration,
|
|
(String configurationId) {
|
|
|
|
device.configurationId = configurationId;
|
|
// Update device main info
|
|
updateMainInfos(device, appContext);
|
|
|
|
// For refresh // TODO better refresh
|
|
/*setState(() {
|
|
});*/
|
|
},
|
|
1,
|
|
context,
|
|
appContext
|
|
);
|
|
},
|
|
color: kPrimaryColor,
|
|
)
|
|
],
|
|
) : InkWell(
|
|
onTap: () {
|
|
showSelectConfigModal(
|
|
AppLocalizations.of(context)!.selectConfiguration,
|
|
(String configurationId) {
|
|
|
|
device.configurationId = configurationId;
|
|
// Update device main info
|
|
updateMainInfos(device, appContext);
|
|
|
|
// For refresh // TODO better refresh
|
|
/*setState(() {
|
|
});*/
|
|
},
|
|
1,
|
|
context,
|
|
appContext
|
|
);
|
|
},
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: kPrimaryColor,
|
|
borderRadius: BorderRadius.circular(50),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 5, right: 5, top: 15, bottom: 15),
|
|
child: Center(
|
|
child: AutoSizeText(
|
|
AppLocalizations.of(context)!.choose,
|
|
style: TextStyle(color: kWhite),
|
|
maxLines: 1,
|
|
)
|
|
),
|
|
)
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}*/
|
|
}
|
|
|
|
class _DeviceCard extends StatefulWidget {
|
|
final AppConfigurationLinkDTO deviceLink;
|
|
const _DeviceCard({required this.deviceLink});
|
|
|
|
@override
|
|
State<_DeviceCard> createState() => _DeviceCardState();
|
|
}
|
|
|
|
class _DeviceCardState extends State<_DeviceCard> {
|
|
bool _hovered = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Un contenu peut être attribué à la borne avant qu'une tablette ne s'y soit
|
|
// appairée : le lien existe alors sans appareil.
|
|
final device = widget.deviceLink.device;
|
|
|
|
return MouseRegion(
|
|
onEnter: (_) => setState(() => _hovered = true),
|
|
onExit: (_) => setState(() => _hovered = false),
|
|
child: AnimatedScale(
|
|
scale: _hovered ? 1.03 : 1.0,
|
|
duration: const Duration(milliseconds: 150),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: kTextLightColor,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kSecond,
|
|
spreadRadius: _hovered ? 1 : 0.5,
|
|
blurRadius: _hovered ? 10 : 5,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
padding: const EdgeInsets.all(10),
|
|
child: device == null
|
|
? _UnpairedDevice(link: widget.deviceLink)
|
|
: DeviceElement(
|
|
deviceDTO: device,
|
|
appConfigurationLinkDTO: widget.deviceLink,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Carte d'un contenu attribué à une borne qu'aucune tablette n'a encore
|
|
/// rejointe. L'appairage se fait depuis la tablette, avec le code PIN de
|
|
/// l'instance : rien à faire ici, seulement à le signaler.
|
|
class _UnpairedDevice extends StatelessWidget {
|
|
const _UnpairedDevice({required this.link});
|
|
|
|
final AppConfigurationLinkDTO link;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final title = link.configuration?.label ?? '';
|
|
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.tablet_mac_outlined, color: kBodyTextColor.withValues(alpha: 0.5),
|
|
size: 34),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
AppLocalizations.of(context)!.noTabletPaired,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500,
|
|
color: kBodyTextColor),
|
|
),
|
|
if (title.isNotEmpty) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
title,
|
|
textAlign: TextAlign.center,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(fontSize: 11,
|
|
color: kBodyTextColor.withValues(alpha: 0.6)),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<List<DeviceDTO>?> getDevices(AppContext appContext) async {
|
|
List<DeviceDTO>? devices = await (appContext.getContext() as ManagerAppContext).clientAPI!.deviceApi!.deviceGet(instanceId: (appContext.getContext() as ManagerAppContext).instanceId);
|
|
//print("number of devices " + devices.length.toString());
|
|
|
|
if(devices != null) {
|
|
devices.forEach((element) {
|
|
//print(element);
|
|
});
|
|
}
|
|
|
|
return devices;
|
|
}
|