Skip to content

Commit 0b2d07a

Browse files
Use AlertDialog for error message
1 parent a867367 commit 0b2d07a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/samples/show_device_location/show_device_location_sample.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ class _ShowDeviceLocationSampleState extends State<ShowDeviceLocationSample>
4444
// A subscription to receive changes to the auto-pan mode.
4545
StreamSubscription? _autoPanModeSubscription;
4646
var _autoPanMode = LocationDisplayAutoPanMode.recenter;
47-
// Declare an exception for if the data source fails to start.
48-
ArcGISException? _dataSourceException;
4947
// A flag for when the map view is ready and controls can be used.
5048
var _ready = false;
5149

@@ -75,14 +73,11 @@ class _ShowDeviceLocationSampleState extends State<ShowDeviceLocationSample>
7573
onMapViewReady: onMapViewReady,
7674
),
7775
),
78-
Visibility(
79-
visible: _dataSourceException == null,
80-
// An error message if the location data source fails to start.
81-
replacement:
82-
Text('Exception: ${_dataSourceException?.message}'),
83-
// A button to show the Settings bottom sheet.
76+
Center(
8477
child: ElevatedButton(
85-
onPressed: () => setState(() => _settingsVisible = true),
78+
onPressed: _status == LocationDataSourceStatus.failedToStart
79+
? null
80+
: () => setState(() => _settingsVisible = true),
8681
child: const Text('Location Settings'),
8782
),
8883
),
@@ -212,9 +207,16 @@ class _ShowDeviceLocationSampleState extends State<ShowDeviceLocationSample>
212207
() => _autoPanMode = _mapViewController.locationDisplay.autoPanMode);
213208

214209
// Attempt to start the location data source (this will prompt the user for permission).
215-
await _locationDataSource.start().onError((e, _) {
216-
setState(() => _dataSourceException = e as ArcGISException);
217-
});
210+
try {
211+
await _locationDataSource.start();
212+
} on ArcGISException catch (e) {
213+
if (mounted) {
214+
showDialog(
215+
context: context,
216+
builder: (_) => AlertDialog(content: Text(e.message)),
217+
);
218+
}
219+
}
218220

219221
// Set the ready state variable to true to enable the UI.
220222
setState(() => _ready = true);

0 commit comments

Comments
 (0)