Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(example): avoid building unsupported PerformanceOverlay on web platform #1803

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions example/lib/pages/many_circles.dart
Original file line number Diff line number Diff line change
@@ -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_web_perf_overlay_snackbar.dart';
import 'package:latlong2/latlong.dart';

const _maxCirclesCount = 20000;
Expand Down Expand Up @@ -33,6 +35,9 @@ class ManyCirclesPageState extends State<ManyCirclesPage> {
@override
void initState() {
super.initState();

showNoWebPerfOverlaySnackbar(context);

Future.microtask(() {
final r = Random();
for (var x = 0; x < _maxCirclesCount; x++) {
Expand Down Expand Up @@ -86,12 +91,13 @@ class ManyCirclesPageState extends State<ManyCirclesPage> {
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(),
),
],
),
);
Expand Down
18 changes: 12 additions & 6 deletions example/lib/pages/many_markers.dart
Original file line number Diff line number Diff line change
@@ -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_web_perf_overlay_snackbar.dart';
import 'package:latlong2/latlong.dart';

const _maxMarkersCount = 20000;
Expand Down Expand Up @@ -33,6 +35,9 @@ class ManyMarkersPageState extends State<ManyMarkersPage> {
@override
void initState() {
super.initState();

showNoWebPerfOverlaySnackbar(context);

Future.microtask(() {
final r = Random();
for (var x = 0; x < _maxMarkersCount; x++) {
Expand Down Expand Up @@ -87,12 +92,13 @@ class ManyMarkersPageState extends State<ManyMarkersPage> {
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(),
),
],
),
);
Expand Down
20 changes: 14 additions & 6 deletions example/lib/pages/polygon_perf_stress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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_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';
Expand All @@ -29,6 +30,12 @@ class _PolygonPerfStressPageState extends State<PolygonPerfStressPage> {
),
);

@override
void initState() {
super.initState();
showNoWebPerfOverlaySnackbar(context);
}

@override
void dispose() {
geoJsonLoader.ignore();
Expand Down Expand Up @@ -82,12 +89,13 @@ class _PolygonPerfStressPageState extends State<PolygonPerfStressPage> {
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(),
),
],
),
);
Expand Down
18 changes: 12 additions & 6 deletions example/lib/pages/polyline_perf_stress.dart
Original file line number Diff line number Diff line change
@@ -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_web_perf_overlay_snackbar.dart';
import 'package:flutter_map_example/widgets/simplification_tolerance_slider.dart';
import 'package:latlong2/latlong.dart';

Expand All @@ -25,6 +27,9 @@ class _PolylinePerfStressPageState extends State<PolylinePerfStressPage> {
@override
void initState() {
super.initState();

showNoWebPerfOverlaySnackbar(context);

final random = Random(1234);
for (int i = 1; i < 300000; i++) {
final lat = (random.nextDouble() - 0.5) * 0.001;
Expand Down Expand Up @@ -81,12 +86,13 @@ class _PolylinePerfStressPageState extends State<PolylinePerfStressPage> {
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(),
),
],
),
);
Expand Down
14 changes: 14 additions & 0 deletions example/lib/widgets/show_no_web_perf_overlay_snackbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void showNoWebPerfOverlaySnackbar(BuildContext context) {
if (kIsWeb) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Cannot show performance graph overlay on web'),
),
),
);
}
}