149 lines
6.2 KiB
Dart
149 lines
6.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Components/common_loader.dart';
|
|
import 'package:manager_app/Components/rounded_button.dart';
|
|
import 'package:manager_app/Components/string_input_container.dart';
|
|
import 'package:manager_app/Screens/Resources/resources_screen.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:manager_api_new/api.dart';
|
|
|
|
import '../Kiosk_devices/change_device_info_modal.dart';
|
|
|
|
dynamic showAddConfigurationLink (BuildContext mainContext, AppContext appContext, InstanceDTO instanceDTO, List<String> configurationIds) async {
|
|
Size size = MediaQuery.of(mainContext).size;
|
|
|
|
List<String> selectedIds = [];
|
|
|
|
var result = await showDialog(
|
|
builder: (BuildContext context) => AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(20.0))
|
|
),
|
|
title: Center(child: Text("Sélectionner une configuration à ajouter")),
|
|
content: FutureBuilder(
|
|
future: getConfigurations(appContext),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
List<ConfigurationDTO> configurations = snapshot.data;
|
|
|
|
// filter by already linked
|
|
configurations = configurations.where((c) => !configurationIds.contains(c.id)).toList();
|
|
|
|
return StatefulBuilder(
|
|
builder: (context, setState) {
|
|
return Container(
|
|
height: size.height * 0.5,
|
|
width: size.width * 0.5,
|
|
constraints: const BoxConstraints(minHeight: 250, minWidth: 250),
|
|
child: configurations.length == 0 ? Center(child: Text("Aucun élément à afficher")) : ListView.builder(
|
|
padding: const EdgeInsets.all(20),
|
|
itemCount: configurations.length,
|
|
itemBuilder: (context, index) {
|
|
final configuration = configurations[index];
|
|
final isSelected = selectedIds.contains(configuration.id);
|
|
|
|
return Card(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
elevation: 4,
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
color: isSelected ? kPrimaryColor.withValues(alpha: 0.2) : null,
|
|
child: ListTile(
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 35, vertical: 12),
|
|
leading: Padding(
|
|
padding: const EdgeInsets.all(0.0),
|
|
child: Container(
|
|
height: 50,
|
|
width: 50,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.rectangle,
|
|
color: kWhite,
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
image: configuration.imageId != null
|
|
? DecorationImage(
|
|
fit: BoxFit.cover,
|
|
image: NetworkImage(configuration.imageSource!),
|
|
)
|
|
: null,
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
spreadRadius: 0.5,
|
|
blurRadius: 1,
|
|
offset: Offset(0, 1.5),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
title: Text(configuration.label!, style: Theme.of(context).textTheme.titleMedium),
|
|
subtitle: Text(configuration.dateCreation!.toString(), style: Theme.of(context).textTheme.bodyMedium),
|
|
trailing: Text(configuration.languages!.toString(), style: Theme.of(context).textTheme.bodyMedium),
|
|
onTap: () {
|
|
setState(() {
|
|
if (isSelected) {
|
|
selectedIds.remove(configuration.id);
|
|
} else {
|
|
selectedIds.add(configuration.id!);
|
|
}
|
|
});
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
return const Text("ERROR");
|
|
} else {
|
|
return Center(
|
|
child: SizedBox(
|
|
height: size.height * 0.2,
|
|
child: CommonLoader(),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
actions: <Widget>[
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
SizedBox(
|
|
width: 180,
|
|
height: 70,
|
|
child: RoundedButton(
|
|
text: "Annuler",
|
|
icon: Icons.undo,
|
|
color: kSecond,
|
|
press: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 180,
|
|
height: 70,
|
|
child: RoundedButton(
|
|
text: "Ajouter",
|
|
icon: Icons.add,
|
|
color: kPrimaryColor,
|
|
press: () {
|
|
Navigator.of(context).pop(selectedIds);
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
), context: mainContext
|
|
);
|
|
return result;
|
|
}
|
|
|
|
|