832 lines
34 KiB
Dart
832 lines
34 KiB
Dart
import 'package:covas_mobile/pages/CameraEdit.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:intl/intl.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:textfield_tags/textfield_tags.dart';
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import '../classes/events.dart';
|
|
import '../classes/MyDrawer.dart';
|
|
|
|
import 'package:camera/camera.dart';
|
|
|
|
import '../classes/alert.dart';
|
|
import '../classes/eventAdded.dart';
|
|
|
|
import '../variable/globals.dart' as globals;
|
|
|
|
import '../classes/ad_helper.dart';
|
|
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
|
import '../classes/auth_service.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await MobileAds.instance.initialize();
|
|
runApp(MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
Events? events;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
home: EditEvent(
|
|
events: events,
|
|
imgPath: "",
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class EditEvent extends StatefulWidget {
|
|
const EditEvent({Key? key, required this.events, required this.imgPath})
|
|
: super(key: key);
|
|
final Events? events;
|
|
|
|
final String imgPath;
|
|
|
|
@override
|
|
_EditEventState createState() => _EditEventState();
|
|
}
|
|
|
|
class _EditEventState extends State<EditEvent>
|
|
with ShowAlertDialog, ShowEventDialog {
|
|
BannerAd? _bannerAd;
|
|
final AuthService _authService = AuthService();
|
|
|
|
TextEditingController inputName = TextEditingController();
|
|
|
|
TextEditingController inputDate = TextEditingController();
|
|
TextEditingController inputDesc = TextEditingController();
|
|
|
|
TextEditingController inputGeo = TextEditingController();
|
|
|
|
TextEditingController startDatepicker = TextEditingController();
|
|
TextEditingController startTimepicker = TextEditingController();
|
|
TextEditingController endDatepicker = TextEditingController();
|
|
TextEditingController endTimepicker = TextEditingController();
|
|
final _stringTagController = StringTagController();
|
|
|
|
DateTime startDate = DateTime.now();
|
|
DateTime endDate = DateTime.now();
|
|
List<Map<String, dynamic>> suggestions = [];
|
|
String geographicalZone = "";
|
|
String imgUrl = "";
|
|
|
|
List<String> initialTags = [];
|
|
|
|
final _stringOrgaController = StringTagController();
|
|
List<String> initialOrga = [];
|
|
|
|
onTapFunctionDatePicker(
|
|
{required BuildContext context, required String position}) async {
|
|
DateTime date;
|
|
if ((startDatepicker.text.isEmpty) || (endDatepicker.text.isEmpty)) {
|
|
date = DateTime.now();
|
|
} else {
|
|
date = DateTime.parse(formatDate(startDatepicker.text));
|
|
if (position == "end") {
|
|
date = DateTime.parse(formatDate(endDatepicker.text));
|
|
}
|
|
}
|
|
DateTime? pickedDate = await showDatePicker(
|
|
context: context,
|
|
firstDate: date,
|
|
initialDate: date,
|
|
lastDate: DateTime(2104));
|
|
if (pickedDate == null) return;
|
|
if (position == "start") {
|
|
startDatepicker.text = DateFormat("dd/MM/yyyy").format(pickedDate);
|
|
}
|
|
if (position == "end") {
|
|
endDatepicker.text = DateFormat("dd/MM/yyyy").format(pickedDate);
|
|
}
|
|
}
|
|
|
|
onTapFunctionTimePicker(
|
|
{required BuildContext context, required String position}) async {
|
|
TimeOfDay time;
|
|
|
|
if ((startTimepicker.text.isEmpty) || (endTimepicker.text.isEmpty)) {
|
|
time = TimeOfDay.now();
|
|
} else {
|
|
DateTime date = new DateTime.now();
|
|
date = date.copyWith(
|
|
hour: int.parse(startTimepicker.text.split(":")[0]),
|
|
minute: int.parse(startTimepicker.text.split(":")[1]));
|
|
time = TimeOfDay.fromDateTime(date);
|
|
if (position == "end") {
|
|
date = date.copyWith(
|
|
hour: int.parse(endTimepicker.text.split(":")[0]),
|
|
minute: int.parse(endTimepicker.text.split(":")[1]));
|
|
time = TimeOfDay.fromDateTime(date);
|
|
}
|
|
}
|
|
|
|
TimeOfDay? pickedDate =
|
|
await showTimePicker(context: context, initialTime: time);
|
|
if (pickedDate == null) return;
|
|
if (position == "start") {
|
|
startTimepicker.text = pickedDate.format(context);
|
|
}
|
|
if (position == "end") {
|
|
endTimepicker.text = pickedDate.format(context);
|
|
}
|
|
}
|
|
|
|
convertNulltoEmptyString(var check) {
|
|
if (check == null) {
|
|
return "";
|
|
}
|
|
return check;
|
|
}
|
|
|
|
convertNulltoArray(List<String> check) {
|
|
if (check == null) {
|
|
return [];
|
|
}
|
|
return check;
|
|
}
|
|
|
|
String formatDate(String date) {
|
|
var splitedDate = date.split("/");
|
|
|
|
var day = splitedDate[0];
|
|
var month = splitedDate[1];
|
|
var year = splitedDate[2];
|
|
|
|
return "${year}-${month}-${day}";
|
|
}
|
|
|
|
Future<void> _updateEvent(BuildContext context) async {
|
|
if (!_isEventInFuture()) {
|
|
_showErrorDialog(context, "Erreur evenement", "Evenement non futur");
|
|
return;
|
|
}
|
|
|
|
final accessToken = await _getAccessToken();
|
|
if (accessToken.isEmpty) {
|
|
_showErrorDialog(context, "Erreur utilisateur", "Champ vide");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await dotenv.load();
|
|
final geolocation = await _fetchGeolocation();
|
|
if (geolocation == null) {
|
|
_showErrorDialog(
|
|
context, "Erreur serveur", "Aucune donnée geographique");
|
|
return;
|
|
}
|
|
|
|
if (await _isDuplicateEvent(accessToken, geolocation)) {
|
|
_showErrorDialog(context, "Info evenement", "Evenement deja existant");
|
|
return;
|
|
}
|
|
|
|
if (widget.imgPath.isNotEmpty) {
|
|
imgUrl = await _uploadImage(widget.imgPath);
|
|
if (imgUrl.isEmpty) {
|
|
_showErrorDialog(context, "Erreur image", "Image non postée");
|
|
return;
|
|
}
|
|
}
|
|
|
|
await _updateEventData(accessToken, geolocation);
|
|
showEventDialog(context, "Evenement ${inputName.text} modifie");
|
|
} catch (e) {
|
|
_showErrorDialog(context, "Erreur serveur", "$e");
|
|
}
|
|
}
|
|
|
|
bool _isEventInFuture() {
|
|
DateTime startDateCompare = DateTime.parse(
|
|
"${formatDate(startDatepicker.text)}T${startTimepicker.text.replaceAll('-', ':')}");
|
|
return startDateCompare.isAfter(DateTime.now());
|
|
}
|
|
|
|
Future<String> _getAccessToken() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
return prefs.getString("access_token") ?? "";
|
|
}
|
|
|
|
Future<Map<String, dynamic>?> _fetchGeolocation() async {
|
|
final apiKey = dotenv.env['PLACE_API_KEY'] ?? '';
|
|
final response = await http.get(Uri.parse(
|
|
'https://maps.googleapis.com/maps/api/place/textsearch/json?query=${inputGeo.text}&key=$apiKey'));
|
|
|
|
if (response.statusCode == 200) {
|
|
final data = json.decode(response.body);
|
|
if (data['results'].isNotEmpty) {
|
|
return data['results'][0]['geometry']['location'];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Future<bool> _isDuplicateEvent(
|
|
String accessToken, Map<String, dynamic> location) async {
|
|
final url = Uri.parse(
|
|
"${globals.api}/events/search?item=${inputName.text}&date_event=${formatDate(startDatepicker.text)}"
|
|
"&min_lat=${location['lat']}&max_lat=${location['lat']}"
|
|
"&min_lon=${location['lng']}&max_lon=${location['lng']}");
|
|
|
|
final response = await http.get(url,
|
|
headers: {HttpHeaders.cookieHeader: 'access_token=$accessToken'});
|
|
|
|
if (response.statusCode == 200) {
|
|
final events = jsonDecode(utf8.decode(response.bodyBytes));
|
|
return events.isNotEmpty && events[0]["id"] != widget.events!.id;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
Future<String> _uploadImage(String imagePath) async {
|
|
final params = {
|
|
'expiration': '15552000',
|
|
'key': dotenv.env["IMGBB_API_KEY"]
|
|
};
|
|
final url = Uri.parse('https://api.imgbb.com/1/upload')
|
|
.replace(queryParameters: params);
|
|
|
|
final image = File(imagePath);
|
|
final req = http.MultipartRequest('POST', url)
|
|
..fields['image'] = base64.encode(await image.readAsBytes());
|
|
|
|
final response = await http.Response.fromStream(await req.send());
|
|
return response.statusCode == 200
|
|
? json.decode(response.body)["data"]["url"]
|
|
: "";
|
|
}
|
|
|
|
Future<void> _updateEventData(
|
|
String accessToken, Map<String, dynamic> location) async {
|
|
final url = Uri.parse("${globals.api}/events/${widget.events!.id}");
|
|
final response = await http.put(url,
|
|
headers: {
|
|
HttpHeaders.cookieHeader: 'access_token=$accessToken',
|
|
HttpHeaders.acceptHeader: 'application/json, text/plain, */*',
|
|
HttpHeaders.contentTypeHeader: 'application/json'
|
|
},
|
|
body: jsonEncode({
|
|
'name': inputName.text,
|
|
'place': inputGeo.text,
|
|
'start_date':
|
|
"${formatDate(startDatepicker.text)}T${startTimepicker.text.replaceAll('-', ':')}",
|
|
'end_date':
|
|
"${formatDate(endDatepicker.text)}T${endTimepicker.text.replaceAll('-', ':')}",
|
|
'organizers':
|
|
List<String>.from(_stringOrgaController.getTags as List),
|
|
'latitude': location['lat'],
|
|
'longitude': location['lng'],
|
|
'description': inputDesc.text,
|
|
"imgUrl": imgUrl,
|
|
"tags": List<String>.from(_stringTagController.getTags as List)
|
|
}));
|
|
|
|
if (response.statusCode != 200 && response.statusCode != 201) {
|
|
_handleErrorResponse(context, response.statusCode);
|
|
}
|
|
}
|
|
|
|
void _handleErrorResponse(BuildContext context, int statusCode) {
|
|
final messages = {
|
|
400: "Requête mal construite",
|
|
406: "Mot de passe incorrect",
|
|
404: "Utilisateur inconnu",
|
|
403: "Utilisateur désactivé",
|
|
410: "Token invalide",
|
|
500: "Problème interne du serveur"
|
|
};
|
|
_showErrorDialog(context, "Erreur serveur",
|
|
messages[statusCode] ?? "Problème d'authentification inconnu");
|
|
}
|
|
|
|
void _showErrorDialog(BuildContext context, String title, String message) {
|
|
showAlertDialog(context, title, message);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_authService.checkTokenStatus(context);
|
|
|
|
AdHelper.createBannerAd(() => setState(() {})).then((ad) {
|
|
setState(() {
|
|
_bannerAd = ad;
|
|
});
|
|
});
|
|
inputName.text = widget.events!.name ?? "";
|
|
startDatepicker.text = DateFormat("dd/MM/yyyy")
|
|
.format(DateTime.parse(
|
|
widget.events!.startDate ?? DateTime.now().toString()))
|
|
.toString();
|
|
startTimepicker.text = DateFormat("HH:mm")
|
|
.format(DateTime.parse(
|
|
widget.events!.startDate ?? DateTime.now().toString()))
|
|
.toString();
|
|
endDatepicker.text = DateFormat("dd/MM/yyyy")
|
|
.format(
|
|
DateTime.parse(widget.events!.endDate ?? DateTime.now().toString()))
|
|
.toString();
|
|
endTimepicker.text = DateFormat("HH:mm")
|
|
.format(
|
|
DateTime.parse(widget.events!.endDate ?? DateTime.now().toString()))
|
|
.toString();
|
|
inputGeo.text = widget.events!.place ?? "";
|
|
|
|
imgUrl = widget.events!.imgUrl ?? "";
|
|
inputDesc.text = widget.events!.description ?? "";
|
|
initialTags = List<String>.from(widget.events!.tags as List);
|
|
initialOrga = List<String>.from(widget.events!.organizers as List);
|
|
}
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
String? _validateField(String? value) {
|
|
return value!.isEmpty ? 'Champ requis' : null;
|
|
}
|
|
|
|
Future<void> searchSuggestions(String input) async {
|
|
await dotenv.load(fileName: ".env"); // Load .env file
|
|
|
|
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
|
final url =
|
|
'https://api.mapbox.com/geocoding/v5/mapbox.places/${input}.json?access_token=${mapboxAccessToken}&types=poi,address,place';
|
|
var encoded = Uri.encodeFull(url);
|
|
final response = await http.get(Uri.parse(encoded));
|
|
print("response code suggesttion : ${response.statusCode}");
|
|
|
|
if (response.statusCode == 200) {
|
|
final data = json.decode(response.body);
|
|
print("data suggestion : ${data}");
|
|
setState(() {
|
|
suggestions = (data['features'] as List)
|
|
.map((feature) => {
|
|
'place_name': feature['place_name'],
|
|
'text': feature['text'],
|
|
'geometry': feature[
|
|
'geometry'], // Include geometry for latitude/longitude
|
|
})
|
|
.toList();
|
|
});
|
|
} else {
|
|
throw Exception('Failed to load suggestions');
|
|
}
|
|
}
|
|
|
|
Padding _buildGeographicalZoneSearchField() {
|
|
return Padding(
|
|
padding:
|
|
const EdgeInsets.only(left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
child: Column(
|
|
children: [
|
|
TextField(
|
|
controller: inputGeo,
|
|
decoration: InputDecoration(
|
|
labelText: 'Lieu',
|
|
border: OutlineInputBorder(),
|
|
suffixIcon: IconButton(
|
|
icon: const Icon(Icons.clear),
|
|
onPressed: () {
|
|
setState(() {
|
|
inputGeo.clear(); // Clear the text field
|
|
geographicalZone = ''; // Reset the geographical zone state
|
|
suggestions.clear(); // Optionally clear suggestions
|
|
});
|
|
},
|
|
),
|
|
),
|
|
onChanged: (value) {
|
|
setState(() {
|
|
geographicalZone = value;
|
|
searchSuggestions(value);
|
|
});
|
|
},
|
|
),
|
|
if (suggestions.isNotEmpty)
|
|
Container(
|
|
height: 200,
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.blue),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: ListView.builder(
|
|
shrinkWrap: true,
|
|
itemCount: suggestions.length,
|
|
itemBuilder: (context, index) {
|
|
return ListTile(
|
|
title: Text(suggestions[index]['text']),
|
|
subtitle: Text(suggestions[index]['place_name']),
|
|
onTap: () async {
|
|
print("suggestion tapped : ${suggestions[index]}");
|
|
final latitude =
|
|
suggestions[index]['geometry']['coordinates'][1];
|
|
final longitude =
|
|
suggestions[index]['geometry']['coordinates'][0];
|
|
|
|
setState(() {
|
|
geographicalZone = suggestions[index]['text'];
|
|
inputGeo.text = geographicalZone;
|
|
suggestions.clear();
|
|
});
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> popCamera() async {
|
|
await availableCameras().then((value) => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) =>
|
|
CameraEdit(camera: value.first, events: widget.events))));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
drawer: MyDrawer(),
|
|
appBar: AppBar(
|
|
title: Text("Add or Update a event"),
|
|
backgroundColor: Colors.blue,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
body: Form(
|
|
key: _formKey,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: <Widget>[
|
|
_bannerAd == null
|
|
? SizedBox.shrink()
|
|
: SizedBox(
|
|
height: _bannerAd!.size.height.toDouble(),
|
|
width: _bannerAd!.size.width.toDouble(),
|
|
child: AdWidget(ad: _bannerAd!)),
|
|
if (widget.imgPath.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 60.0),
|
|
child: Center(
|
|
child: Container(
|
|
width: 200,
|
|
height: 150,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(100.0)),
|
|
child: Image.file(File(widget.imgPath))),
|
|
),
|
|
),
|
|
if (widget.imgPath.isEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 60.0),
|
|
child: Image.network(
|
|
imgUrl,
|
|
width: MediaQuery.of(context).size.width *
|
|
0.5, // 50% of screen width
|
|
height: MediaQuery.of(context).size.height * 0.5,
|
|
loadingBuilder: (BuildContext context, Widget child,
|
|
ImageChunkEvent? loadingProgress) {
|
|
if (loadingProgress == null) {
|
|
return child; // The image has finished loading
|
|
}
|
|
return Center(
|
|
child: CircularProgressIndicator(),
|
|
);
|
|
},
|
|
errorBuilder: (BuildContext context, Object error,
|
|
StackTrace? stackTrace) {
|
|
return Center(
|
|
child: Icon(Icons.error,
|
|
size: MediaQuery.of(context).size.width * 0.1),
|
|
);
|
|
},
|
|
)),
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
|
child: ElevatedButton.icon(
|
|
onPressed: popCamera,
|
|
icon: Icon(Icons.edit, size: 16), // Edit icon
|
|
label: Text("Edit Image"), // Button text
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue, // Button color
|
|
foregroundColor: Colors.white, // Text color
|
|
padding:
|
|
EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
//padding: const EdgeInsets.only(left:15.0,right: 15.0,top:0,bottom: 0),
|
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
|
child: TextFormField(
|
|
controller: inputName,
|
|
validator: (value) => _validateField(value),
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Nom',
|
|
hintText: 'Modifier le nom de l\'évènement'),
|
|
),
|
|
),
|
|
_buildGeographicalZoneSearchField(),
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
child: TextFormField(
|
|
controller: startDatepicker,
|
|
readOnly: true,
|
|
validator: (value) => _validateField(value),
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Date de debut',
|
|
hintText: 'Cliquez ici pour selectionner une date'),
|
|
onTap: () => onTapFunctionDatePicker(
|
|
context: context, position: "start")),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
child: TextFormField(
|
|
controller: startTimepicker,
|
|
readOnly: true,
|
|
validator: (value) => _validateField(value),
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Heure de debut',
|
|
hintText: 'Cliquez ici pour selectionner une heure'),
|
|
onTap: () => onTapFunctionTimePicker(
|
|
context: context, position: "start")),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
child: TextFormField(
|
|
controller: endDatepicker,
|
|
readOnly: true,
|
|
validator: (value) => _validateField(value),
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Date de fin',
|
|
hintText: 'Cliquez ici pour selectionner une date'),
|
|
onTap: () => onTapFunctionDatePicker(
|
|
context: context, position: "end")),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
child: TextFormField(
|
|
controller: endTimepicker,
|
|
readOnly: true,
|
|
validator: (value) => _validateField(value),
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Heure de fin',
|
|
hintText: 'Cliquez ici pour selectionner une heure'),
|
|
onTap: () => onTapFunctionTimePicker(
|
|
context: context, position: "end")),
|
|
),
|
|
TextFieldTags<String>(
|
|
textfieldTagsController: _stringTagController,
|
|
initialTags: initialTags,
|
|
textSeparators: const [' ', ','],
|
|
validator: (String tag) {
|
|
if (_stringTagController.getTags!.contains(tag)) {
|
|
return 'Tu as deja rentre ce tag';
|
|
}
|
|
return null;
|
|
},
|
|
inputFieldBuilder: (context, inputFieldValues) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
child: TextField(
|
|
controller: inputFieldValues.textEditingController,
|
|
focusNode: inputFieldValues.focusNode,
|
|
onChanged: inputFieldValues.onTagChanged,
|
|
onSubmitted: inputFieldValues.onTagSubmitted,
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Tags',
|
|
hintText: inputFieldValues.tags.isNotEmpty
|
|
? ''
|
|
: "Enter tag...",
|
|
errorText: inputFieldValues.error,
|
|
prefixIcon: inputFieldValues.tags.isNotEmpty
|
|
? SingleChildScrollView(
|
|
controller:
|
|
inputFieldValues.tagScrollController,
|
|
scrollDirection: Axis.vertical,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
top: 8,
|
|
bottom: 8,
|
|
left: 8,
|
|
),
|
|
child: Wrap(
|
|
runSpacing: 4.0,
|
|
spacing: 4.0,
|
|
children: inputFieldValues.tags
|
|
.map((String tag) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(20.0),
|
|
),
|
|
color: Colors.blue,
|
|
),
|
|
margin:
|
|
const EdgeInsets.symmetric(
|
|
horizontal: 5.0),
|
|
padding:
|
|
const EdgeInsets.symmetric(
|
|
horizontal: 10.0,
|
|
vertical: 5.0),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
InkWell(
|
|
child: Text(
|
|
'$tag',
|
|
style: const TextStyle(
|
|
color: Colors.white),
|
|
),
|
|
onTap: () {
|
|
//print("$tag selected");
|
|
},
|
|
),
|
|
const SizedBox(width: 4.0),
|
|
InkWell(
|
|
child: const Icon(
|
|
Icons.cancel,
|
|
size: 14.0,
|
|
color: Color.fromARGB(
|
|
255, 233, 233, 233),
|
|
),
|
|
onTap: () {
|
|
inputFieldValues
|
|
.onTagRemoved(tag);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}).toList()),
|
|
),
|
|
)
|
|
: null,
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
TextFieldTags<String>(
|
|
textfieldTagsController: _stringOrgaController,
|
|
initialTags: initialOrga,
|
|
textSeparators: const [','],
|
|
validator: (String tag) {
|
|
if (_stringOrgaController.getTags!.contains(tag)) {
|
|
return 'Cet organisateur est déjà rentré';
|
|
}
|
|
return null;
|
|
},
|
|
inputFieldBuilder: (context, inputFieldValues) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
child: TextField(
|
|
controller: inputFieldValues.textEditingController,
|
|
focusNode: inputFieldValues.focusNode,
|
|
onChanged: inputFieldValues.onTagChanged,
|
|
onSubmitted: inputFieldValues.onTagSubmitted,
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Organisateurs',
|
|
hintText: inputFieldValues.tags.isNotEmpty
|
|
? ''
|
|
: "Enter un organisateur...",
|
|
errorText: inputFieldValues.error,
|
|
prefixIcon: inputFieldValues.tags.isNotEmpty
|
|
? SingleChildScrollView(
|
|
controller:
|
|
inputFieldValues.tagScrollController,
|
|
scrollDirection: Axis.vertical,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
top: 8,
|
|
bottom: 8,
|
|
left: 8,
|
|
),
|
|
child: Wrap(
|
|
runSpacing: 4.0,
|
|
spacing: 4.0,
|
|
children: inputFieldValues.tags
|
|
.map((String tag) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(20.0),
|
|
),
|
|
color: Colors.blue,
|
|
),
|
|
margin:
|
|
const EdgeInsets.symmetric(
|
|
horizontal: 5.0),
|
|
padding:
|
|
const EdgeInsets.symmetric(
|
|
horizontal: 10.0,
|
|
vertical: 5.0),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
InkWell(
|
|
child: Text(
|
|
'$tag',
|
|
style: const TextStyle(
|
|
color: Colors.white),
|
|
),
|
|
onTap: () {
|
|
//print("$tag selected");
|
|
},
|
|
),
|
|
const SizedBox(width: 4.0),
|
|
InkWell(
|
|
child: const Icon(
|
|
Icons.cancel,
|
|
size: 14.0,
|
|
color: Color.fromARGB(
|
|
255, 233, 233, 233),
|
|
),
|
|
onTap: () {
|
|
inputFieldValues
|
|
.onTagRemoved(tag);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}).toList()),
|
|
),
|
|
)
|
|
: null,
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 15.0, right: 15.0, top: 15, bottom: 0),
|
|
//padding: EdgeInsets.symmetric(horizontal: 15),
|
|
child: TextField(
|
|
controller: inputDesc,
|
|
keyboardType: TextInputType.multiline,
|
|
maxLines: 10,
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Description',
|
|
hintText: 'Décrire l\'evènement'),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 30,
|
|
),
|
|
Container(
|
|
height: 50,
|
|
width: 250,
|
|
decoration: BoxDecoration(
|
|
color: Colors.blue,
|
|
borderRadius: BorderRadius.circular(20)),
|
|
child: TextButton(
|
|
onPressed: () {
|
|
if (_formKey.currentState!.validate()) {
|
|
_updateEvent(context);
|
|
}
|
|
},
|
|
child: Text(
|
|
'Ajouter',
|
|
style: TextStyle(color: Colors.white, fontSize: 25),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
));
|
|
}
|
|
}
|