FutureProvider - Family, and Shows How You Can Fetch and Display A Voucher Properly in Flutter.
FutureProvider - Family, and Shows How You Can Fetch and Display A Voucher Properly in Flutter.
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:geolocator/geolocator.dart';
1/6
2025-05-07
location.when(
data: (position) => Text('Lat: ${position.latitude}, Lng:
${position.longitude}'),
loading: () => CircularProgressIndicator(),
error: (e, _) => Text('Error: $e'),
);
📝 Notes:
distanceFilter helps reduce noise—location updates only fire if the user moves 10
meters (you can adjust this).
Want to combine both—e.g., fetch once initially and then listen for changes? I can
show you that too!
2/6
2025-05-07
return locationAsyncValue.when(
data: (position) => position.latitude,
loading: () => 0.0, // Or handle it however you like
error: (e, _) => 0.0, // Handle the error
);
});
return locationAsyncValue.when(
data: (position) => position.longitude,
loading: () => 0.0, // Or handle it however you like
error: (e, _) => 0.0, // Handle the error
);
});
3/6
2025-05-07
3. Complete Example:
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:geolocator/geolocator.dart';
4/6
2025-05-07
return locationAsyncValue.when(
data: (position) => position.latitude,
loading: () => 0.0, // Or handle it however you like
error: (e, _) => 0.0, // Handle the error
);
});
return locationAsyncValue.when(
5/6
2025-05-07
Summary:
latitudeProvider and longitudeProvider: These providers extract latitude and
longitude from the stream provided by locationStreamProvider.
You can watch these providers anywhere in your app to get the current latitude
and longitude.
Let me know if you'd like more details or need help with any other part of the
app!
6/6