Skip to content

Commit

Permalink
#1037: fix LateInitializationError with polylineCulling (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
jithware authored Feb 2, 2022
1 parent 42fa4b5 commit 52dc38e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 49 deletions.
145 changes: 97 additions & 48 deletions example/lib/pages/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@ import 'package:latlong2/latlong.dart';

import '../widgets/drawer.dart';

class PolylinePage extends StatelessWidget {
class PolylinePage extends StatefulWidget {
static const String route = 'polyline';

@override
State<PolylinePage> createState() => _PolylinePageState();
}

class _PolylinePageState extends State<PolylinePage> {
late Future<List<Polyline>> polylines;

Future<List<Polyline>> getPolylines() async {
var polyLines = [
Polyline(
points: [
LatLng(50.5, -0.09),
LatLng(51.3498, -6.2603),
LatLng(53.8566, 2.3522),
],
strokeWidth: 4.0,
color: Colors.amber,
),
];
await Future.delayed(Duration(seconds: 3));
return polyLines;
}

@override
void initState() {
polylines = getPolylines();
super.initState();
}

@override
Widget build(BuildContext context) {
var points = <LatLng>[
Expand All @@ -22,54 +51,74 @@ class PolylinePage extends StatelessWidget {
];

return Scaffold(
appBar: AppBar(title: Text('Polylines')),
drawer: buildDrawer(context, PolylinePage.route),
body: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
children: [
Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Text('Polylines'),
),
Flexible(
child: FlutterMap(
options: MapOptions(
center: LatLng(51.5, -0.09),
zoom: 5.0,
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
PolylineLayerOptions(
polylines: [
Polyline(
points: points,
strokeWidth: 4.0,
color: Colors.purple),
],
),
PolylineLayerOptions(
polylines: [
Polyline(
points: pointsGradient,
strokeWidth: 4.0,
gradientColors: [
Color(0xffE40203),
Color(0xffFEED00),
Color(0xff007E2D),
appBar: AppBar(title: Text('Polylines')),
drawer: buildDrawer(context, PolylinePage.route),
body: Padding(
padding: EdgeInsets.all(8.0),
child: FutureBuilder<List<Polyline>>(
future: polylines,
builder:
(BuildContext context, AsyncSnapshot<List<Polyline>> snapshot) {
debugPrint('snapshot: ${snapshot.hasData}');
if (snapshot.hasData) {
return Column(
children: [
Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Text('Polylines'),
),
Flexible(
child: FlutterMap(
options: MapOptions(
center: LatLng(51.5, -0.09),
zoom: 5.0,
onTap: (tapPosition, point) {
setState(() {
debugPrint('onTap');
polylines = getPolylines();
});
},
),
layers: [
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c']),
PolylineLayerOptions(
polylines: [
Polyline(
points: points,
strokeWidth: 4.0,
color: Colors.purple),
],
),
PolylineLayerOptions(
polylines: [
Polyline(
points: pointsGradient,
strokeWidth: 4.0,
gradientColors: [
Color(0xffE40203),
Color(0xffFEED00),
Color(0xff007E2D),
],
),
],
),
PolylineLayerOptions(
polylines: snapshot.data!,
polylineCulling: true,
),
],
),
],
),
],
),
),
],
),
),
);
),
],
);
}
return const Text(
'Getting map data...\n\nTap on map when complete to refresh map data.');
},
),
));
}
}
2 changes: 1 addition & 1 deletion lib/src/layer/polyline_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Polyline {
final bool isDotted;
final StrokeCap strokeCap;
final StrokeJoin strokeJoin;
late final LatLngBounds boundingBox;
late LatLngBounds boundingBox;

Polyline({
required this.points,
Expand Down

0 comments on commit 52dc38e

Please sign in to comment.