134 lines
4.2 KiB
Dart
134 lines
4.2 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/Screens/Resources/new_ressource_popup.dart';
|
|
import 'package:manager_app/Screens/Resources/show_ressource_popup.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:managerapi/api.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class ResourcesScreen extends StatefulWidget {
|
|
ResourcesScreen({Key key}) : super(key: key);
|
|
|
|
@override
|
|
_ResourcesScreenState createState() => _ResourcesScreenState();
|
|
}
|
|
|
|
class _ResourcesScreenState extends State<ResourcesScreen> {
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return Container(
|
|
child: Column(
|
|
children: [
|
|
FutureBuilder(
|
|
future: getResources(appContext),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
var tempOutput = new List<RessourceDTO>.from(snapshot.data);
|
|
tempOutput.add(RessourceDTO(id: null));
|
|
return bodyGrid(tempOutput, size, appContext);
|
|
} 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')));
|
|
}
|
|
}
|
|
),
|
|
]
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget bodyGrid(data, Size size, AppContext appContext) {
|
|
return GridView.builder(
|
|
shrinkWrap: true,
|
|
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8),
|
|
itemCount: data.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return // User Picture
|
|
InkWell(
|
|
onTap: () {
|
|
if (data[index].id == null) {
|
|
showNewRessource(appContext, context);
|
|
} else {
|
|
showRessource(data[index], appContext, context);
|
|
}
|
|
},
|
|
child: Container(
|
|
decoration: boxDecoration(data[index]),
|
|
padding: const EdgeInsets.all(15),
|
|
margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
|
|
child: Align(
|
|
alignment: Alignment.center,
|
|
child: getElement(data[index], size)
|
|
),
|
|
),
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
getElement(RessourceDTO ressource, Size size) {
|
|
if (ressource.id != null) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: AutoSizeText(
|
|
ressource.label,
|
|
style: new TextStyle(fontSize: 25),
|
|
maxLines: 1,
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: AutoSizeText(
|
|
ressource.type.toString(),
|
|
style: new TextStyle(fontSize: 18, fontFamily: ""),
|
|
maxLines: 1,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
} else {
|
|
return Icon(
|
|
Icons.add,
|
|
color: kTextLightColor,
|
|
size: 80.0,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
boxDecoration(RessourceDTO ressourceDTO) {
|
|
return BoxDecoration(
|
|
color: ressourceDTO.id == null ? Colors.lightGreen : kTextLightColor,
|
|
shape: BoxShape.rectangle,
|
|
borderRadius: BorderRadius.circular(25.0),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kSecond,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 5,
|
|
offset: Offset(0, 1.5), // changes position of shadow
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
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;
|
|
}
|