74 lines
2.8 KiB
Dart
74 lines
2.8 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Components/fetch_resource_icon.dart';
|
|
import 'package:manager_app/Components/string_input_container.dart';
|
|
import 'package:manager_app/Screens/Resources/new_resource_popup.dart';
|
|
import 'package:manager_app/Screens/Resources/resource_body_grid.dart';
|
|
import 'package:manager_app/Screens/Resources/show_resource_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 {
|
|
final Function onGetResult; //return ResourceDTO
|
|
final bool isImage;
|
|
const ResourcesScreen({
|
|
Key key,
|
|
this.isImage = false,
|
|
this.onGetResult,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_ResourcesScreenState createState() => _ResourcesScreenState();
|
|
}
|
|
|
|
class _ResourcesScreenState extends State<ResourcesScreen> {
|
|
String filter;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
return FutureBuilder(
|
|
future: getResources(widget.onGetResult, widget.isImage, appContext),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
var tempOutput = new List<ResourceDTO>.from(snapshot.data);
|
|
// tempOutput.add(ResourceDTO(id: null));
|
|
return ResourceBodyGrid(resources: tempOutput, isImage: widget.isImage, onSelect: (value) {
|
|
if (widget.onGetResult == null) {
|
|
// Main screen
|
|
if (value.id == null) {
|
|
showNewResource(appContext, context);
|
|
} else {
|
|
showResource(value, appContext, context, size);
|
|
}
|
|
} else {
|
|
if (value.id == null) {
|
|
showNewResource(appContext, context);
|
|
} else {
|
|
// Result for select modal
|
|
widget.onGetResult(value);
|
|
}
|
|
}
|
|
},);//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')));
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<List<ResourceDTO>> getResources(Function onGetResult, bool isImage, dynamic appContext) async {
|
|
List<ResourceDTO> resources = await appContext.getContext().clientAPI.resourceApi.resourceGet();
|
|
if (onGetResult != null && isImage) {
|
|
resources = resources.where((element) => element.type == ResourceType.image || element.type == ResourceType.imageUrl).toList();
|
|
}
|
|
return resources;
|
|
}
|