docs: Fix non-web examples (#2411)

Fix build for non-web platforms, by hiding dart:html into platform-specific import.
This commit is contained in:
Eugene Kleshnin
2023-03-16 06:20:02 +00:00
committed by GitHub
parent 55f66add63
commit 11e329d665
7 changed files with 34 additions and 6 deletions

1
examples/.gitignore vendored
View File

@ -1,7 +1,6 @@
linux/
macos/
windows/
test/
# Miscellaneous
*.class

View File

@ -1,5 +1,6 @@
import 'dart:html';
import 'package:dashbook/dashbook.dart';
import 'package:examples/platform/stub_provider.dart'
if (dart.library.html) 'platform/web_provider.dart';
import 'package:examples/stories/animations/animations.dart';
import 'package:examples/stories/bridge_libraries/audio/audio.dart';
import 'package:examples/stories/bridge_libraries/flame_isolate/isolate.dart';
@ -29,10 +30,7 @@ import 'package:flame/game.dart';
import 'package:flutter/material.dart';
void main() {
var page = window.location.search ?? '';
if (page.startsWith('?')) {
page = page.substring(1);
}
final page = PageProviderImpl().getPage();
final routes = <String, FlameGame Function()>{
'constant_volume_joint': ConstantVolumeJointExample.new,

View File

@ -0,0 +1,3 @@
abstract class PageProvider {
String? getPage();
}

View File

@ -0,0 +1,8 @@
import 'package:examples/platform/page_provider.dart';
class PageProviderImpl extends PageProvider {
@override
String? getPage() {
return null;
}
}

View File

@ -0,0 +1,13 @@
import 'dart:html';
import 'package:examples/platform/page_provider.dart';
class PageProviderImpl extends PageProvider {
@override
String? getPage() {
var page = window.location.search ?? '';
if (page.startsWith('?')) {
page = page.substring(1);
}
return page;
}
}

View File

@ -26,6 +26,7 @@ dependencies:
padracing: ^1.0.0
provider: ^6.0.3
rogue_shooter: ^0.1.0
test: ^1.23.1
trex_game: ^0.1.0
dev_dependencies:

View File

@ -0,0 +1,6 @@
import 'package:examples/main.dart' as examples;
import 'package:test/test.dart';
void main() {
test('main', examples.main);
}