Skip to content

Commit

Permalink
Update Dart example for latest stable SDK (#3340)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Mar 15, 2021
1 parent 1ef6a1d commit 807a80b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
13 changes: 6 additions & 7 deletions community/samples/serving/helloworld-dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ be created using the following instructions.
```yaml
name: hello_world_dart
publish_to: none # let's not accidentally publish this to pub.dartlang.org
description: Hello world server example in Dart

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
shelf: ^0.7.3
shelf: ^1.0.0
```
2. If you want to run locally, install dependencies. If you only want to run in
Expand All @@ -50,16 +49,16 @@ be created using the following instructions.
Future main() async {
// Find port to listen on from environment variable.
var port = int.tryParse(Platform.environment['PORT'] ?? '8080');
final port = int.parse(Platform.environment['PORT'] ?? '8080');
// Read $TARGET from environment variable.
var target = Platform.environment['TARGET'] ?? 'World';
final target = Platform.environment['TARGET'] ?? 'World';
Response handler(Request request) => Response.ok('Hello $target');
// Serve handler on given port.
var server = await serve(
Pipeline().addMiddleware(logRequests()).addHandler(handler),
final server = await serve(
const Pipeline().addMiddleware(logRequests()).addHandler(handler),
InternetAddress.anyIPv4,
port,
);
Expand Down
8 changes: 4 additions & 4 deletions community/samples/serving/helloworld-dart/bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import 'package:shelf/shelf_io.dart';

Future main() async {
// Find port to listen on from environment variable.
var port = int.tryParse(Platform.environment['PORT'] ?? '8080');
final port = int.parse(Platform.environment['PORT'] ?? '8080');

// Read $TARGET from environment variable.
var target = Platform.environment['TARGET'] ?? 'World';
final target = Platform.environment['TARGET'] ?? 'World';

Response handler(Request request) => Response.ok('Hello $target');

// Serve handler on given port.
var server = await serve(
Pipeline().addMiddleware(logRequests()).addHandler(handler),
final server = await serve(
const Pipeline().addMiddleware(logRequests()).addHandler(handler),
InternetAddress.anyIPv4,
port,
);
Expand Down
4 changes: 2 additions & 2 deletions community/samples/serving/helloworld-dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: hello_world_dart
publish_to: none # let's not accidentally publish this to pub.dartlang.org

environment:
sdk: '>=2.1.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dependencies:
shelf: ^0.7.3
shelf: ^1.0.0

0 comments on commit 807a80b

Please sign in to comment.