Dart 2 async package precompilation error - dart

I'm trying to run a web app with the Dart 2 SDK using webdev. I finally got the dependencies to resolve successfully, but now pub get cannot precompile the async package.
I found this issue that seems relevant, but the pub global run workaround they suggested did not work: https://github.com/dart-lang/pub/issues/1932
pubspec.yaml
environment:
sdk: '>=2.0.0-dev.68.0 <3.0.0'
dependencies:
browser_detect: ^1.0.4
dnd: ^1.2.0
firebase: ^0.5.0
gorgon: ^0.14.2
intl: ^0.15.6
jsonx: ^2.0.2
slack: ^1.2.2
stagexl: ^1.3.1+4
xml: ^3.0.0
dev_dependencies:
build_runner: '>=0.8.10 <0.10.0'
build_web_compilers: '>=0.3.6 <0.5.0'
pub get
Dart VM version: 2.0.0-dev.69.0 (Unknown timestamp) on "linux_x64"
Resolving dependencies...
Overriding the upper bound Dart SDK constraint to <=2.0.0-dev.69.0 for the following packages:
args, async, browser, browser_detect, coUemoticons, convert, cou_toolkit, edit_distance, firebase, fixnum, glob, gorgon, graphs, http_parser, js, jsonx, libld, logging, meta, petitparser, pub_semver, quiver, quiver_iterables, scproxy, slack, source_span, stack_trace, stagexl, string_scanner, transmit, typed_data, xml
To disable this you can set the PUB_ALLOW_PRERELEASE_SDK system environment variable to `false`, or you can silence this message by setting it to `quiet`.
Got dependencies!
Precompiling executables...
Failed to precompile build_runner:graph_inspector:
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:56:10: Error: The return type of the method 'TypeSafeStream::firstWhere' is dart.async::Future<dynamic>, which does not match the return type of the overridden method (dart.async::Future<#lib1::TypeSafeStream::T>).
Change to a subtype of dart.async::Future<#lib1::TypeSafeStream::T>.
Future firstWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:56:10: Error: The method 'TypeSafeStream::firstWhere' doesn't have the named parameter 'orElse' of overriden method 'Stream::firstWhere'.
Future firstWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:59:10: Error: The return type of the method 'TypeSafeStream::lastWhere' is dart.async::Future<dynamic>, which does not match the return type of the overridden method (dart.async::Future<#lib1::TypeSafeStream::T>).
Change to a subtype of dart.async::Future<#lib1::TypeSafeStream::T>.
Future lastWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:59:10: Error: The method 'TypeSafeStream::lastWhere' doesn't have the named parameter 'orElse' of overriden method 'Stream::lastWhere'.
Future lastWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:62:13: Error: The method 'TypeSafeStream::singleWhere' has fewer named arguments than those of overridden method 'Stream::singleWhere'.
Future<T> singleWhere(bool test(T element)) async =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/restartable_timer.dart:11:7: Error: The non-abstract class 'RestartableTimer' is missing implementations for these members:
'tick'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class RestartableTimer implements Timer {
^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/result/capture_transformer.dart:15:7: Error: The non-abstract class 'CaptureStreamTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class CaptureStreamTransformer<T> implements StreamTransformer<T, Result<T>> {
^^^^^^^^^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/result/release_transformer.dart:12:7: Error: The non-abstract class 'ReleaseStreamTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class ReleaseStreamTransformer<T> implements StreamTransformer<Result<T>, T> {
^^^^^^^^^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/single_subscription_transformer.dart:16:7: Error: The non-abstract class 'SingleSubscriptionTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class SingleSubscriptionTransformer<S, T> implements StreamTransformer<S, T> {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed_stream_transformer.dart:23:7: Error: The non-abstract class '_TypeSafeStreamTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class _TypeSafeStreamTransformer<S, T> implements StreamTransformer<S, T> {
^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed to precompile build_runner:build_runner:
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:56:10: Error: The return type of the method 'TypeSafeStream::firstWhere' is dart.async::Future<dynamic>, which does not match the return type of the overridden method (dart.async::Future<#lib1::TypeSafeStream::T>).
Change to a subtype of dart.async::Future<#lib1::TypeSafeStream::T>.
Future firstWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:56:10: Error: The method 'TypeSafeStream::firstWhere' doesn't have the named parameter 'orElse' of overriden method 'Stream::firstWhere'.
Future firstWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:59:10: Error: The return type of the method 'TypeSafeStream::lastWhere' is dart.async::Future<dynamic>, which does not match the return type of the overridden method (dart.async::Future<#lib1::TypeSafeStream::T>).
Change to a subtype of dart.async::Future<#lib1::TypeSafeStream::T>.
Future lastWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:59:10: Error: The method 'TypeSafeStream::lastWhere' doesn't have the named parameter 'orElse' of overriden method 'Stream::lastWhere'.
Future lastWhere(bool test(T element), {Object defaultValue()}) =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed/stream.dart:62:13: Error: The method 'TypeSafeStream::singleWhere' has fewer named arguments than those of overridden method 'Stream::singleWhere'.
Future<T> singleWhere(bool test(T element)) async =>
^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/restartable_timer.dart:11:7: Error: The non-abstract class 'RestartableTimer' is missing implementations for these members:
'tick'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class RestartableTimer implements Timer {
^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/result/capture_transformer.dart:15:7: Error: The non-abstract class 'CaptureStreamTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class CaptureStreamTransformer<T> implements StreamTransformer<T, Result<T>> {
^^^^^^^^^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/result/release_transformer.dart:12:7: Error: The non-abstract class 'ReleaseStreamTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class ReleaseStreamTransformer<T> implements StreamTransformer<Result<T>, T> {
^^^^^^^^^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/single_subscription_transformer.dart:16:7: Error: The non-abstract class 'SingleSubscriptionTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class SingleSubscriptionTransformer<S, T> implements StreamTransformer<S, T> {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
file:///home/andy/.pub-cache/hosted/pub.dartlang.org/async-1.13.3/lib/src/typed_stream_transformer.dart:23:7: Error: The non-abstract class '_TypeSafeStreamTransformer' is missing implementations for these members:
'cast'.
Try to either
- provide an implementation,
- inherit an implementation from a superclass or mixin,
- mark the class as abstract, or
- provide a 'noSuchMethod' implementation.
class _TypeSafeStreamTransformer<S, T> implements StreamTransformer<S, T> {
^^^^^^^^^^^^^^^^^^^^^^^^^^
Am I doing something wrong in my pubspec.yaml, or is there an issue with async or another package? This project has worked fine for about 4 years now, but I can't get it to work in Dart 2. Any help is appreciated.

You are depending on several libraries that haven't been updated for Dart 2. Unfortunately the only solution would be to remove these dependencies or move back to a Dart 1 SDK. For reference:
browser_detect: v 1.0.4 • Updated: Mar 2, 2016
gorgon v 0.14.2 • Updated: Dec 6, 2014
jsonx v 2.0.2 • Updated: May 19, 2016
slack 1.2.2 • Updated: Jun 6, 2015 WEB
In general, only libraries which were last updated sometime in 2018 will work in Dart 2, and usually only the very latest version. You can check the status of your dependencies by searching for the package name on pub.dartlang.org
Edit: gorgon in particular has a dependency on an older version of async, I would start by removing that

Related

Dart Mixin get super field value

Based on a class and a mixin
class CounterModel extends MVAModel with CounterModelGeneratedCode {
int counter = 2;
}
mixin CounterModelGeneratedCode on MVAModel {
int get counter => store.get("counter", () => (super as CounterModel).counter);
set counter(int value) => store.set("counter", value);
}
The dart analyzer does not complain but on compilation I get an
Error: Can't use 'super' as an expression. To delegate a constructor
to a super constructor, put the super call as an initializer.
How can I access the overshadowed values of the CounterModel class (e.g. 2 for counter)?
You cannot do that, and the analyzer should have caught the syntax error too.
You cannot override the resolution of super-invocations, you can only call the actual superclass member.
Also, the counter is not on the superclass, which is MVAModel, so using super is not the right approach.
You could try (this as CounterModel).counter, which would work, but it isn't optimal. The cast is not necessary, we can do better.
What you probably want in this case is to add a definition of the counter variable to the mixin declaration:
abstract int counter;
That way, it requires classes mixing it in to define such a counter (which the one class doing so then does).
Then you can invoke the counter in the mixin as just this.counter.

Dart - implementing a class method with argument as implemented class

I am developing external library. Assume I have different implementations of logger class, I create abstract class ILogger which those classes can then implement.
I also have various implementations of log objects that I want to adhere to ILog abstract class so I expose it as well.
The problem is when my ILogger uses ILog as argument to one of its methods. I would assume that any of my implemented logger classes (that implement ILogger) would accept any arguments that are log classes (which implement ILog).
See my constrained example below:
abstract class ILog {
const LogImpl({required this.id});
final String id;
}
class Log implements ILog {
const Log({required this.id});
final String id;
}
abstract class ILogger {
void writeLog({
required LogImpl log,
required bool persist,
});
}
class Logger implements ILogger {
void writeLog({
required Log log,
required bool persist,
}) {
print('writing $log with persistence? $persist');
}
}
void main() {
final logger = Logger();
final log = Log(id: 'abcd-1234');
logger.writeLog(log: log, persist: true)
}
For this I get error:
Error: The parameter 'log' of the method 'Logger.writeLog' has type 'Log', which does not match the corresponding type, 'ILog', in the overridden method, 'ILogger.writeLog'.
Is there a way to solve this without resorting to applying generics?
The reason why my log object ILog needs to be abstract class instead of regular class that is extended is technical. One of my serialization libraries uses source code annotation which means that this annotation cannot be part of the library (because the annotation might be different for different applications).
The program doesn't compile because it's not sound.
Dart, and object oriented programming in general, is based around subtype substitutability. If your code works with an instance of a type, it works with an instance of a subtype too - the subtype can substitute for the supertype.
The Logger's writeLog method is not a valid override of the ILogger's writeLog method. The latter accepts an ILog as argument, and for the subtype to be able to substitute for that, it needs to accept an ILog too. However, it only accepts a Log, which is a subtype, and not any implementation of ILog.
One alternative is to admit that what you are writing is unsound, and tell the compiler to accept it anyway:
class Logger implements ILogger {
void writeLog({
required covariant Log log,
required bool persist,
}) {
print('writing $log with persistence? $persist');
}
}
Here the covariant tells the compiler that you know that Log does not satisfy the superclass parameter type of ILog, but it's OK. You know what you're doing, and no-one will ever call this function with something which isn't a proper Log. (And if they do anyway, it'll throw an error).
The other alternative, which is what I'd probably recommend, is to parameterize your classes on the Log it uses:
abstract class ILogger<L extends ILog> {
void writeLog({
required L log,
required bool persist,
});
}
class Logger implements ILogger<Log> {
void writeLog({
required Log log,
required bool persist,
}) {
print('writing $log with persistence? $persist');
}
}
With that, the Logger doesn't have to substitute for all ILoggers, only for ILogger<Log>, and it can do that soundly.
(Well, as soundly as the inherently unsound covariant generics allow, but the program will compile, and throw if you ever pass something which isn't a Log instance.)
In both cases the compiler will know that the argument to a Logger must be a Log. In both cases, you can fool the program by casting the Logger to the supertype ILogger/ILogger<ILog>, and then pass in an ILog to writeLog, but it takes at least a little effort to circumvent the type system.

Dart - Mark as Deprecated Documentation

I changed something in my implementations and I want to mark some classes deprecated, so that they will use the new implementations instead.
How can I mark a class as deprecated in dart? For now I only document it as deprecated without actually marking the class or crossing it out.
/// Throws a BadRequestException - 400
class BadRequestException implements Exception {}
/// Throws a NotFoundException - 404
class NotFoundException implements Exception {}
/// Throws a ConflictException - 409
class ConflictException implements Exception {}
/// [DEPRECATED]
/// Don't use this anymore, this is deprecated.
class AlreadyExistsException implements Exception {}
Found it. Deprecated Classes
#Deprecated('Use [ConflictException]')
class AlreadyExistsException implements Exception {}

Are there any sealed classes alternatives in Dart 2.0?

I have Android development background and I'm learning Flutter.
In Android it's a common practice to use Kotlin sealed classes to return a state from ViewModel e.g.
sealed class MyState {
data class Success(val data: List<MyObject>) : MyState()
data class Error(val error: String) : MyState()
}
I want to use similar pattern in Flutter and return a State object from the BLOC class. What is the best way to achieve the same in Flutter?
Such use case would be done using named factory constructors.
It requires a lot more code, but the behavior is the same.
class MyState {
MyState._();
factory MyState.success(String foo) = MySuccessState;
factory MyState.error(String foo) = MyErrorState;
}
class MyErrorState extends MyState {
MyErrorState(this.msg): super._();
final String msg;
}
class MySuccessState extends MyState {
MySuccessState(this.value): super._();
final String value;
}
Rémi Rousselet's answer is somehow correct but as sindrenm mentioned:
Unfortunately, this isn't the same thing. Kotlin sealed classes guarantee that there are no other implementations of the given class outside of the file they're defined in. That means you can exhaust when statements (switch in Dart) by just providing all possible alternatives as cases, not having to think about potential sub-classes elsewhere
While there is an active discussion about this feature on dart language: Algebraic Data Types, but there is some libraries that can help you implement this behavior. You can use this libraries:
Sealed Unions
Super Enum
Sealed Class
And if you are using BLoC library you can use this lib:
Sealed Flutter Bloc
I hope that dart language add this feature ASAP
Soon Dart is going to support sealed classes.
GitHub Code: source
sealed class Either {}
class Left extends Either {}
class Right extends Either {}
You can now test the sealed class
test(Either either) {
switch (either) {
case Left(): print('Left');
case Right(): print('Right');
}
}
Here is the package for the Sealed Classes/Unions in Flutter
Freezed
This Package provided the features to deal with Data Classes, Sealed Class in Dart/Flutter
Here is the link which explains the beast use of freezed package in Flutter
Use of Freezed Package in Flutter/Dart

Use of a mixin with the exit code

Mixin Problem
Without the use of a mixin, the following code in the default_project works:
abstract class ProjectGen extends ConceptEntity<Project> {
With the use of the ConceptEntity mixin, there is a problem, without an error message, with the exit code=139 on Ubuntu 14.04 LTS, and the exit code=-1073741819 on Windows 7.
abstract class ProjectGen extends Object with ConceptEntity<Project> {
The restrictions on the ConceptEntity mixin in dartling are fulfilled:
ConceptEntity does not declare a constructor.
Its superclass is Object.
It does not ontain calls to super.
default_project
https://github.com/dzenanr/default_project
ProjectGen in lib/gen/default/project/projects.dart
dartling
https://github.com/dzenanr/dartling
ConceptEntity in lib/domain/model/entity.dart
class ConceptEntity<E extends ConceptEntity<E>> implements EntityApi {

Resources