@@ -103,36 +103,45 @@ class _HomeScreenState extends State<HomeScreen> {
103103
104104 (double , double )? _cachedLocation;
105105
106- /// Get device location — GPS on iOS/Android, IP fallback on macOS .
106+ /// Get device location — GPS on iOS/Android/macOS , IP fallback.
107107 Future <(double , double )> _fetchLocation () async {
108108 if (_cachedLocation != null ) return _cachedLocation! ;
109109
110- // Try GPS first (matches original bitchat behavior)
110+ // Try GPS/CoreLocation first (matches original bitchat behavior)
111111 try {
112112 bool serviceEnabled = await Geolocator .isLocationServiceEnabled ();
113+ debugPrint ('[bitchat] Location service enabled: $serviceEnabled ' );
113114 if (serviceEnabled) {
114115 LocationPermission perm = await Geolocator .checkPermission ();
116+ debugPrint ('[bitchat] Location permission: $perm ' );
115117 if (perm == LocationPermission .denied) {
116118 perm = await Geolocator .requestPermission ();
119+ debugPrint ('[bitchat] After request: $perm ' );
117120 }
118121 if (perm == LocationPermission .whileInUse ||
119122 perm == LocationPermission .always) {
120123 final pos = await Geolocator .getCurrentPosition (
121124 locationSettings: const LocationSettings (
122- accuracy:
123- LocationAccuracy .low, // City-level is enough for geohash
125+ accuracy: LocationAccuracy .low,
124126 timeLimit: Duration (seconds: 10 ),
125127 ),
126128 );
129+ debugPrint (
130+ '[bitchat] GPS location: ${pos .latitude }, ${pos .longitude }' ,
131+ );
127132 _cachedLocation = (pos.latitude, pos.longitude);
128133 return _cachedLocation! ;
134+ } else {
135+ debugPrint (
136+ '[bitchat] Location permission denied, falling back to IP' ,
137+ );
129138 }
130139 }
131- } catch (_ ) {
132- // GPS unavailable (e.g. macOS desktop), fall through to IP
140+ } catch (e ) {
141+ debugPrint ( '[bitchat] GPS failed: $ e , falling back to IP' );
133142 }
134143
135- // IP-based fallback for macOS/desktop
144+ // IP-based fallback
136145 try {
137146 final uri = Uri .parse ('https://ipapi.co/json/' );
138147 final client = HttpClient ();
@@ -143,14 +152,15 @@ class _HomeScreenState extends State<HomeScreen> {
143152 final response = await request.close ();
144153 final body = await response.transform (utf8.decoder).join ();
145154 final json = jsonDecode (body) as Map <String , dynamic >;
146- _cachedLocation = (
147- (json['latitude ' ] as num ).toDouble (),
148- (json[ 'longitude' ] as num ). toDouble (),
149- );
155+ final lat = (json[ 'latitude' ] as num ). toDouble ();
156+ final lon = (json['longitude ' ] as num ).toDouble ();
157+ debugPrint ( '[bitchat] IP location: $ lat , $ lon ' );
158+ _cachedLocation = (lat, lon );
150159 client.close ();
151160 return _cachedLocation! ;
152- } catch (_) {
153- return (39.9 , - 77.0 ); // Final fallback
161+ } catch (e) {
162+ debugPrint ('[bitchat] IP fallback also failed: $e ' );
163+ return (39.9 , - 77.0 );
154164 }
155165 }
156166
0 commit comments