Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 07 2019 18:54
    @timsneath banned @hpoit
Matias Meno
@enyo
Does anyone know how to get the info if a variable is nullable with dart mirrors?

Like, with this simple class:

class Foo {
  String? bar;
  Foo(this.bar);
}

I can iterate over the properties like this:

  final classMirror = reflectClass(Foo);

  classMirror.declarations.forEach((symbol, declarationMirror) {
    if (declarationMirror is VariableMirror) {
      // How to know if declarationMirror.type is nullable?
    }
  });
Nate Bosch
@natebosch
I don't think we ever added nullability to the mirrors APIs.
Jacob MacDonald
@jakemac53
Correct, and there is no plan to afaik
Anything like patch-package in pub of Dart?
Jacob MacDonald
@jakemac53
Not that I am aware of, pub doesn't have post-install hooks and it also uses a global cache which this would corrupt. But you can clone the repo for the package you need to patch and then use a path dependency on your local copy with the edits.
sunbreak
@sunbreak:matrix.org
[m]
Thanks. An issue on https://github.com/dart-lang/pub may be a better place to collect discussion
Jacob Bang
@julemand101
@jakemac53 I think this can do it if you make your own fork of the package: https://dart.dev/tools/pub/dependencies#dependency-overrides
(the question got asked multiple places so I linked to that in one of the other places)
Jacob MacDonald
@jakemac53
Yes you likely would need to put the path dependency in the dependency_overridessection.
Olzhas Suleimen
@ykmnkmi
Is Dart language parser generated from specs?
I can't use the analyzer in the web application
Simon Binder
@simolus3
@ykmnkmi I think an up-to-date ANTLR grammar is available somewhere, but the parser used for the analyzer and the frontend are hand-written here. They don't import dart:io a lot, so you may find a way to run that on the web.
Olzhas Suleimen
@ykmnkmi
@simolus3 thanks for ANTRL, parseString from analyzer don't work in web.
Olzhas Suleimen
@ykmnkmi
compiles with dart2js but not with build_web_compilers
Graciliano Monteiro Passos
@gmpassos
FYI:
Severe SIMD degradation in Dart VM 2.15.0-178.1.beta:
dart-lang/sdk#47488
dizeros
@dizeros
Hello everyone, I have deleted the data and cookies from chrome and my data in dartpad deleted which was i written how to recover help me pls?
Jacob Bang
@julemand101
@dizeros So you had some code in DartPad which got removed by your cleaning and you would have saved?
In that case, I am sorry but you cannot restore the code then since all code in DartPad is saved locally
dizeros
@dizeros
@julemand101 πŸ˜”πŸ˜” πŸ₯ΊπŸ˜ͺok thanks
Jacob Bang
@julemand101
@dizeros Maybe time to install a development environment on your computer instead of doing it inside a browser ;)
randiaz95
@randiaz95
Hi! How is everyone today?
Does any1 have a link to the docs for basic array <String>{}? I can only find List docs...
Maybe I should only use Lists?
Simon Binder
@simolus3
@randiaz95 Yes, there is no visible array type in Dart - just use lists. A non-growable list (set growable: false in the constructor) is the closest you can get to arrays.
Graciliano Monteiro Passos
@gmpassos
Gameel Ali
@aleinei
what to do when getting this:
Library Dart Packages has broken classes paths:
Jacob Bang
@julemand101
@aleinei Is that the full error? What are you doing when it happens?
6heads
@6heads

something seems to have changed language-wise, I wanted to initialize sqflite in a singleton just once

  DatabaseHelper._privateConstructor();
  static final DatabaseHelper instance = DatabaseHelper._privateConstructor();

  static Database _database;

  Future<Database> get database async {
    if (_database != null) return _database;
    // lazily instantiate the db the first time it is accessed
    _database = await _initDatabase();
    return _database;
  }

but it complains about:
Non-nullable instance field '_database' must be initialized.
Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'.dartnot_initialized_non_nullable_instance_field

what do I need to change?

Patrick Minogue
@afpatmin
Dart recently had a major update in which variables are "NNBD" ("Non Nullable By Default"). To make a variable nullable, add a '?' to the type;
static Database? _database;
@6heads
corecode
@2:0x2c.org
[m]
hi
i'm new to dart, and i'm trying to figure out what an idiomatic way is to have my class accept objects that conform to an interface I have defined, including a class from some other package. Is there a way to mark a foreign class that it implements my interface? how is this usually handled?
corecode
@2:0x2c.org
[m]
specifically, i'm implementing DNS-SD, and want to accept an instance of MDnsClient, but also some other resolver (i.e. one that would use normal DNS queries). I have defined a DnsResolver abstract class, and I accept that as argument. But of course MDnsClient does not implement my DnsResolver.
Jacob Bang
@julemand101
@2:0x2c.org I would make two methods/constructors. One taking your type, and another taking a MDnsClient
corecode
@2:0x2c.org
[m]
but how do i store that argument? it's different types then
I have the feeling that I'm already so tightly coupled to multicast_dns's classes that maybe I should just require something that implements MDnsClient.
Jacob Bang
@julemand101
Maybe. It sounds like a problematic design you are trying to do. :)
You could make a class which implements DnsResolver and encapsulate MDnsClient
So it forwards calls to the MDnsClient instance inside it
@2:0x2c.org
Your method taking a MDnsClient as argument could then create an instance of this new class and save that instance
corecode
@2:0x2c.org
[m]
yea that's what i'm doing right now, with extends MDnsClient implements DnsResolver
Jacob Bang
@julemand101
@2:0x2c.org You don't even need the extends part. I would just implement and forward requests
But do what works for you :)
Olzhas Suleimen
@ykmnkmi
is or comment refers to b?
// a
void a() {}

// or

// b
void b() {}
cjcdev
@cjcdev
Quick question: Is there a way to get package version from code?
bpilot
@bpilot
Is there way to do this: class INode<T extends INode> { List<T> children = []; }
The problem is recursively satisfying the T parameter is impossible. What's a workaround?
bpilot
@bpilot
Think I need two types, one which avoids mentioning the children field.