Skip to content

Commit ca59b52

Browse files
committed
Support non-ASCII characters
1 parent 52a8e3f commit ca59b52

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

docs/Usage/Storage Access Framework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ final Uint8List? fileContent = await getDocumentContent(uri);
161161
/// Handle [fileContent]...
162162
163163
/// If the file is intended to be human readable, you can convert the output to [String]:
164-
print(String.fromCharCodes(fileContent));
164+
print(utf8.decode(fileContent));
165165
```
166166

167167
### <samp>getRealPathFromUri</samp>

example/lib/utils/document_file_utils.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:fl_toast/fl_toast.dart';
24
import 'package:flutter/material.dart';
35
import 'package:flutter/services.dart';
@@ -67,7 +69,7 @@ extension ShowDocumentFileContents on DocumentFile {
6769
return Image.memory(content);
6870
}
6971

70-
final contentAsString = String.fromCharCodes(content);
72+
final contentAsString = utf8.decode(content);
7173

7274
final fileIsEmpty = contentAsString.isEmpty;
7375

lib/src/saf/saf.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:convert';
23
import 'dart:io';
34
import 'dart:typed_data';
45

@@ -573,7 +574,7 @@ Future<String?> getDocumentContentAsString(
573574
}) async {
574575
final Uint8List? bytes = await getDocumentContent(uri);
575576

576-
return bytes?.apply((Uint8List a) => String.fromCharCodes(a));
577+
return bytes?.apply((Uint8List a) => utf8.decode(a));
577578
}
578579

579580
/// {@template sharedstorage.saf.getDocumentContentAsString}

0 commit comments

Comments
 (0)