107 lines
3.8 KiB
Dart
107 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:manager_app/Components/confirmation_dialog.dart';
|
|
import 'package:manager_app/Components/message_notification.dart';
|
|
import 'package:manager_app/Components/rounded_button.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:managerapi/api.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
void showResource(ResourceDTO resourceDTO,AppContext appContext, BuildContext context, Size size) {
|
|
showDialog(
|
|
builder: (BuildContext context) => AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(20.0))
|
|
),
|
|
content: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(
|
|
resourceDTO.label == null ? "" : resourceDTO.label,
|
|
style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)),
|
|
),
|
|
Container(
|
|
height: size.height *0.6,
|
|
child: Center(
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(30),
|
|
border: Border.all(width: 3, color: kSecond)
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Image.network(
|
|
resourceDTO.type == ResourceType.image ? appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDTO.id : "https://miro.medium.com/max/1920/1*8wFh-pEuwyAGa1IaKb-lEw.png",
|
|
fit:BoxFit.scaleDown
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
actions: <Widget>[
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Align(
|
|
alignment: AlignmentDirectional.bottomEnd,
|
|
child: Container(
|
|
width: 175,
|
|
height: 70,
|
|
child: RoundedButton(
|
|
text: "Retour",
|
|
icon: Icons.undo,
|
|
color: kSecond,
|
|
press: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: AlignmentDirectional.bottomEnd,
|
|
child: Container(
|
|
width: 200,
|
|
height: 70,
|
|
child: RoundedButton(
|
|
text: "Supprimer",
|
|
icon: Icons.delete,
|
|
color: kPrimaryColor,
|
|
textColor: kWhite,
|
|
press: () {
|
|
delete(resourceDTO, appContext, context);
|
|
},
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
), context: context
|
|
);
|
|
}
|
|
|
|
Future<void> delete(ResourceDTO resourceDTO, AppContext appContext, context) async {
|
|
showConfirmationDialog(
|
|
"Êtes-vous sûr de vouloir supprimer cette ressource ?",
|
|
() {},
|
|
() async {
|
|
await appContext.getContext().clientAPI.resourceApi.resourceDelete(resourceDTO.id);
|
|
// just to refresh
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
appContext.setContext(managerAppContext);
|
|
Navigator.of(context).pop();
|
|
|
|
showNotification(Colors.green, kWhite, 'La ressource a été supprimée avec succès', context);
|
|
},
|
|
context
|
|
);
|
|
}
|