-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
- Dart version and tooling diagnostic info (
dart info)
If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.
#### General info
- Dart 3.5.2 (stable) (Wed Aug 28 10:01:20 2024 +0000) on "windows_x64"
- on windows / "Windows 10 Home" 10.0 (Build 22631)
- locale is en-US
#### Project info
- sdk constraint: '>=3.4.0 <4.0.0'
- dependencies: appwrite, auto_size_text, badges, beamer, carousel_slider, croppy, cupertino_icons, device_info_plus, dropdown_button2, file_picker, flutter, flutter_animate, flutter_bloc, flutter_blue_plus, flutter_cache_manager, flutter_quill, flutter_svg, flutter_xlider, get_it, gradient_borders, image_size_getter, intl, marquee, octo_image, onboarding_overlay, open_file, path_provider, pdf, permission_handler, photo_view, printing, provider, regexpattern, responsive_framework, result_dart, shared_preferences, sliver_tools, smooth_page_indicator, sticky_headers, super_banners, url_launcher, uuid, vector_math, video_player, visibility_detector, web, webview_flutter, webview_flutter_web
- dev_dependencies: flutter_launcher_icons, flutter_lints, flutter_test, test
- elided dependencies: 7
#### Process info
| Memory | CPU | Elapsed time | Command line |
| -----: | --: | -----------: | ------------ |
| 40 MB | -- | | dart.exe |
| 724 MB | -- | | dart.exe |
| 49 MB | -- | | dart.exe |
| 19 MB | -- | | dart.exe |
| 95 MB | -- | | dart.exe |-
Whether you are using Windows, macOS, or Linux (if applicable)
Tested on Windows -
Whether you are using Chrome, Safari, Firefox, Edge (if applicable)
On Android
While compiling stub code, our team had repeatable crashes during compilation for android. Only after one of us deleted pubspec lock file and re-ran flutter pub get, changed Kotlin to version 2.0.21 from 1.7.10 it was able to compile. Here was the following compilation errors:
Unhandled exception:
Null check operator used on a null value
#0 TextualOutlineListener.endShow (package:front_end/src/util/textual_outline.dart:877)
#1 ForwardingListener.endShow (package:_fe_analyzer_shared/src/parser/forwarding_listener.dart:1185)
#2 ImportRecoveryListener.endShow (package:_fe_analyzer_shared/src/parser/recovery_listeners.dart:67)
#3 Parser.parseShow (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1177)
#4 Parser.parseCombinatorStar (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1142)
#5 Parser.parseImportRecovery (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1016)
#6 Parser.parseImport (package:_fe_analyzer_shared/src/parser/parser_impl.dart:932)
#7 Parser.parseTopLevelKeywordDeclaration (package:_fe_analyzer_shared/src/parser/parser_impl.dart:731)
#8 Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:532)
#9 Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:412)
#10 textualOutline (package:front_end/src/util/textual_outline.dart:458)
#11 IncrementalCompiler._initializeExperimentalInvalidation (package:front_end/src/base/incremental_compiler.dart:1248)
#12 IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/base/incremental_compiler.dart:306)
<asynchronous suspension>
#13 CompilerContext.clear (package:front_end/src/base/compiler_context.dart:128)
<asynchronous suspension>
#14 IncrementalCompiler.compile (package:vm/incremental_compiler.dart:77)
<asynchronous suspension>
#15 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:636)
<asynchronous suspension>
#16 listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1385)
<asynchronous suspension>
2
the Dart compiler exited unexpectedly.While the line number is different to upstream, I can see that the null-assert operator is being used without any safety checks, so it must be expected to not fail here - yet it does.
https://github.com/dart-lang/sdk/blob/main/pkg/front_end/lib/src/util/textual_outline.dart#L874
Our code. We were experimenting with making our first cross-platform library. So the code is bare minimal.
stub.dart
import 'dart:typed_data';
import 'package:project/common/utility/platform_file_utils_impl/base.dart';
import 'package:project/constants/enums.dart';
class PlatformFileUtilities extends BaseFileUtilities {
@override
void downloadFile(Uint8List bytes, String filename) {}
@override
Future<Uint8List> loadLocalFileAsBytes(String path) async {
return Uint8List.fromList([]);
}
@override
void openFile(Uint8List bytes, MimeType mimeType) {}
}mobile.dart
import 'dart:typed_data';
import 'package:project/constants/all.dart' as k;
import 'package:project/common/utility/platform_file_utils_impl/base.dart';
class PlatformFileUtilities implements BaseFileUtilities {
@override
void downloadFile(Uint8List bytes, String filename) {}
@override
Future<Uint8List> loadLocalFileAsBytes(String path) async {
return Uint8List.fromList([]);
}
@override
void openFile(Uint8List bytes, k.MimeType mimeType) {
// TODO: implement openFile
}
}web.dart
import 'dart:typed_data';
import 'package:project/constants/all.dart' as k;
import 'package:project/common/utility/platform_file_utils_impl/base.dart';
import 'dart:convert' show base64Encode;
import 'package:web/web.dart' as web;
import 'dart:js_interop';
@JS("Blob")
extension type Blob._(JSObject _) implements JSObject {
external factory Blob(JSArray<JSArrayBuffer> blobParts, JSObject? options);
factory Blob.fromBytes(List<int> bytes, k.MimeType fileType) {
final data = Uint8List.fromList(bytes).buffer.toJS;
return Blob([data].toJS, web.BlobPropertyBag(type: fileType.name));
}
external JSArrayBuffer? get blobParts;
external JSObject? get options;
}
class PlatformFileUtilities implements BaseFileUtilities {
@override
void downloadFile(Uint8List bytes, String filename) {
/// downloads file
final web.HTMLAnchorElement anchor =
web.document.createElement('a') as web.HTMLAnchorElement
..href = "data:application/octet-stream;base64,${base64Encode(bytes)}"
..style.display = 'none'
..download = filename;
/// not quite certain what this actually does
web.document.body!.appendChild(anchor);
// simulates a click to download the file
// (as we arent displaying a download prompt we need to do this)
anchor.click();
/// supposed to clean up
web.document.body!.removeChild(anchor);
}
@override
Future<Uint8List> loadLocalFileAsBytes(String path) {
// TODO: implement loadFileAsBytes
throw UnimplementedError();
}
@override
void openFile(Uint8List bytes, k.MimeType mimeType) {
/// creates a blob from our bytes and formats it so that it will display as a pdf
/// Note: the extension names are very particular and I assume they are html/web specific
final Blob blob = Blob.fromBytes(bytes, k.MimeType.pdf);
// Generate URL object from blob
final url = web.URL.createObjectURL(blob);
// opens a window using our blobs url in a new tab
web.window.open(
url,
'_blank',
);
web.URL.revokeObjectURL(url);
}
}platform_file_utils.dart
export 'package:project/common/utility/platform_file_utils_impl/stub.dart'
if (dart.library.io) 'package:project/common/utility/platform_file_utils_impl/mobile.dart'
if (dart.library.js_interop) 'package:project/common/utility/platform_file_utils_impl/web.dart';enums.dart
This file is commonly exported by package:project/constants/all.dart in our project as k.
enum MimeType {
jpeg(name: 'image/jpeg'),
pdf(name: 'application/pdf');
final String name;
const MimeType({required this.name});
}Finally in main, just include and use it like so:
import 'package:project/common/utility/platform_file_utils.dart';
int main() {
final PlatformFileUtilities fileUtils = PlatformFileUtilities();
final Uint8List bytes = Uint8List.fromList([]);
final fileName = "test.pdf";
fileUtils.downloadFile(bytes, fileName);
}