Add real client api call for config and resources

This commit is contained in:
Thomas Fransolet 2021-04-21 18:41:36 +02:00
parent 1a043ec675
commit 0245d659bf
3 changed files with 91 additions and 8 deletions

View File

@ -1,4 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:manager_app/app_context.dart';
import 'package:managerapi/api.dart';
import 'package:provider/provider.dart';
class ConfigurationsScreen extends StatefulWidget { class ConfigurationsScreen extends StatefulWidget {
ConfigurationsScreen({Key key}) : super(key: key); ConfigurationsScreen({Key key}) : super(key: key);
@ -10,12 +13,49 @@ class ConfigurationsScreen extends StatefulWidget {
class _ConfigurationsScreenState extends State<ConfigurationsScreen> { class _ConfigurationsScreenState extends State<ConfigurationsScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);
Size size = MediaQuery.of(context).size;
return Container( return Container(
child: Center( child: Column(
child: Text( children: [
Text(
"Configurations" "Configurations"
) ),
FutureBuilder(
future: getConfigurations(appContext),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return GridView.builder(
shrinkWrap: true,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return // User Picture
Text(snapshot.data[0].label);
}
);
} 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')));
}
}
),
]
), ),
); );
} }
} }
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;
}

View File

@ -1,4 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:manager_app/app_context.dart';
import 'package:provider/provider.dart';
class DevicesScreen extends StatefulWidget { class DevicesScreen extends StatefulWidget {
DevicesScreen({Key key}) : super(key: key); DevicesScreen({Key key}) : super(key: key);
@ -10,6 +12,9 @@ class DevicesScreen extends StatefulWidget {
class _DevicesScreenState extends State<DevicesScreen> { class _DevicesScreenState extends State<DevicesScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);
Size size = MediaQuery.of(context).size;
return Container( return Container(
child: Center( child: Center(
child: Text( child: Text(

View File

@ -1,4 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:manager_app/app_context.dart';
import 'package:managerapi/api.dart';
import 'package:provider/provider.dart';
class ResourcesScreen extends StatefulWidget { class ResourcesScreen extends StatefulWidget {
ResourcesScreen({Key key}) : super(key: key); ResourcesScreen({Key key}) : super(key: key);
@ -8,14 +11,49 @@ class ResourcesScreen extends StatefulWidget {
} }
class _ResourcesScreenState extends State<ResourcesScreen> { class _ResourcesScreenState extends State<ResourcesScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final appContext = Provider.of<AppContext>(context);
Size size = MediaQuery.of(context).size;
return Container( return Container(
child: Center( child: Column(
child: Text( children: [
Text(
"Resources" "Resources"
) ),
FutureBuilder(
future: getResources(appContext),
builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return GridView.builder(
shrinkWrap: true,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return // User Picture
Text("Test resources");
}
);
} 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')));
}
}
),
]
), ),
); );
} }
} }
Future<List<RessourceDTO>> getResources(dynamic appContext) async {
List<RessourceDTO> ressources = await appContext.getContext().clientAPI.ressourceApi.ressourceGet();
print("number of ressources " + ressources.length.toString());
ressources.forEach((element) {
print(element);
});
return ressources;
}