Skip to content

Commit f52b1db

Browse files
committed
feat(examples/starwars): add web support
1 parent c7e1edc commit f52b1db

File tree

10 files changed

+74
-9
lines changed

10 files changed

+74
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity","path":"/Users/mjr/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+2/","dependencies":[]},{"name":"path_provider","path":"/Users/mjr/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/","dependencies":[]}],"android":[{"name":"connectivity","path":"/Users/mjr/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.8+2/","dependencies":[]},{"name":"path_provider","path":"/Users/mjr/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/","dependencies":[]}],"macos":[{"name":"connectivity_macos","path":"/Users/mjr/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_macos-0.1.0+2/","dependencies":[]},{"name":"path_provider_macos","path":"/Users/mjr/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4/","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"connectivity","dependencies":["connectivity_macos"]},{"name":"connectivity_macos","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]}],"date_created":"2020-03-29 14:38:58.208164","version":"1.15.17"}

examples/starwars/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ Start the server:
33
flutter packages pub run graphql_starwars_test_server
44
```
55

6-
And then `flutter run`
6+
And then `flutter run`, or `flutter run -d chrome` for web support:
77

8+
![flutter for web image](./for_web.png)

examples/starwars/for_web.png

110 KB
Loading

examples/starwars/lib/main.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
import 'dart:io';
22

33
import 'package:flutter/material.dart';
4+
import 'package:universal_platform/universal_platform.dart';
45

56
import './client_provider.dart';
67
import './episode/episode_page.dart';
78
import './reviews/review_page.dart';
89
import './reviews/review_page_list.dart';
910

1011
String get host {
11-
if (Platform.isAndroid) {
12+
// https://github.com/flutter/flutter/issues/36126#issuecomment-596215587
13+
if (UniversalPlatform.isAndroid) {
1214
return '10.0.2.2';
1315
} else {
14-
return 'localhost';
16+
return '127.0.0.1';
1517
}
1618
}
1719

18-
final String GRAPHQL_ENDPOINT = 'http://$host:3000/graphql';
19-
final String SUBSCRIPTION_ENDPOINT = 'ws://$host:3000/subscriptions';
20+
final graphqlEndpoint = 'http://$host:3000/graphql';
21+
final subscriptionEndpoint = 'ws://$host:3000/subscriptions';
2022

2123
void main() => runApp(MyApp());
2224

2325
class MyApp extends StatelessWidget {
2426
@override
2527
Widget build(BuildContext context) {
2628
return ClientProvider(
27-
uri: GRAPHQL_ENDPOINT,
28-
subscriptionUri: SUBSCRIPTION_ENDPOINT,
29+
uri: graphqlEndpoint,
30+
subscriptionUri: subscriptionEndpoint,
2931
child: MaterialApp(
30-
title: 'Graphql Starwas Demo',
32+
title: 'Graphql Starwars Demo',
3133
theme: ThemeData(
3234
primarySwatch: Colors.blue,
3335
),

examples/starwars/pubspec.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ dependencies:
88
path: ../../packages/graphql_flutter
99
graphql:
1010
path: ../../packages/graphql
11-
graphql_starwars_test_server: ^0.0.4
11+
graphql_starwars_test_server: ^0.1.0
12+
universal_platform: ^0.1.3
13+
# https://github.com/flutter/flutter/issues/36126#issuecomment-596215587
1214

1315
flutter:
1416
uses-material-design: true
@@ -18,3 +20,6 @@ dependency_overrides:
1820
path: ../../packages/graphql_flutter
1921
graphql:
2022
path: ../../packages/graphql
23+
graphql_starwars_test_server:
24+
path: /Users/mjr/Documents/code/libraries/angel-starwars-server
25+

examples/starwars/web/favicon.png

917 Bytes
Loading
5.17 KB
Loading
8.06 KB
Loading

examples/starwars/web/index.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
6+
<meta name="description" content="A new Flutter project.">
7+
8+
<!-- iOS meta tags & icons -->
9+
<meta name="apple-mobile-web-app-capable" content="yes">
10+
<meta name="apple-mobile-web-app-status-bar-style" content="black">
11+
<meta name="apple-mobile-web-app-title" content="starwars_app">
12+
<link rel="apple-touch-icon" href="icons/Icon-192.png">
13+
14+
<!-- Favicon -->
15+
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
16+
17+
<title>starwars_app</title>
18+
<link rel="manifest" href="manifest.json">
19+
</head>
20+
<body>
21+
<!-- This script installs service_worker.js to provide PWA functionality to
22+
application. For more information, see:
23+
https://developers.google.com/web/fundamentals/primers/service-workers -->
24+
<script>
25+
if ('serviceWorker' in navigator) {
26+
window.addEventListener('load', function () {
27+
navigator.serviceWorker.register('flutter_service_worker.js');
28+
});
29+
}
30+
</script>
31+
<script src="main.dart.js" type="application/javascript"></script>
32+
</body>
33+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "starwars_app",
3+
"short_name": "starwars_app",
4+
"start_url": ".",
5+
"display": "minimal-ui",
6+
"background_color": "#0175C2",
7+
"theme_color": "#0175C2",
8+
"description": "A new Flutter project.",
9+
"orientation": "portrait-primary",
10+
"prefer_related_applications": false,
11+
"icons": [
12+
{
13+
"src": "icons/Icon-192.png",
14+
"sizes": "192x192",
15+
"type": "image/png"
16+
},
17+
{
18+
"src": "icons/Icon-512.png",
19+
"sizes": "512x512",
20+
"type": "image/png"
21+
}
22+
]
23+
}

0 commit comments

Comments
 (0)