Visitar URL original
[xdg_directories] Migrate to null safety by yash1200 · Pull Request #250 · flutter/packages · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests fixed
  • Loading branch information
yash1200 committed Dec 29, 2020
commit c734d9152f3c7616405c4535eebb4fe0772a2069
8 changes: 4 additions & 4 deletions packages/xdg_directories/lib/xdg_directories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:process/process.dart';

/// An override function used by the tests to override the environment variable
/// lookups using [xdgEnvironmentOverride].
typedef EnvironmentAccessor = String Function(String envVar);
typedef EnvironmentAccessor = String? Function(String? envVar);

/// A testing setter that replaces the real environment lookups with an override.
///
Expand All @@ -34,7 +34,7 @@ set xdgEnvironmentOverride(EnvironmentAccessor? override) {
EnvironmentAccessor? get xdgEnvironmentOverride => _xdgEnvironmentOverride;
EnvironmentAccessor? _xdgEnvironmentOverride;
EnvironmentAccessor _productionGetEnv =
(String value) => Platform.environment[value]!;
(String? value) => Platform.environment[value]!;
Comment thread
yash1200 marked this conversation as resolved.
Resolved
EnvironmentAccessor _getenv = _productionGetEnv;

/// A testing function that replaces the process manager used to run xdg-user-path
Expand Down Expand Up @@ -65,7 +65,7 @@ List<Directory> _directoryListFromEnvironment(

Directory? _directoryFromEnvironment(String? envVar, String? fallback) {
assert(envVar != null);
final String? value = _getenv(envVar!);
final String? value = _getenv(envVar);
if (value == null || value.isEmpty) {
if (fallback == null) {
return null;
Expand Down Expand Up @@ -147,7 +147,7 @@ Directory getUserDirectory(String dirName) {
final ProcessResult result = _processManager.runSync(
<String>['xdg-user-dir', dirName],
includeParentEnvironment: true,
stdoutEncoding: Encoding.getByName('utf8')!,
stdoutEncoding: Encoding.getByName('utf8') ?? systemEncoding,
);
final String path = utf8.decode(result.stdout).split('\n')[0];
return Directory(path);
Expand Down
2 changes: 1 addition & 1 deletion packages/xdg_directories/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies:

dev_dependencies:
mockito: ^5.0.0-nullsafety.0
test: ^1.16.0-nullsafety.12
test: ^1.16.0-nullsafety.13
2 changes: 1 addition & 1 deletion packages/xdg_directories/test/xdg_directories_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_VIDEOS_DIR="$HOME/Videos"
''');
xdg.xdgEnvironmentOverride = (String key) => fakeEnv[key]!;
xdg.xdgEnvironmentOverride = (String? key) => fakeEnv[key];
Comment thread
yash1200 marked this conversation as resolved.
Resolved
});

tearDown(() {
Expand Down