import 'dart:async'; import 'package:auto_size_text/auto_size_text.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_widget_from_html/flutter_widget_from_html.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:tablet_app/Components/loading_common.dart'; import 'package:tablet_app/Models/agenda.dart'; // Assurez-vous d'importer votre modèle d'agenda import 'package:intl/intl.dart'; import 'package:tablet_app/constants.dart'; class EventPopup extends StatefulWidget { final EventAgenda eventAgenda; EventPopup({Key? key, required this.eventAgenda}) : super(key: key); @override State createState() => _EventPopupState(); } class _EventPopupState extends State { final DateFormat formatter = DateFormat('dd/MM/yyyy hh:mm'); Completer _controller = Completer(); Set markers = {}; bool init = false; Set getMarkers() { markers = {}; if (widget.eventAgenda.address!.lat != null && widget.eventAgenda.address!.lng != null) { markers.add(Marker( draggable: false, markerId: MarkerId(widget.eventAgenda.address!.lat.toString() + widget.eventAgenda.address!.lng.toString()), position: LatLng( double.parse(widget.eventAgenda.address!.lat!.toString()), double.parse(widget.eventAgenda.address!.lng!.toString()), ), icon: BitmapDescriptor.defaultMarker, infoWindow: InfoWindow.noText)); } return markers; } @override Widget build(BuildContext context) { var dateToShow = widget.eventAgenda.dateFrom!.isAtSameMomentAs(widget.eventAgenda.dateTo!) ? "${formatter.format(widget.eventAgenda.dateFrom!)}": "${formatter.format(widget.eventAgenda.dateFrom!)} - ${formatter.format(widget.eventAgenda.dateTo!)}"; print(widget.eventAgenda.phone); Size size = MediaQuery.of(context).size; if(!init) { print("getmarkers in build"); getMarkers(); init = true; } return AlertDialog( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) ), contentPadding: EdgeInsets.zero, // title: Text(eventAgenda.name!), content: SizedBox( height: size.height * 0.8, child: Stack( children: [ Positioned( right: 5, top: 5, child: InkWell( onTap: () { Navigator.of(context).pop(); }, child: Container( width: 50, height: 50, decoration: BoxDecoration( color: kMainGrey, shape: BoxShape.circle, boxShadow: [ BoxShadow( color: kMainGrey, spreadRadius: 0.5, blurRadius: 1.1, offset: Offset(0, 1.1), // changes position of shadow ), ], ), child: Icon( Icons.close, size: 25, color: Colors.white, ), ), ), ), Row( children: [ widget.eventAgenda.image != null ? ClipRRect( borderRadius: const BorderRadius.only(topLeft: Radius.circular(20.0), bottomLeft: Radius.circular(20.0)), child: Container( child: Center( child: Container( width: 225, height: size.height, color: Colors.grey, child: CachedNetworkImage( imageUrl: widget.eventAgenda.image!, width: size.width, fit: BoxFit.cover, progressIndicatorBuilder: (context, url, downloadProgress) { return Center( child: SizedBox( width: 50, height: 50, child: LoadingCommon(), ), ); }, errorWidget: (context, url, error) => Icon(Icons.error), ), ), ) ), ): SizedBox(), Padding( padding: const EdgeInsets.only(left: 20, right: 10, bottom: 10), child: Column( children: [ SizedBox( height: size.height * 0.11, width: size.width * 0.45, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ AutoSizeText( widget.eventAgenda.name!, style: TextStyle(fontSize: 25), maxFontSize: 25, ), Text('${dateToShow}', style: TextStyle(fontSize: 20, color: kMainGrey)), ], ), ), Container( height: size.height * 0.65, width: size.width * 0.45, color: Colors.grey, child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(8.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ HtmlWidget( widget.eventAgenda.description!, customStylesBuilder: (element) { return {'text-align': 'left'}; }, textStyle: TextStyle(fontSize: kDescriptionSize), ), widget.eventAgenda.idVideoYoutube != null && widget.eventAgenda.idVideoYoutube!.isNotEmpty ? Text('TODO YOUTUBE VIDEO : ${widget.eventAgenda.idVideoYoutube}') : Text(""), ], ), ), ), ), ], ), ), SizedBox( width: size.width * 0.28, height: size.height * 0.6, child: Padding( padding: const EdgeInsets.all(8.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ widget.eventAgenda.address!.lat != null && widget.eventAgenda.address!.lng != null ? SizedBox( width: size.width * 0.28, height: size.height * 0.2, child: GoogleMap( mapToolbarEnabled: false, initialCameraPosition: CameraPosition( target: LatLng(double.parse(widget.eventAgenda.address!.lat!.toString()), double.parse(widget.eventAgenda.address!.lng!.toString())), zoom: 16, ), onMapCreated: (GoogleMapController controller) { _controller.complete(controller); }, markers: markers, ), ): SizedBox(), SizedBox( width: size.width * 0.28, height: size.height * 0.35, child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ widget.eventAgenda.address!.address != null && widget.eventAgenda.address!.address!.isNotEmpty ? Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Icon(Icons.location_on, size: 13), Padding( padding: const EdgeInsets.all(4.0), child: SizedBox( width: size.width*0.25, child: AutoSizeText(widget.eventAgenda.address!.address!, style: TextStyle(fontSize: 12), maxLines: 3) ), ) ], ): SizedBox(), widget.eventAgenda.phone != null && widget.eventAgenda.phone!.isNotEmpty ? Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Icon(Icons.phone, size: 13), Padding( padding: const EdgeInsets.all(4.0), child: Text(widget.eventAgenda.phone!, style: TextStyle(fontSize: 12)), ) ], ): SizedBox(), widget.eventAgenda.email != null && widget.eventAgenda.email!.isNotEmpty ? Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Icon(Icons.email, size: 13), Padding( padding: const EdgeInsets.all(4.0), child: Text(widget.eventAgenda.email!, style: TextStyle(fontSize: 12)), ) ], ): SizedBox(), widget.eventAgenda.website != null && widget.eventAgenda.website!.isNotEmpty ? Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Icon(Icons.public, size: 13), Padding( padding: const EdgeInsets.all(4.0), child: Text(widget.eventAgenda.website!, style: TextStyle(fontSize: 12)), ) ], ): SizedBox(), ], ), ), ], ), ), ) ], ), ], ), ), ); } }