336 lines
13 KiB
Dart
336 lines
13 KiB
Dart
import 'package:auto_size_text/auto_size_text.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/painting.dart';
|
|
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
|
import 'package:manager_app/Components/color_picker.dart';
|
|
import 'package:manager_app/Components/color_picker_input_container.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/Components/rounded_input_field.dart';
|
|
import 'package:manager_app/Components/string_input_container.dart';
|
|
import 'package:manager_app/Models/managerContext.dart';
|
|
import 'package:manager_app/app_context.dart';
|
|
import 'package:manager_app/client.dart';
|
|
import 'package:manager_app/constants.dart';
|
|
import 'package:managerapi/api.dart';
|
|
import 'package:overlay_support/overlay_support.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class ConfigurationDetailScreen extends StatefulWidget {
|
|
final String id;
|
|
ConfigurationDetailScreen({Key key, @required this.id}) : super(key: key);
|
|
|
|
@override
|
|
_ConfigurationDetailScreenState createState() => _ConfigurationDetailScreenState();
|
|
}
|
|
|
|
class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
|
ConfigurationDTO configurationDTO;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appContext = Provider.of<AppContext>(context);
|
|
Size size = MediaQuery.of(context).size;
|
|
return Container(
|
|
child: Column(
|
|
children: [
|
|
FutureBuilder(
|
|
future: getConfiguration(this.widget, appContext.getContext().clientAPI),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
print(this.widget);
|
|
return bodyConfiguration(snapshot.data, size, appContext, context);
|
|
} 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 bodyConfiguration(ConfigurationDTO configurationDTO, Size size, AppContext appContext, BuildContext context) {
|
|
|
|
return Container(
|
|
height: size.height*0.96,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
width: size.width*0.9,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Align(
|
|
alignment: AlignmentDirectional.bottomStart,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(configurationDTO.label, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)),
|
|
Padding(
|
|
padding: const EdgeInsets.all(5.0),
|
|
child: Text(DateFormat('dd/MM/yyyy').format(configurationDTO.dateCreation), style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200)),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
child: InkWell(
|
|
onTap: () {
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
managerAppContext.selectedConfiguration = null;
|
|
appContext.setContext(managerAppContext);
|
|
},
|
|
child: Container(
|
|
child: Icon(
|
|
Icons.arrow_back,
|
|
color: kPrimaryColor,
|
|
size: 50.0,
|
|
)
|
|
)
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
), // TITLE
|
|
Padding(
|
|
padding: const EdgeInsets.all(15.0),
|
|
child: Container(
|
|
//color: Colors.yellowAccent,
|
|
height: size.height*0.65,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
StringContainer(
|
|
label: "Label :",
|
|
initialValue: configurationDTO.label,
|
|
onChanged: (value) {
|
|
configurationDTO.label = value;
|
|
},
|
|
),
|
|
Row(
|
|
children: [
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Text("Languages :", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300))
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Container(
|
|
width: size.width *0.2,
|
|
child: RoundedInputField(
|
|
color: kSecond,
|
|
textColor: kBlack,
|
|
initialValue: configurationDTO.label,
|
|
onChanged: (value) {
|
|
configurationDTO.label = value;
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
ColorPickerInputContainer(
|
|
label: "Primary color :",
|
|
color: configurationDTO.primaryColor,
|
|
onChanged: (value) {
|
|
configurationDTO.primaryColor = value;
|
|
},
|
|
),
|
|
ColorPickerInputContainer(
|
|
label: "Secondary color :",
|
|
color: appContext.getContext().selectedConfiguration.secondaryColor,
|
|
onChanged: (value) {
|
|
configurationDTO.secondaryColor = value;
|
|
},
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Text("Sections :", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300))
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),// FIELDS SECTION
|
|
Align(
|
|
alignment: AlignmentDirectional.bottomCenter,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: RoundedButton(
|
|
text: "Annuler",
|
|
icon: Icons.undo,
|
|
color: Colors.grey,
|
|
textColor: Colors.white,
|
|
fontSize: 15,
|
|
press: () {
|
|
print("Annuler pressed");
|
|
cancel(configurationDTO, appContext);
|
|
},
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: RoundedButton(
|
|
text: "Supprimer",
|
|
icon: Icons.delete,
|
|
color: Colors.red,
|
|
textColor: Colors.white,
|
|
fontSize: 15,
|
|
press: () {
|
|
print("Supprimer pressed");
|
|
delete(configurationDTO, appContext);
|
|
},
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: RoundedButton(
|
|
text: "Sauvegarder",
|
|
icon: Icons.done,
|
|
color: Colors.lightGreen,
|
|
textColor: Colors.white,
|
|
fontSize: 15,
|
|
press: () {
|
|
save(configurationDTO, appContext);
|
|
print("Sauvegarder pressed");
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),// BUTTONS
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
getElement(ConfigurationDTO configuration, Size size) {
|
|
if (configuration.id != null) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: AutoSizeText(
|
|
configuration.label,
|
|
style: new TextStyle(fontSize: 25),
|
|
maxLines: 1,
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: AutoSizeText(
|
|
DateFormat('dd/MM/yyyy').format(configuration.dateCreation),
|
|
style: new TextStyle(fontSize: 18, fontFamily: ""),
|
|
maxLines: 1,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
} else {
|
|
return Icon(
|
|
Icons.add,
|
|
color: kTextLightColor,
|
|
size: 100.0,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> save(ConfigurationDTO configurationDTO, AppContext appContext) async {
|
|
ConfigurationDTO configuration = await appContext.getContext().clientAPI.configurationApi.configurationUpdate(configurationDTO);
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
managerAppContext.selectedConfiguration = configuration;
|
|
appContext.setContext(managerAppContext);
|
|
|
|
// popup a toast.
|
|
toast('La configuration a été sauvegardée avec succès');
|
|
|
|
// show a notification at top of screen.
|
|
/*showSimpleNotification(
|
|
Text("La configuration a été sauvegardée avec succès"),
|
|
position: NotificationPosition.bottom,
|
|
background: Colors.green);*/
|
|
}
|
|
|
|
Future<void> delete(ConfigurationDTO configurationDTO, AppContext appContext) async {
|
|
showConfirmationDialog(
|
|
"Êtes-vous sûr de vouloir supprimer cette configuration ?",
|
|
() {},
|
|
() async {
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
ConfigurationDTO configuration = await appContext.getContext().clientAPI.configurationApi.configurationDelete(configurationDTO.id);
|
|
managerAppContext.selectedConfiguration = null;
|
|
appContext.setContext(managerAppContext);
|
|
},
|
|
context
|
|
);
|
|
}
|
|
|
|
Future<void> cancel(ConfigurationDTO configurationDTO, AppContext appContext) async {
|
|
ManagerAppContext managerAppContext = appContext.getContext();
|
|
ConfigurationDTO configuration = await appContext.getContext().clientAPI.configurationApi.configurationGetDetail(configurationDTO.id);
|
|
managerAppContext.selectedConfiguration = configuration;
|
|
appContext.setContext(managerAppContext);
|
|
}
|
|
|
|
Future<ConfigurationDTO> getConfiguration(ConfigurationDetailScreen widget, Client client) async {
|
|
print(widget.id);
|
|
ConfigurationDTO configuration = await client.configurationApi.configurationGetDetail(widget.id);
|
|
print(configuration);
|
|
|
|
return configuration;
|
|
}
|
|
}
|
|
|
|
boxDecoration(ConfigurationDTO configurationDTO) {
|
|
return BoxDecoration(
|
|
color: configurationDTO.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
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|