-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cross_file] adopt code excerpts in README (#5347)
Updates the README to use a compiled excerpt source for its example of instantiating an `XFile`. Part of [flutter/flutter#102679](flutter/flutter#102679)
- Loading branch information
Showing
8 changed files
with
73 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, world! |
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,24 @@ | ||
// 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. | ||
|
||
// ignore_for_file: avoid_print | ||
|
||
import 'package:cross_file/cross_file.dart'; | ||
|
||
/// Demonstrate instantiating an XFile for the README. | ||
Future<XFile> instantiateXFile() async { | ||
// #docregion Instantiate | ||
final XFile file = XFile('assets/hello.txt'); | ||
|
||
print('File information:'); | ||
print('- Path: ${file.path}'); | ||
print('- Name: ${file.name}'); | ||
print('- MIME type: ${file.mimeType}'); | ||
|
||
final String fileContent = await file.readAsString(); | ||
print('Content of the file: $fileContent'); | ||
// #enddocregion Instantiate | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: cross_file_example | ||
description: Demonstrates how to use cross files. | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ">=3.0.0 <4.0.0" | ||
|
||
dependencies: | ||
cross_file: | ||
# When depending on this package from a real application you should use: | ||
# cross_file: ^x.y.z | ||
# See https://dart.dev/tools/pub/dependencies#version-constraints | ||
# The example app is bundled with the plugin so we use a path dependency on | ||
# the parent directory to use the current plugin's version. | ||
path: ../ | ||
|
||
dev_dependencies: | ||
test: ^1.24.0 |
23 changes: 23 additions & 0 deletions
23
packages/cross_file/example/test/readme_excerpts_test.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,23 @@ | ||
// 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. | ||
|
||
import 'package:cross_file/cross_file.dart'; | ||
import 'package:cross_file_example/readme_excerpts.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
const bool kIsWeb = bool.fromEnvironment('dart.library.js_util'); | ||
|
||
void main() { | ||
test('instantiateXFile loads asset file', () async { | ||
// Ensure that the snippet code runs successfully. | ||
final XFile xFile = await instantiateXFile(); | ||
// It should have a nonempty path and name. | ||
expect(xFile.path, allOf(isNotNull, isNotEmpty)); | ||
expect(xFile.name, allOf(isNotNull, isNotEmpty)); | ||
|
||
// And the example file should have contents. | ||
final String fileContent = await xFile.readAsString(); | ||
expect(fileContent, allOf(isNotNull, isNotEmpty)); | ||
}, skip: kIsWeb); | ||
} |
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