diff --git a/packages/cross_file/CHANGELOG.md b/packages/cross_file/CHANGELOG.md index e5083cd05d..b10acb4529 100644 --- a/packages/cross_file/CHANGELOG.md +++ b/packages/cross_file/CHANGELOG.md @@ -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 diff --git a/packages/cross_file/README.md b/packages/cross_file/README.md index 3bbca28c2f..bfa7b3db65 100644 --- a/packages/cross_file/README.md +++ b/packages/cross_file/README.md @@ -10,18 +10,17 @@ access the file and its metadata. Example: + ```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). diff --git a/packages/cross_file/example/assets/hello.txt b/packages/cross_file/example/assets/hello.txt new file mode 100644 index 0000000000..5dd01c177f --- /dev/null +++ b/packages/cross_file/example/assets/hello.txt @@ -0,0 +1 @@ +Hello, world! \ No newline at end of file diff --git a/packages/cross_file/example/lib/readme_excerpts.dart b/packages/cross_file/example/lib/readme_excerpts.dart new file mode 100644 index 0000000000..e2dcdc18cb --- /dev/null +++ b/packages/cross_file/example/lib/readme_excerpts.dart @@ -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 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; +} diff --git a/packages/cross_file/example/pubspec.yaml b/packages/cross_file/example/pubspec.yaml new file mode 100644 index 0000000000..cfc3baf8ae --- /dev/null +++ b/packages/cross_file/example/pubspec.yaml @@ -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 diff --git a/packages/cross_file/example/test/readme_excerpts_test.dart b/packages/cross_file/example/test/readme_excerpts_test.dart new file mode 100644 index 0000000000..e9a4bd3d1d --- /dev/null +++ b/packages/cross_file/example/test/readme_excerpts_test.dart @@ -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); +} diff --git a/packages/cross_file/pubspec.yaml b/packages/cross_file/pubspec.yaml index ffcca3c387..f1216d3e77 100644 --- a/packages/cross_file/pubspec.yaml +++ b/packages/cross_file/pubspec.yaml @@ -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" diff --git a/script/configs/temp_exclude_excerpt.yaml b/script/configs/temp_exclude_excerpt.yaml index 2bea7dcb7d..c1fe3e9aa8 100644 --- a/script/configs/temp_exclude_excerpt.yaml +++ b/script/configs/temp_exclude_excerpt.yaml @@ -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