import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:location_picker_flutter_map/location_picker_flutter_map.dart'; import 'package:manager_app/Components/common_loader.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/constants.dart'; class GeolocInputContainer extends StatefulWidget { final Color color; final String label; final LatLong? initialValue; final ValueChanged onChanged; final bool isSmall; final double fontSize; final double fontSizeText; const GeolocInputContainer({ Key? key, this.color = kSecond, required this.label, required this.initialValue, required this.onChanged, this.isSmall = false, this.fontSize = 25, this.fontSizeText = 20, }) : super(key: key); @override State createState() => _GeolocInputContainerState(); } class _GeolocInputContainerState extends State { LatLong? localisation; @override Widget build(BuildContext context) { Size size = MediaQuery.of(context).size; localisation = widget.initialValue; return Container( child: Row( children: [ Align( alignment: AlignmentDirectional.centerStart, child: AutoSizeText( widget.label, style: TextStyle(fontSize: widget.fontSize, fontWeight: FontWeight.w300), maxLines: 2, maxFontSize: widget.fontSize, textAlign: TextAlign.center, ), ), Padding( padding: const EdgeInsets.all(10.0), child: Container( width: size.width *0.15, child: InkWell( onTap: () { showDialog( builder: (BuildContext context) { return AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) ), title: Center(child: Text(widget.label)), content: SingleChildScrollView( child: Container( width: size.width *0.75, height: 350, child: FlutterLocationPicker( initZoom: 14, initPosition: localisation == null ? LatLong(50.429333, 4.891434) : LatLong(localisation!.latitude, localisation!.longitude), minZoomLevel: 0, maxZoomLevel: 17, markerIcon: const Icon( Icons.location_pin, color: kPrimaryColor, size: 50, ), loadingWidget: CommonLoader(iconSize: 40.0), searchBarHintColor: kPrimaryColor, mapLoadingBackgroundColor: kSecond, zoomButtonsBackgroundColor: kPrimaryColor, zoomButtonsColor: Colors.white, locationButtonBackgroundColor: kPrimaryColor, locationButtonsColor: Colors.white, countryFilter: "be, fr", trackMyPosition: false, searchBarHintText: "Chercher une localisation", searchBarTextColor: Colors.black, searchBarBackgroundColor: Colors.white, showSelectLocationButton : true, selectLocationButtonText: "Choisir cette localisation", selectedLocationButtonTextstyle: const TextStyle(fontSize: 18, color: kPrimaryColor), mapLanguage: 'fr', onError: (e) => print(e), selectLocationButtonLeadingIcon: const Icon(Icons.check, color: kPrimaryColor), onPicked: (pickedData) { print("onPicked"); localisation = pickedData.latLong; print(localisation); }, onChanged: (pickedData) { print("onChanged"); print(pickedData.latLong.latitude); print(pickedData.latLong.longitude); print(pickedData.address); print(pickedData.addressData); }, showContributorBadgeForOSM: false, ), ), ), actions: [ Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Container( width: 180, height: 70, child: RoundedButton( text: "Annuler", icon: Icons.undo, color: kSecond, press: () { Navigator.of(context).pop(); }, fontSize: 20, ), ), Container( width: 180, height: 70, child: RoundedButton( text: "Valider", icon: Icons.check, color: kPrimaryColor, textColor: kWhite, press: () { if(localisation != null) { widget.onChanged(localisation!); Navigator.of(context).pop(); } else { showNotification(kPrimaryColor, kWhite, "Aucune localisation choisie", context, null); } }, fontSize: 20, ), ), ], ), ], ); }, context: context ); }, child: Container( decoration: BoxDecoration( color: widget.color, borderRadius: BorderRadius.circular(50), ), child: Padding( padding: const EdgeInsets.only(left: 5, right: 5, top: 15, bottom: 15), child: Center( child: AutoSizeText( "Changer la localisation", style: TextStyle(color: kWhite), maxLines: 2, ) ), ) ), ), ), ), ], ), ); } }