From 20452cd65f52023aeb00d51ce912a4b21e2c721a Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Wed, 17 Jan 2024 11:21:26 +0000 Subject: [PATCH 1/2] Avoid building unsupported `PerformanceOverlay` on web platform --- example/lib/pages/many_circles.dart | 18 +++++++++++------ example/lib/pages/many_markers.dart | 18 +++++++++++------ example/lib/pages/polygon_perf_stress.dart | 20 +++++++++++++------ example/lib/pages/polyline_perf_stress.dart | 18 +++++++++++------ .../lib/widgets/show_no_perf_overlay_web.dart | 14 +++++++++++++ 5 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 example/lib/widgets/show_no_perf_overlay_web.dart diff --git a/example/lib/pages/many_circles.dart b/example/lib/pages/many_circles.dart index c8dc17d86..060fb2a68 100644 --- a/example/lib/pages/many_circles.dart +++ b/example/lib/pages/many_circles.dart @@ -1,10 +1,12 @@ import 'dart:math'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; import 'package:flutter_map_example/widgets/number_of_items_slider.dart'; +import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; import 'package:latlong2/latlong.dart'; const _maxCirclesCount = 20000; @@ -33,6 +35,9 @@ class ManyCirclesPageState extends State { @override void initState() { super.initState(); + + showNoPerfOverlayWeb(context); + Future.microtask(() { final r = Random(); for (var x = 0; x < _maxCirclesCount; x++) { @@ -86,12 +91,13 @@ class ManyCirclesPageState extends State { onChangedNumber: (v) => setState(() => numOfCircles = v), ), ), - Positioned( - bottom: 16, - left: 0, - right: 0, - child: PerformanceOverlay.allEnabled(), - ), + if (!kIsWeb) + Positioned( + bottom: 16, + left: 0, + right: 0, + child: PerformanceOverlay.allEnabled(), + ), ], ), ); diff --git a/example/lib/pages/many_markers.dart b/example/lib/pages/many_markers.dart index 53a42e993..9fe69ef69 100644 --- a/example/lib/pages/many_markers.dart +++ b/example/lib/pages/many_markers.dart @@ -1,10 +1,12 @@ import 'dart:math'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; import 'package:flutter_map_example/widgets/number_of_items_slider.dart'; +import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; import 'package:latlong2/latlong.dart'; const _maxMarkersCount = 20000; @@ -33,6 +35,9 @@ class ManyMarkersPageState extends State { @override void initState() { super.initState(); + + showNoPerfOverlayWeb(context); + Future.microtask(() { final r = Random(); for (var x = 0; x < _maxMarkersCount; x++) { @@ -87,12 +92,13 @@ class ManyMarkersPageState extends State { onChangedNumber: (v) => setState(() => numOfMarkers = v), ), ), - Positioned( - bottom: 16, - left: 0, - right: 0, - child: PerformanceOverlay.allEnabled(), - ), + if (!kIsWeb) + Positioned( + bottom: 16, + left: 0, + right: 0, + child: PerformanceOverlay.allEnabled(), + ), ], ), ); diff --git a/example/lib/pages/polygon_perf_stress.dart b/example/lib/pages/polygon_perf_stress.dart index 1bbc2607a..933e1de3a 100644 --- a/example/lib/pages/polygon_perf_stress.dart +++ b/example/lib/pages/polygon_perf_stress.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; +import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; import 'package:flutter_map_example/widgets/simplification_tolerance_slider.dart'; import 'package:flutter_map_geojson/flutter_map_geojson.dart'; import 'package:latlong2/latlong.dart'; @@ -29,6 +30,12 @@ class _PolygonPerfStressPageState extends State { ), ); + @override + void initState() { + super.initState(); + showNoPerfOverlayWeb(context); + } + @override void dispose() { geoJsonLoader.ignore(); @@ -82,12 +89,13 @@ class _PolygonPerfStressPageState extends State { setState(() => simplificationTolerance = v), ), ), - Positioned( - bottom: 16, - left: 0, - right: 0, - child: PerformanceOverlay.allEnabled(), - ), + if (!kIsWeb) + Positioned( + bottom: 16, + left: 0, + right: 0, + child: PerformanceOverlay.allEnabled(), + ), ], ), ); diff --git a/example/lib/pages/polyline_perf_stress.dart b/example/lib/pages/polyline_perf_stress.dart index f20396260..c3a3c7c59 100644 --- a/example/lib/pages/polyline_perf_stress.dart +++ b/example/lib/pages/polyline_perf_stress.dart @@ -1,9 +1,11 @@ import 'dart:math'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; +import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; import 'package:flutter_map_example/widgets/simplification_tolerance_slider.dart'; import 'package:latlong2/latlong.dart'; @@ -25,6 +27,9 @@ class _PolylinePerfStressPageState extends State { @override void initState() { super.initState(); + + showNoPerfOverlayWeb(context); + final random = Random(1234); for (int i = 1; i < 300000; i++) { final lat = (random.nextDouble() - 0.5) * 0.001; @@ -81,12 +86,13 @@ class _PolylinePerfStressPageState extends State { setState(() => simplificationTolerance = v), ), ), - Positioned( - bottom: 16, - left: 0, - right: 0, - child: PerformanceOverlay.allEnabled(), - ), + if (!kIsWeb) + Positioned( + bottom: 16, + left: 0, + right: 0, + child: PerformanceOverlay.allEnabled(), + ), ], ), ); diff --git a/example/lib/widgets/show_no_perf_overlay_web.dart b/example/lib/widgets/show_no_perf_overlay_web.dart new file mode 100644 index 000000000..7f285f8ef --- /dev/null +++ b/example/lib/widgets/show_no_perf_overlay_web.dart @@ -0,0 +1,14 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +void showNoPerfOverlayWeb(BuildContext context) { + if (kIsWeb) { + WidgetsBinding.instance.addPostFrameCallback( + (_) => ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Cannot show performance graph overlay on web'), + ), + ), + ); + } +} From 2ac57879b10c294ef3e2948dd6bb1cfcacbaa6bc Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Sat, 20 Jan 2024 22:03:27 +0000 Subject: [PATCH 2/2] Renamed `showNoPerfOverlayWeb` to `showNoWebPerfOverlaySnackbar` --- example/lib/pages/many_circles.dart | 4 ++-- example/lib/pages/many_markers.dart | 4 ++-- example/lib/pages/polygon_perf_stress.dart | 4 ++-- example/lib/pages/polyline_perf_stress.dart | 4 ++-- ...verlay_web.dart => show_no_web_perf_overlay_snackbar.dart} | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) rename example/lib/widgets/{show_no_perf_overlay_web.dart => show_no_web_perf_overlay_snackbar.dart} (85%) diff --git a/example/lib/pages/many_circles.dart b/example/lib/pages/many_circles.dart index 060fb2a68..62e7adee7 100644 --- a/example/lib/pages/many_circles.dart +++ b/example/lib/pages/many_circles.dart @@ -6,7 +6,7 @@ import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; import 'package:flutter_map_example/widgets/number_of_items_slider.dart'; -import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; +import 'package:flutter_map_example/widgets/show_no_web_perf_overlay_snackbar.dart'; import 'package:latlong2/latlong.dart'; const _maxCirclesCount = 20000; @@ -36,7 +36,7 @@ class ManyCirclesPageState extends State { void initState() { super.initState(); - showNoPerfOverlayWeb(context); + showNoWebPerfOverlaySnackbar(context); Future.microtask(() { final r = Random(); diff --git a/example/lib/pages/many_markers.dart b/example/lib/pages/many_markers.dart index 9fe69ef69..20e02b446 100644 --- a/example/lib/pages/many_markers.dart +++ b/example/lib/pages/many_markers.dart @@ -6,7 +6,7 @@ import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; import 'package:flutter_map_example/widgets/number_of_items_slider.dart'; -import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; +import 'package:flutter_map_example/widgets/show_no_web_perf_overlay_snackbar.dart'; import 'package:latlong2/latlong.dart'; const _maxMarkersCount = 20000; @@ -36,7 +36,7 @@ class ManyMarkersPageState extends State { void initState() { super.initState(); - showNoPerfOverlayWeb(context); + showNoWebPerfOverlaySnackbar(context); Future.microtask(() { final r = Random(); diff --git a/example/lib/pages/polygon_perf_stress.dart b/example/lib/pages/polygon_perf_stress.dart index 933e1de3a..f812ce6d1 100644 --- a/example/lib/pages/polygon_perf_stress.dart +++ b/example/lib/pages/polygon_perf_stress.dart @@ -4,7 +4,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; -import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; +import 'package:flutter_map_example/widgets/show_no_web_perf_overlay_snackbar.dart'; import 'package:flutter_map_example/widgets/simplification_tolerance_slider.dart'; import 'package:flutter_map_geojson/flutter_map_geojson.dart'; import 'package:latlong2/latlong.dart'; @@ -33,7 +33,7 @@ class _PolygonPerfStressPageState extends State { @override void initState() { super.initState(); - showNoPerfOverlayWeb(context); + showNoWebPerfOverlaySnackbar(context); } @override diff --git a/example/lib/pages/polyline_perf_stress.dart b/example/lib/pages/polyline_perf_stress.dart index c3a3c7c59..f68f6a755 100644 --- a/example/lib/pages/polyline_perf_stress.dart +++ b/example/lib/pages/polyline_perf_stress.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_example/misc/tile_providers.dart'; import 'package:flutter_map_example/widgets/drawer/menu_drawer.dart'; -import 'package:flutter_map_example/widgets/show_no_perf_overlay_web.dart'; +import 'package:flutter_map_example/widgets/show_no_web_perf_overlay_snackbar.dart'; import 'package:flutter_map_example/widgets/simplification_tolerance_slider.dart'; import 'package:latlong2/latlong.dart'; @@ -28,7 +28,7 @@ class _PolylinePerfStressPageState extends State { void initState() { super.initState(); - showNoPerfOverlayWeb(context); + showNoWebPerfOverlaySnackbar(context); final random = Random(1234); for (int i = 1; i < 300000; i++) { diff --git a/example/lib/widgets/show_no_perf_overlay_web.dart b/example/lib/widgets/show_no_web_perf_overlay_snackbar.dart similarity index 85% rename from example/lib/widgets/show_no_perf_overlay_web.dart rename to example/lib/widgets/show_no_web_perf_overlay_snackbar.dart index 7f285f8ef..d75b8fc90 100644 --- a/example/lib/widgets/show_no_perf_overlay_web.dart +++ b/example/lib/widgets/show_no_web_perf_overlay_snackbar.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -void showNoPerfOverlayWeb(BuildContext context) { +void showNoWebPerfOverlaySnackbar(BuildContext context) { if (kIsWeb) { WidgetsBinding.instance.addPostFrameCallback( (_) => ScaffoldMessenger.of(context).showSnackBar(