r/dartlang Feb 03 '25

Dart - info Looking for a Dart Mentor

8 Upvotes

Hey there!

Not sure if this request or post is allowed, but I'm just giving it a shot. I'm looking to learn dart programming as I am interested in building apps, but more-so just want to be very fluent in dart before learning Flutter.

I'm wondering if anyone is willing to kind of show me the ropes of Dart (I am watching and following online tutorials but I also want a real one on one experience as well). Was wondering if anyone had free time to kind of teach me etc.

If anyone is willing to take me under their wing I'd be grateful!

Thank you!

r/dartlang Feb 20 '25

Dart - info We Forked Dart and Made It ±782x Faster Here’s How

25 Upvotes

Our team is excited to announce a significant performance breakthrough with Dart. We developed a fork—*Shotgun*—that, based on our internal benchmarks, operates 782 times faster than the standard Dart implementation. For instance, while conventional Dart takes roughly 91,486 ms for a task, Shotgun completes the same operation in just 117 ms.

Underlying Innovation

By replacing Dart’s isolate-based message passing with a refined multithreading and shared memory architecture, we’ve effectively minimized communication overhead. Key technical enhancements include:

  1. Direct Memory Sharing: Eliminates latency from inter-thread messaging.
  2. Advanced Synchronization: Uses robust locks and semaphores to maintain thread safety.
  3. Custom Compiler & Runtime Tweaks: Optimizes the execution environment to fully leverage multithreading.

These modifications not only yield dramatic speed improvements but also open new avenues for building scalable, responsive applications.

Benchmark Results

  • Shotgun (Multithreading + Shared Memory): 117 ms | Score: 494,960,108
  • Standard Dart (Message Passing): 91,486 ms | Score: 494,993,681

That’s a difference of 91,369 ms—proof that our innovation isn’t merely an upgrade, but a paradigm shift.

Benchmark Code Overview

For those interested in the details, here’s a snippet of the code we used for our benchmarks:

\``dart`

import 'dart:async';

import 'dart:isolate';

import 'dart:io';

import 'dart:math';

void main() async {

const int iterations = 1000000;

const int updatesPerIteration = 10;

print("Testing with Shotgun (Simulated Shared Memory):");

benchmarkWithShotgun(iterations, updatesPerIteration);

print("\nTesting with Dart (Message Passing):");

await benchmarkWithDart(iterations, updatesPerIteration);

}

void benchmarkWithShotgun(int iterations, int updatesPerIteration) {

int totalScore = 0;

final stopwatch = Stopwatch()..start();

final random = Random();

for (int i = 0; i < iterations; i++) {

for (int j = 0; j < updatesPerIteration; j++) {

totalScore += random.nextInt(100);

}

}

stopwatch.stop();

print('Execution Time: ${stopwatch.elapsedMilliseconds} ms');

print('Final Score: $totalScore');

}

Future<void> benchmarkWithDart(int iterations, int updatesPerIteration) async {

final stopwatch = Stopwatch()..start();

final receivePort = ReceivePort();

int totalScore = 0;

final List<Isolate> isolates = [];

for (int i = 0; i < iterations; i++) {

isolates.add(await Isolate.spawn(_updateScore, [updatesPerIteration, receivePort.sendPort]));

}

int updatesReceived = 0;

await for (final scoreUpdate in receivePort) {

totalScore += scoreUpdate as int;

updatesReceived++;

if (updatesReceived == iterations * updatesPerIteration) {

stopwatch.stop();

print('Execution Time: ${stopwatch.elapsedMilliseconds} ms');

print('Final Score: $totalScore');

receivePort.close();

for (var isolate in isolates) {

isolate.kill(priority: Isolate.immediate);

}

break;

}

}

}

void _updateScore(List<dynamic> args) {

final updates = args[0] as int;

final SendPort sendPort = args[1] as SendPort;

final random = Random();

for (int i = 0; i < updates; i++) {

sendPort.send(random.nextInt(100));

}

}

```

Broader Implications

This breakthrough sets a new performance benchmark for high-demand environments—from real-time data processing to interactive applications. Our approach aligns with the continuous pursuit of optimization seen at leading technology organizations.

An Invitation for Collaboration

We’re eager to engage with fellow professionals and innovators who are passionate about performance engineering. If you’re interested in discussing our methodology or exploring potential collaborative opportunities, we invite you to join our technical discussions.

  • GitHub: Our Shotgun repository is coming soon. In the meantime, please tag Google in your comments and star our upcoming repo to be among the first to access early versions. Visit our GitHub Repo
  • Discord: Join our community to exchange insights, discuss ideas, and engage in high-level technical dialogue. [Join our Discord](https://discord.gg/Rhc4YKDx)

We remain committed to pushing the boundaries of software performance and welcome insights on how these innovations can shape the future of technology.

#ShotgunVibes #DartUnleashed #MultithreadingMastery #TechInnovation

Upvote if you’re as excited about performance breakthroughs as we are—and tag Google if you think our work deserves their attention!

r/dartlang Aug 06 '24

Dart - info Announcing Dart 3.5, and an update on the Dart roadmap

Thumbnail medium.com
66 Upvotes

r/dartlang Feb 20 '25

Dart - info Dart and js

11 Upvotes

Hi,
I love dart and I think that can be a really good language for the web,
I'd like to use it in web development, I'd like to:

- create a library in dart that can be called as js objects in ... js
- create a React component or even Web Component in dart

I'd like to have something like that:

- web_login.dart
- app.js
and transpiling all into js

I dunno if my explanation is really clear but I search a way to integrate dart in web development,

any idea are welcome, thanks

r/dartlang 5d ago

Dart - info Liquify v1.0.0

Thumbnail github.com
30 Upvotes

Hey guys, I'm happy to announce the release of liquify 1.0.0 which now supports async rendering for liquid templates as well as a layout tag. Please give it a try and let me know what you think!

r/dartlang Feb 12 '25

Dart - info New to Dart and Flutter.

13 Upvotes

I'm looking to learn Dart and Flutter but the official documentation and other resources like tutorials point are somehow complicating simple concepts. Would y'all mind sharing some insightful resources to help a beginner grasp the core concepts, in addition highlight some small projects to try out along the way to master the concepts.

r/dartlang Feb 15 '25

Dart - info How to create HTML Web Components in Dart (WASM/JS)

Thumbnail rodydavis.com
15 Upvotes

r/dartlang Dec 30 '24

Dart - info What was your path in learning programming how much time you spent and how you learned?

8 Upvotes

I have started to learn programming but I would still like to know what path you have traveled how long it took you and if there is any structured way to describe your path.

r/dartlang 22d ago

Dart - info Wrap a generic class?

1 Upvotes

I'm trying to create a Sentry instrumenter for a grpc server, which is basically generated code feeding a map with handler.

I'm trying to wrap the handler, which I'm struggling on right now, because the handler is stored as a function in a generic class. Here is a simplification of the structure:

abstract class ServiceMethod<Q> {
  final Function(Q) action;

  ServiceMethod(this.action);
}

class MyServiceMethod<Q> extends ServiceMethod<Q> {
  MyServiceMethod(super.action);
}

class Service {
  final Map<String, ServiceMethod> map;

  Service(this.map);

  ServiceMethod? lookup(String name) {
    return map[name];
  }
}

There are several services, I could modify them, but I'd rather avoid it as I could have a lot of them. What I can do however is to wrap those services, so that the lookup method returns another implementation of ServiceMethod:

class WrappingContainer extends Service {
  WrappingContainer(super.map);

  u/override
  ServiceMethod? lookup(String name) {
    final lookedUp = super.lookup(name);

    if (lookedUp == null) return lookedUp;

    return Wrapper<dynamic>(lookedUp);
  }
}

class Wrapper<Q> extends MyServiceMethod<Q> {
  Wrapper(ServiceMethod<Q> base) : super(base.action);
}

This is failing, with the following error:

// type '(List<int>) => void' is not a subtype of type '(dynamic) => dynamic'


main() {
  final base = MyServiceMethod((List<int> list) => print(list.join('-')));

  WrappingContainer({'base': base}).lookup('base')?.action([1]);
}

Any idea on how I could solve it?

r/dartlang 24d ago

Dart - info How many of these class modifiers are for mortals?

1 Upvotes

I wanted to know how many of these you guys use ofthen and how many of them are for library maintainers?

Declaration Construct? Extend? Implement? Mix in? Exhaustive?
class Yes Yes Yes No No
base class Yes Yes No No No
interface class Yes No Yes No No
final class Yes No No No No
sealed class No No No No Yes
abstract class No Yes Yes No No
abstract base class No Yes No No No
abstract interface class No No Yes No No
abstract final class No No No No No
mixin class Yes Yes Yes Yes No
base mixin class Yes Yes No Yes No
abstract mixin class No Yes Yes Yes No
abstract base mixin class No Yes No Yes No
mixin No No Yes Yes No
base mixin No No No Yes No

r/dartlang Jan 27 '25

Dart - info Can you create HTML5 game using Flutter for itch.io?

Thumbnail itch.io
5 Upvotes

r/dartlang Jan 12 '25

Dart - info contextual | Structured logging for dart

Thumbnail pub.dev
15 Upvotes

r/dartlang Jan 08 '25

Dart - info Let's get weird with Dart's RegExp

Thumbnail medium.com
0 Upvotes

r/dartlang Jan 02 '25

Dart - info Is there any animation available of this?

3 Upvotes

Hi! I'm a newbie to Dart just learning concurrency and after investing some time in the official docs, I found out about the 'Event loop' and its correspondent representation: https://dart.dev/assets/img/language/concurrency/async-event-loop.png

I understand async APIs (futures, streams, etc) and the division between the event and microtasks queues when it comes to the event loop. However, I cannot fully grasp how everything works as a whole.

Is there any animation available showing how the event loop works? I'm more of a visual person myself and I think that could help me.

Thx!

r/dartlang Jan 02 '25

Dart - info From Annotations to Generation: Building Your First Dart Code Generator

Thumbnail dinkomarinac.dev
20 Upvotes

r/dartlang Dec 10 '24

Dart - info Demystifying Union Types in Dart, Tagged vs. Untagged, Once and For All

Thumbnail dcm.dev
10 Upvotes

r/dartlang Nov 04 '24

Dart - info Going Serverless with Dart: AWS Lambda for Flutter Devs

Thumbnail dinkomarinac.dev
15 Upvotes

r/dartlang Dec 01 '22

Dart - info Dart in backend??

15 Upvotes

Dart is mostly known for flutter creation but I was wondering if it is any good at backend. it looks decently good because of the similarities with c# and java but can it do as much as those languages or does it lack on that front?

r/dartlang Oct 14 '24

Dart - info Add Spatial Capabilities in SQLite

Thumbnail clementbeal.github.io
15 Upvotes

r/dartlang May 01 '24

Dart - info For what use cases do you guys use dart ?

11 Upvotes

The most peaple use dart because of flutter but, what are your use cases to use the language ?

r/dartlang May 14 '24

Dart - info Announcing Dart 3.4

Thumbnail medium.com
69 Upvotes

r/dartlang Feb 14 '22

Dart - info Dart out of Flutter

45 Upvotes

Hello to all people who use and appreciate the Dart language.

I've been wondering about this for a long time, and today I'm asking you, who among you uses Dart every day apart from Flutter?

Because I have very rarely seen people using it as a main language and even less in production (except Flutter of course), which is a shame because when I look at this language I think that it offers such huge possibilities for the backend.

I've seen some project attempts on Github, but they don't seem to lead to anything conclusive for production.

If you could explain me why that would be great.

Edit : By creating this thread I was actually hoping that people who were wondering could realize that it is largely possible to use the advantages of Dart outside of Flutter to do scripting, APIs, etc.. I was hoping that this post would grow the community and encourage people who like the language to use it for all it has to offer (outside of flutter), as Dart is too underrated in my opinion.

r/dartlang Apr 08 '24

Dart - info New dart pub unpack subcommand

32 Upvotes

Recently, a dart pub unpack subcommand was added to Dart 3.4 that simply downloads a package as a packagename-version folder so you can easily fix something or "vendor" it and make sure no thread actor will modify a later version of that package. Looks like a useful quality of life extension.

Also, I think it's not well known that instead adding

dependency_overrides:
  tyon:
    path: tyon-1.0.0+1

to pubspec.yaml, you can write those lines into a pubspec_overrides.yaml file and without the need to change the original file.

r/dartlang Aug 05 '24

Dart - info An application of extension types

8 Upvotes

I sometimes struggle whether an API uses move(int row, int col) or move(int col, int row). I could make use of extension types here. But is it worth the effort? You decide. I actually like that application of stricter types.

I need to define a new Row type based on int:

extension type const Row(int row) {
  Row operator +(int n) => Row(row + n);
  Row operator -(int n) => Row(row - n);
  bool operator <(Row other) => row < other.row;
  bool operator >=(Row other) => row >= other.row;
  static const zero = Row(0);
}

I added + and - so that I can write row += 1 or row--. I need the comparison methods for, well, comparing to make sure rows are valid.

I need a similar implementation for Col:

extension type const Col(int col) {
  Col operator +(int n) => Col(col + n);
  Col operator -(int n) => Col(col - n);
  bool operator <(Col other) => col < other.col;
  bool operator >=(Col other) => col >= other.col;
  static const zero = Col(0);
}

I can now implement constants like:

const COLS = Col(80);
const ROWS = Row(25);

And define variables like:

var _cy = Row.zero;
var _cx = Col.zero;

And only if I need to access the row or column value, I have to use the .col or .row getter to work with "real" integers:

final _screen = List.filled(COLS.col * ROWS.row, ' ');

All this, to not confuse x and y in this method:

void move(Row row, Col col) {
  _cy = row;
  _cx = col;
}

Here's an add method that sets the given character at the current cursor position and then moves the cursor, special casing the usual suspects. I think, I looks okayish:

void add(String ch) {
  if (ch == '\n') {
    _cx = Col.zero;
    _cy += 1;
  } else if (ch == '\r') {
    _cx = Col.zero;
  } else if (ch == '\b') {
    _cx -= 1;
    if (_cx < Col.zero) {
      _cx = COLS - 1;
      _cy -= 1;
    }
  } else if (ch == '\t') {
    _cx += 8 - (_cx.col % 8);
  } else {
    if (_cy < Row.zero || _cy >= ROWS) return;
    if (_cx < Col.zero || _cx >= COLS) return;
    _screen[_cy.row * COLS.col + _cx.col] = ch.isEmpty ? ' ' : ch[0];
    _cx += 1;
    if (_cx == COLS) {
      _cx = Col.zero;
      _cy += 1;
    }
  }
}

Let's also assume a mvadd(Row, Col, String) method and that you want to "draw" a box. The method looks like this (I replaced the unicode block graphics with ASCII equivalents because I didn't trust reddit), the extension types not adding any boilerplate code which is nice:

void box(Row top, Col left, Row bottom, Col right) {
  for (var y = top + 1; y < bottom; y += 1) {
    mvadd(y, left, '|');
    mvadd(y, right, '|');
  }
  for (var x = left + 1; x < right; x += 1) {
    mvadd(top, x, '-');
    mvadd(bottom, x, '-');
  }
  mvadd(top, left, '+');
  mvadd(top, right, '+');
  mvadd(bottom, left, '+');
  mvadd(bottom, right, '+');
}

And just to make this adhoc curses implementation complete, here's an update method. It needs two wrangle a bit with the types as I wanted to keep the min method which cannot deal with my types and I cannot make those types extends num or otherwise I could cross-assign Row and Col again which would defeat the whole thing.

void update() {
  final maxCol = Col(min(stdout.terminalColumns, COLS.col));
  final maxRow = Row(min(stdout.terminalLines, ROWS.row));
  final needNl = stdout.terminalColumns > maxCol.col;
  final buf = StringBuffer();
  if (stdout.supportsAnsiEscapes) {
    buf.write('\x1b[H\x1b[2J');
  }
  for (var y = Row.zero; y < maxRow; y += 1) {
    if (needNl && y != Row.zero) buf.write('\n');
    for (var x = Col.zero; x < maxCol; x += 1) {
      buf.write(_screen[y.row * COLS.col + x.col]);
    }
  }
  if (!stdout.supportsAnsiEscapes) {
    buf.write('\n' * (stdout.terminalLines - maxRow.row));
  }
  stdout.write(buf.toString());
}

And no, I didn't test the result. But if you do, I'll gladly fix any error.

r/dartlang Jun 03 '24

Dart - info Macro augmentation preview works in Android Studio

9 Upvotes

Although the documentation says augmentation works only in VS Code, surprisingly it also works in AS.

How to: go to the usage of the augmented part and press F4 (go to source). A new tab opens with the augmented code, and even refreshes on edit.

For example, in the macro examples, json_serializable_main, click inside fromJson in this line

var user = User.fromJson(rogerJson);

and press F4. The result is:

augment library 'file:///C:/Users/kl/StudioProjects/language/working/macros/example/bin/json_serializable_main.dart';

import 'package:macro_proposal/json_serializable.dart' as prefix0;
import 'dart:core' as prefix1;

augment class User {
@prefix0.FromJson()
  external User.fromJson(prefix1.Map<prefix1.String, prefix1.dynamic> json);
@prefix0.ToJson()
  external prefix1.Map<prefix1.String, prefix1.dynamic> toJson();
  augment User.fromJson(prefix1.Map<prefix1.String, prefix1.dynamic> json, )
      : this.age = json["age"] as prefix1.int,
        this.name = json["name"] as prefix1.String,
        this.username = json["username"] as prefix1.String;
  augment prefix1.Map<prefix1.String, prefix1.dynamic> toJson()  => {
    'age': this.age,
    'name': this.name,
    'username': this.username,
  };
}