import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:idrocap/private/model/organizzazioni.dart'; import 'package:idrocap/private/notifiche.dart'; import 'package:latlong2/latlong.dart'; import '../utility/utility.dart'; import 'constant/globals.dart' as globals; import 'widget/menu.dart'; class ProfileOrganisations extends StatefulWidget { final Organizzazioni organizzazioni; ProfileOrganisations({super.key, required this.organizzazioni}); @override State createState() => _ProfileOrganisationsState(); } class _ProfileOrganisationsState extends State { String searchString = ""; List _markers = []; String split = ""; late String latitude; late String longitude; @override void initState() { var split; split = widget.organizzazioni.coordinates.split(" "); this.latitude = split[1]; this.longitude = split[0]; _markers = [ Marker( point: LatLng(double.parse(latitude), double.parse(longitude)), width: 100, height: 100, child: Wrap( children: [ Icon( Icons.pin_drop, size: 60, color: Colors.blueAccent, ), Text(""), ], ), ), ]; super.initState(); } @override Widget build(BuildContext context) { return PopScope( canPop: true, child: Scaffold( appBar: AppBar( leading: InkWell( onTap: () { Navigator.pop(context); }, child: Icon( Icons.arrow_back_ios, color: Colors.white, ), ), iconTheme: IconThemeData(color: Colors.white), backgroundColor: HexColor(globals.colorAppbar), title: Center( child: Text( "Organizzazioni", style: TextStyle(color: Colors.white), ), ), actions: [ IconButton( onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) => Notifiche())); }, icon: Icon(Icons.notifications), ) ], ), drawer: Menu(), body: ListView( children: [ Padding( padding: EdgeInsets.all(5), child: Container( color: HexColor(globals.coloreCardProfili), child: Wrap(children: [ ListTile( leading: Icon( Icons.account_circle_outlined, size: 50, color: Colors.white, ), title: Wrap( children: [ Text(widget.organizzazioni.actor.description, style: TextStyle(color: Colors.white)), ], ), subtitle: Wrap( children: [ Text( widget.organizzazioni.acronym + " - " + widget.organizzazioni.organisation_type .description, style: TextStyle(color: Colors.white), ), ], ), ), ])), ), Padding( padding: EdgeInsets.all(5), child: Card( elevation: 20, child: Column( children: [ Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topRight: Radius.circular(10), topLeft: Radius.circular(10)), color: HexColor(globals.colorAppbar), ), child: ListTile( title: Wrap( children: [ Text( "Contatti disponibili", style: TextStyle( color: Colors.white, fontSize: 20), ) ], ), ), ), Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)), ), child: Padding( padding: EdgeInsets.all(15), child: Column( children: [ if (widget.organizzazioni.district.isNotEmpty) Align( alignment: Alignment.topLeft, child: Wrap( alignment: WrapAlignment.start, children: [ Text( "Comune: ", style: TextStyle( fontWeight: FontWeight.bold), ), Text(widget.organizzazioni.district), ], ), ), if (widget.organizzazioni.province.isNotEmpty) Align( alignment: Alignment.topLeft, child: Wrap( children: [ Text( "Provincia: ", style: TextStyle( fontWeight: FontWeight.bold), ), Text( widget.organizzazioni.province, ), ], ), ), if (widget.organizzazioni.address.isNotEmpty) Align( alignment: Alignment.topLeft, child: Wrap( alignment: WrapAlignment.start, children: [ Text( "Indirizzo: ", style: TextStyle( fontWeight: FontWeight.bold), ), Text(widget.organizzazioni.address), ], ), ), if (widget.organizzazioni.cap.isNotEmpty) Align( alignment: Alignment.topLeft, child: Wrap( alignment: WrapAlignment.start, children: [ Text( "Cap: ", style: TextStyle( fontWeight: FontWeight.bold), ), Text(widget.organizzazioni.cap), ], ), ), /* if (widget.organizzazioni.coordinates.isNotEmpty) Align( alignment: Alignment.center, child: Wrap( children: [ TextButton.icon( icon: Icon(Icons.pin_drop_outlined), onPressed: () { var test = widget .organizzazioni.coordinates .split(" "); Utility.viewToMaps(test[0], test[1]); }, label: Text("Guarda su mappa"), ) ], ), ), */ Divider(), if (widget.organizzazioni.phones.length > 0 || widget.organizzazioni.mobile_phones.length > 0) Row( children: [ Text( "Numeri di telefono", style: TextStyle( fontWeight: FontWeight.bold, fontSize: 18), ), ], ), if (widget.organizzazioni.phones.length > 0 || widget.organizzazioni.mobile_phones.length > 0) SizedBox( height: 20, ), for (int i = 0; i < widget.organizzazioni.phones.length; i++) Container( child: Column( children: [ Row( children: [ Text(widget.organizzazioni.phones[i] ['type']), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(widget.organizzazioni.phones[i] ['value']), IconButton( icon: Icon(Icons.phone), color: Colors.green, onPressed: () async { await Utility.makePhoneCall(widget .organizzazioni .phones[i]['value']); }, ) ], ), Divider(), ], ), ), for (int i = 0; i < widget .organizzazioni.mobile_phones.length; i++) Container( child: Column( children: [ Row( children: [ Text(widget.organizzazioni .mobile_phones[i]['type']), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(widget.organizzazioni .mobile_phones[i]['value']), IconButton( icon: Icon(Icons.phone), color: Colors.green, onPressed: () async { await Utility.makePhoneCall(widget .organizzazioni .mobile_phones[i]['value']); }, ) ], ), Divider(), ], ), ), if (widget.organizzazioni.phones.length > 0 || widget.organizzazioni.mobile_phones.length > 0) SizedBox( height: 20, ), if (widget.organizzazioni.emails.length > 0) Row( children: [ Text( "E-mail", style: TextStyle( fontWeight: FontWeight.bold, fontSize: 18), ), ], ), if (widget.organizzazioni.emails.length > 0) SizedBox( height: 20, ), for (int i = 0; i < widget.organizzazioni.emails.length; i++) Container( child: Column( children: [ Row( children: [ Text(widget.organizzazioni.emails[i] ['type']), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(widget.organizzazioni.emails[i] ['value']), IconButton( icon: Icon(Icons.email), color: Colors.red, onPressed: () async { await Utility.makeEmail(widget .organizzazioni .emails[i]['value']); }, ) ], ), Divider(), ], ), ), ], ), ), ), ], )), ), if (widget.organizzazioni.coordinates.isNotEmpty) Container( height: 250.0, padding: EdgeInsets.all(5), child: FlutterMap( options: MapOptions( initialCenter: LatLng(double.parse(latitude), double.parse(longitude)), minZoom: 11, maxZoom: 16, interactionOptions: InteractionOptions( flags: InteractiveFlag.pinchZoom | InteractiveFlag.drag, ), backgroundColor: Colors.black, ), children: [ TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', minZoom: 11, maxZoom: 16, subdomains: ['a', 'b', 'c'], ), MarkerClusterLayerWidget( options: MarkerClusterLayerOptions( maxClusterRadius: 45, // size: Size(40, 40), markers: _markers, builder: (context, markers) { return Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(20), color: Colors.blue), child: Center( child: Text( markers.length.toString(), style: TextStyle(color: Colors.white), ), ), ); }, ), ), ], ), ), ], ), ), ); } }