[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](https://github.com/flutter/flutter/issues/102679)
This commit is contained in:
Michael McGuiness
2023-11-22 02:01:13 -08:00
committed by GitHub
parent f2fef4ed11
commit 2102327ab9
8 changed files with 73 additions and 8 deletions

View File

@ -1,5 +1,6 @@
## NEXT
## 0.3.3+7
* Updates README to improve example of instantiating an XFile.
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
## 0.3.3+6

View File

@ -10,18 +10,17 @@ access the file and its metadata.
Example:
<?code-excerpt "example/lib/readme_excerpts.dart (Instantiate)"?>
```dart
import 'package:cross_file/cross_file.dart';
final file = XFile('assets/hello.txt');
final XFile file = XFile('assets/hello.txt');
print('File information:');
print('- Path: ${file.path}');
print('- Name: ${file.name}');
print('- MIME type: ${file.mimeType}');
final fileContent = await file.readAsString();
print('Content of the file: ${fileContent}'); // e.g. "Moto G (4)"
final String fileContent = await file.readAsString();
print('Content of the file: $fileContent');
```
You will find links to the API docs on the [pub page](https://pub.dev/packages/cross_file).

View File

@ -0,0 +1 @@
Hello, world!

View File

@ -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;
}

View File

@ -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

View File

@ -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);
}

View File

@ -2,7 +2,7 @@ name: cross_file
description: An abstraction to allow working with files across multiple platforms.
repository: https://github.com/flutter/packages/tree/main/packages/cross_file
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+cross_file%22
version: 0.3.3+6
version: 0.3.3+7
environment:
sdk: ">=3.0.0 <4.0.0"

View File

@ -5,7 +5,6 @@
# TODO(stuartmorgan): Remove everything from this list. See
# https://github.com/flutter/flutter/issues/102679
- cross_file
- css_colors
- espresso
- extension_google_sign_in_as_googleapis_auth