151 lines
5.4 KiB
Dart
151 lines
5.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Components/loading.dart';
|
|
import 'package:manager_app/Components/rounded_button.dart';
|
|
import 'package:manager_app/Components/string_input_container.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:managerapi/api.dart';
|
|
|
|
import 'dropDown_configuration.dart';
|
|
|
|
showChangeInfo (String text, DeviceDTO inputDevice, Function onGetResult, int maxLines, BuildContext mainContext, dynamic appContext) {
|
|
Size size = MediaQuery.of(mainContext).size;
|
|
|
|
showDialog(
|
|
builder: (BuildContext context) => AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(20.0))
|
|
),
|
|
title: Center(child: Text(text)),
|
|
content: Container(
|
|
width: size.width * 0.3,
|
|
height: size.height * 0.3,
|
|
child: Column(
|
|
children: [
|
|
Center(
|
|
child: Container(
|
|
width: size.width * 0.3,
|
|
height: size.height * 0.15,
|
|
child: StringInputContainer(
|
|
label: "Nom:",
|
|
initialValue: inputDevice.name,
|
|
onChanged: (value) {
|
|
inputDevice.name = value;
|
|
},
|
|
maxLength: 20,
|
|
),
|
|
),
|
|
),
|
|
Row(
|
|
children: [
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Text("Configuration:", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300))
|
|
),
|
|
Container(
|
|
height: size.height * 0.1,
|
|
child: FutureBuilder(
|
|
future: getConfigurations(appContext),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
return Row(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: DropDownConfig(
|
|
configurations: snapshot.data,
|
|
selectedConfigurationId: inputDevice.configurationId,
|
|
onChange: (ConfigurationDTO configurationOut) {
|
|
inputDevice.configuration = configurationOut.label;
|
|
inputDevice.configurationId = configurationOut.id;
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
return Text("No data");
|
|
} else {
|
|
return Center(
|
|
child: Container(
|
|
child: Text("Loading..")
|
|
)
|
|
);
|
|
}
|
|
}
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
actions: <Widget>[
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
Container(
|
|
width: 180,
|
|
height: 70,
|
|
child: RoundedButton(
|
|
text: "Annuler",
|
|
icon: Icons.undo,
|
|
color: kSecond,
|
|
press: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
Container(
|
|
width: 180,
|
|
height: 70,
|
|
child: RoundedButton(
|
|
text: "Changer",
|
|
icon: Icons.check,
|
|
color: kPrimaryColor,
|
|
textColor: kWhite,
|
|
press: () {
|
|
onGetResult(inputDevice);
|
|
Navigator.of(context).pop();
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
), context: mainContext
|
|
);
|
|
}
|
|
|
|
getConfigurationsElement(DeviceDTO inputDevice, data, Function onGetResult) {
|
|
List<Widget> widgets = new List<Widget>();
|
|
for(var configuration in data as List<ConfigurationDTO>) {
|
|
var widget = new InkWell(
|
|
onTap: () {
|
|
inputDevice.configuration = configuration.label;
|
|
inputDevice.configurationId = configuration.id;
|
|
},
|
|
child: Ink(
|
|
color: inputDevice.configurationId == configuration.id ? kPrimaryColor : null,
|
|
child: ListTile(
|
|
leading: Icon(Icons.account_tree_rounded),
|
|
title: Text(configuration.label),
|
|
),
|
|
),
|
|
);
|
|
widgets.add(widget);
|
|
}
|
|
return widgets;
|
|
}
|
|
|
|
Future<List<ConfigurationDTO>> getConfigurations(dynamic appContext) async {
|
|
List<ConfigurationDTO> configurations = await appContext.getContext().clientAPI.configurationApi.configurationGet();
|
|
print("number of configurations " + configurations.length.toString());
|
|
configurations.forEach((element) {
|
|
print(element);
|
|
});
|
|
return configurations;
|
|
}
|
|
|