Update Dart example for latest stable SDK (#3340)

This commit is contained in:
Kevin Moore 2021-03-15 15:02:41 -07:00 committed by GitHub
parent 1ef6a1de55
commit 807a80b542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 13 deletions

View File

@ -24,13 +24,12 @@ be created using the following instructions.
```yaml ```yaml
name: hello_world_dart name: hello_world_dart
publish_to: none # let's not accidentally publish this to pub.dartlang.org publish_to: none # let's not accidentally publish this to pub.dartlang.org
description: Hello world server example in Dart
environment: environment:
sdk: ">=2.1.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: 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 2. If you want to run locally, install dependencies. If you only want to run in
@ -50,16 +49,16 @@ be created using the following instructions.
Future main() async { Future main() async {
// Find port to listen on from environment variable. // 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. // 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'); Response handler(Request request) => Response.ok('Hello $target');
// Serve handler on given port. // Serve handler on given port.
var server = await serve( final server = await serve(
Pipeline().addMiddleware(logRequests()).addHandler(handler), const Pipeline().addMiddleware(logRequests()).addHandler(handler),
InternetAddress.anyIPv4, InternetAddress.anyIPv4,
port, port,
); );

View File

@ -5,16 +5,16 @@ import 'package:shelf/shelf_io.dart';
Future main() async { Future main() async {
// Find port to listen on from environment variable. // 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. // 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'); Response handler(Request request) => Response.ok('Hello $target');
// Serve handler on given port. // Serve handler on given port.
var server = await serve( final server = await serve(
Pipeline().addMiddleware(logRequests()).addHandler(handler), const Pipeline().addMiddleware(logRequests()).addHandler(handler),
InternetAddress.anyIPv4, InternetAddress.anyIPv4,
port, port,
); );

View File

@ -2,7 +2,7 @@ name: hello_world_dart
publish_to: none # let's not accidentally publish this to pub.dartlang.org publish_to: none # let's not accidentally publish this to pub.dartlang.org
environment: environment:
sdk: '>=2.1.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
shelf: ^0.7.3 shelf: ^1.0.0