Skip to content

Commit 1cb5b60

Browse files
authored
Add loading indicator for Add raster from service sample (#277)
* Created BusyIndicator widget - added widget to add_raster_from_service sample * Added member for drawStatusChanged subscription - Added class comment for BusyIndicator
1 parent 4820037 commit 1cb5b60

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

lib/common/busy_indicator.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import 'package:flutter/material.dart';
2+
3+
// This is a widget that is meant to sit atop the widget stack to indicate
4+
// that the system is doing something without blocking user interaction.
5+
// The widget consists of a [CircularProgressIndicator] and a very short [Text]
6+
// label.
7+
class BusyIndicator extends StatelessWidget {
8+
const BusyIndicator({
9+
required this.labelText,
10+
required this.visible,
11+
super.key,
12+
});
13+
14+
final String labelText;
15+
final bool visible;
16+
17+
@override
18+
Widget build(BuildContext context) {
19+
return Visibility(
20+
visible: visible,
21+
child: Center(
22+
child: Container(
23+
decoration: BoxDecoration(
24+
color: Colors.white,
25+
borderRadius: BorderRadius.circular(10),
26+
),
27+
width: 110,
28+
height: 90,
29+
child: Column(
30+
mainAxisAlignment: MainAxisAlignment.center,
31+
children: [
32+
const SizedBox(
33+
width: 30,
34+
height: 30,
35+
child: CircularProgressIndicator(backgroundColor: Colors.white),
36+
),
37+
Text(labelText),
38+
],
39+
),
40+
),
41+
),
42+
);
43+
}
44+
}

lib/samples/add_raster_from_service/add_raster_from_service.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import 'dart:async';
1717

1818
import 'package:arcgis_maps/arcgis_maps.dart';
19+
import 'package:arcgis_maps_sdk_flutter_samples/common/busy_indicator.dart';
1920
import 'package:arcgis_maps_sdk_flutter_samples/common/common.dart';
2021
import 'package:flutter/material.dart';
2122

@@ -30,13 +31,18 @@ class _AddRasterFromServiceState extends State<AddRasterFromService>
3031
with SampleStateSupport {
3132
// Create a controller for the map view.
3233
final _mapViewController = ArcGISMapView.createController();
34+
// A flag indicating the map is currently drawing layers.
35+
var _drawing = false;
3336
// A flag for when the map view is ready and controls can be used.
3437
var _ready = false;
38+
// A subscription to listen for MapViewController draw status state changes.
39+
late final StreamSubscription _drawStatusChangedSubscription;
3540
// A subscription to listen for layer view state changes.
3641
late final StreamSubscription _layerViewChangedSubscription;
3742

3843
@override
3944
void dispose() {
45+
_drawStatusChangedSubscription.cancel();
4046
_layerViewChangedSubscription.cancel();
4147
super.dispose();
4248
}
@@ -51,12 +57,22 @@ class _AddRasterFromServiceState extends State<AddRasterFromService>
5157
onMapViewReady: onMapViewReady,
5258
),
5359
LoadingIndicator(visible: !_ready),
60+
BusyIndicator(labelText: 'Drawing...', visible: _drawing),
5461
],
5562
),
5663
);
5764
}
5865

5966
void onMapViewReady() {
67+
_drawStatusChangedSubscription = _mapViewController.onDrawStatusChanged
68+
.listen((status) {
69+
if (status == DrawStatus.inProgress) {
70+
setState(() => _drawing = true);
71+
} else {
72+
setState(() => _drawing = false);
73+
}
74+
});
75+
6076
// Create a map with the ArcGIS DarkGrayBase basemap style and set to the map view.
6177
final map = ArcGISMap.withBasemapStyle(BasemapStyle.arcGISDarkGrayBase);
6278

0 commit comments

Comments
 (0)