forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[url_launcher] Update README to use code excerpts. (flutter#6042)
- Loading branch information
1 parent
c36048d
commit 9293a46
Showing
12 changed files
with
247 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/url_launcher/url_launcher/example/build.excerpt.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
targets: | ||
$default: | ||
sources: | ||
include: | ||
- lib/** | ||
- android/app/src/main/** | ||
# Some default includes that aren't really used here but will prevent | ||
# false-negative warnings: | ||
- $package$ | ||
- lib/$lib$ | ||
exclude: | ||
- '**/.*/**' | ||
- '**/build/**' | ||
- 'android/app/src/main/res/**' | ||
builders: | ||
code_excerpter|code_excerpter: | ||
enabled: true | ||
generate_for: | ||
- '**/*.dart' | ||
- android/**/*.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Run this example with: flutter run -t lib/basic.dart -d emulator | ||
|
||
// This file is used to extract code samples for the README.md file. | ||
// Run update-excerpts if you modify this file. | ||
|
||
// #docregion basic-example | ||
import 'package:flutter/material.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
final Uri _url = Uri.parse('https://flutter.dev'); | ||
|
||
void main() => runApp( | ||
const MaterialApp( | ||
home: Material( | ||
child: Center( | ||
child: ElevatedButton( | ||
onPressed: _launchUrl, | ||
child: Text('Show Flutter homepage'), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
Future<void> _launchUrl() async { | ||
if (!await launchUrl(_url)) { | ||
throw 'Could not launch $_url'; | ||
} | ||
} | ||
// #enddocregion basic-example |
70 changes: 70 additions & 0 deletions
70
packages/url_launcher/url_launcher/example/lib/encoding.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Run this example with: flutter run -t lib/encoding.dart -d emulator | ||
|
||
// This file is used to extract code samples for the README.md file. | ||
// Run update-excerpts if you modify this file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
/// Encode [params] so it produces a correct query string. | ||
/// Workaround for: https://github.com/dart-lang/sdk/issues/43838 | ||
// #docregion encode-query-parameters | ||
String? encodeQueryParameters(Map<String, String> params) { | ||
return params.entries | ||
.map((MapEntry<String, String> e) => | ||
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') | ||
.join('&'); | ||
} | ||
// #enddocregion encode-query-parameters | ||
|
||
void main() => runApp( | ||
MaterialApp( | ||
home: Material( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
children: const <Widget>[ | ||
ElevatedButton( | ||
onPressed: _composeMail, | ||
child: Text('Compose an email'), | ||
), | ||
ElevatedButton( | ||
onPressed: _composeSms, | ||
child: Text('Compose a SMS'), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
|
||
void _composeMail() { | ||
// #docregion encode-query-parameters | ||
final Uri emailLaunchUri = Uri( | ||
scheme: 'mailto', | ||
path: 'smith@example.com', | ||
query: encodeQueryParameters(<String, String>{ | ||
'subject': 'Example Subject & Symbols are allowed!', | ||
}), | ||
); | ||
|
||
launchUrl(emailLaunchUri); | ||
// #enddocregion encode-query-parameters | ||
} | ||
|
||
void _composeSms() { | ||
// #docregion sms | ||
final Uri smsLaunchUri = Uri( | ||
scheme: 'sms', | ||
path: '0118 999 881 999 119 7253', | ||
queryParameters: <String, String>{ | ||
'body': Uri.encodeComponent('Example Subject & Symbols are allowed!'), | ||
}, | ||
); | ||
// #enddocregion sms | ||
|
||
launchUrl(smsLaunchUri); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Run this example with: flutter run -t lib/files.dart -d linux | ||
|
||
// This file is used to extract code samples for the README.md file. | ||
// Run update-excerpts if you modify this file. | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
void main() => runApp( | ||
const MaterialApp( | ||
home: Material( | ||
child: Center( | ||
child: ElevatedButton( | ||
onPressed: _openFile, | ||
child: Text('Open File'), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
Future<void> _openFile() async { | ||
// Prepare a file within tmp | ||
final String tempFilePath = p.joinAll(<String>[ | ||
...p.split(Directory.systemTemp.path), | ||
'flutter_url_launcher_example.txt' | ||
]); | ||
final File testFile = File(tempFilePath); | ||
await testFile.writeAsString('Hello, world!'); | ||
// #docregion file | ||
final String filePath = testFile.absolute.path; | ||
final Uri uri = Uri.file(filePath); | ||
|
||
if (!File(uri.toFilePath()).existsSync()) { | ||
throw '$uri does not exist!'; | ||
} | ||
if (!await launchUrl(uri)) { | ||
throw 'Could not launch $uri'; | ||
} | ||
// #enddocregion file | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.