manager-app/lib/Screens/Devices/select_config_modal.dart

92 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/constants.dart';
import 'package:managerapi/api.dart';
showSelectConfigModal (String text, 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: SingleChildScrollView(
child: Column(
children: [
Container(
width: size.width * 0.2,
height: size.height * 0.3,
child: FutureBuilder(
future: getConfigurations(appContext),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return ListView(
scrollDirection: Axis.vertical,
children: getConfigurationsElement(snapshot.data, onGetResult, () {
Navigator.of(context).pop();
}),
);
} else if (snapshot.connectionState == ConnectionState.none) {
return Text("No data");
} else {
return Center(child: Container(height: size.height * 0.2, child: Text('LOADING TODO FRAISE')));
}
}
),
),
],
)
),
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,
),
),
],
),
],
), context: mainContext
);
}
getConfigurationsElement(data, Function onGetResult, Function requestClose) {
List<Widget> widgets = new List<Widget>();
for(var configuration in data as List<ConfigurationDTO>) {
var widget = new InkWell(
onTap: () {
onGetResult(configuration.id);
requestClose();
},
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;
}