1313// limitations under the License.
1414//
1515
16+ import 'dart:async' ;
17+
1618import 'package:arcgis_maps/arcgis_maps.dart' ;
1719import 'package:arcgis_maps_sdk_flutter_samples/common/common.dart' ;
1820import 'package:flutter/material.dart' ;
@@ -28,13 +30,28 @@ class _AddRasterFromServiceState extends State<AddRasterFromService>
2830 with SampleStateSupport {
2931 // Create a controller for the map view.
3032 final _mapViewController = ArcGISMapView .createController ();
33+ // A flag for when the map view is ready and controls can be used.
34+ var _ready = false ;
35+ // A subscription to listen for layer view state changes.
36+ late final StreamSubscription _layerViewChangedSubscription;
37+
38+ @override
39+ void dispose () {
40+ _layerViewChangedSubscription.cancel ();
41+ super .dispose ();
42+ }
3143
3244 @override
3345 Widget build (BuildContext context) {
3446 return Scaffold (
35- body: ArcGISMapView (
36- controllerProvider: () => _mapViewController,
37- onMapViewReady: onMapViewReady,
47+ body: Stack (
48+ children: [
49+ ArcGISMapView (
50+ controllerProvider: () => _mapViewController,
51+ onMapViewReady: onMapViewReady,
52+ ),
53+ LoadingIndicator (visible: ! _ready),
54+ ],
3855 ),
3956 );
4057 }
@@ -71,5 +88,15 @@ class _AddRasterFromServiceState extends State<AddRasterFromService>
7188
7289 // Add Raster layer to the map.
7390 map.operationalLayers.add (rasterLayer);
91+ // Listen for layer view state changes.
92+ _layerViewChangedSubscription = _mapViewController.onLayerViewStateChanged
93+ .listen ((layerViewState) {
94+ if (layerViewState.layer == rasterLayer &&
95+ layerViewState.layerViewState.status.contains (
96+ LayerViewStatus .active,
97+ )) {
98+ setState (() => _ready = true );
99+ }
100+ });
74101 }
75102}
0 commit comments