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 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: [ 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 widgets = new List(); for(var configuration in data as List) { 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> getConfigurations(dynamic appContext) async { List configurations = await appContext.getContext().clientAPI.configurationApi.configurationGet(); print("number of configurations " + configurations.length.toString()); configurations.forEach((element) { print(element); }); return configurations; }