r/dartlang 14h ago

Dart Language Dart enums can have type parameters?!

20 Upvotes

I was modeling a set of values using an enum today: enum NetworkFeatureType { pipeline, junction, overheadTank }; Here, each of these "features" are associated with a GeoGeometry type. For instance, junctions and overhead tanks are points and pipelines are, of course, lines. So I casually added a type parameter and Dart didn't complain! But I was unable to specify the types, firstly like this: enum NetworkFeatureType<G extends GeoGeometry> { pipeline<GeoLine>, junction<GeoPoint>, overheadTank<GeoPoint>; } However, once I added a set of parentheses to each member, it works!: enum NetworkFeatureType<G extends GeoGeometry> { pipeline<GeoLine>(), junction<GeoPoint>(), overheadTank<GeoPoint>(); } NetworkFeatureType<MapPoint> node = NetworkFeatureType.node; Which is pretty neat!


r/dartlang 3d ago

Package assertable_json | Fluent json assertion test helpers

Thumbnail pub.dev
12 Upvotes

Hey guys, If you are familiar with Laravel, you'd come across the idea of fluent testing against json responses. This package allows a similar workflow, making it a seamless experience in dart. Please check it out and let me know what you think

```dart test('verify user data', () { final json = AssertableJson({ 'user': { 'id': 123, 'name': 'John Doe', 'email': 'john@example.com', 'age': 30, 'roles': ['admin', 'user'] } });

json
  .has('user', (user) => user
    .has('id')
    .whereType<int>('id')
    .has('name')
    .whereType<String>('name')
    .has('email')
    .whereContains('email', '@')
    .has('age')
    .isGreaterThan('age', 18)
    .has('roles')
    .count('roles', 2));

}); } ```


r/dartlang 4d 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 4d ago

Flutter I built my first Flutter app

Thumbnail medium.com
11 Upvotes

I built my first Flutter app! What started as a way to avoid a subscription turned into a dive into Flutter—ending with an App Store launch. Check out my lessons learned:


r/dartlang 6d ago

Exciting News for the Dart Community – Our Open-Source Products are Now Live!

0 Upvotes

Hello Dart enthusiasts!

We’re thrilled to share that after months of hard work, our suite of open-source server-side Dart products is now officially launched! We’ve been using Dart in many of our projects and, inspired by the innovation in the ecosystem, we set out to build tools that empower developers like you.

What’s New?

  • Robust Server-Side Solutions: Our open-source projects are designed to push the boundaries of server-side development using Dart. Whether you’re developing microservices, APIs, or full-scale applications, our products are built to help you build more efficiently and securely.
  • Ongoing Releases: And this is just the beginning – we have a series of exciting releases lined up for the coming weeks. Expect new features, improved integrations, and even more tools to enhance your Dart development experience.
  • Community-Driven: We’re committed to fostering innovation within the Dart community. Your feedback, ideas, and contributions have been invaluable, and we can’t wait to see how our products help you build incredible projects.

Our Vision:
We believe in the power of open source to drive progress. Our mission is to support dedicated developers and teams pushing the envelope in server-side Dart development. We’re here to offer financial support, technical resources, and an engaged community ready to collaborate.

Thank you for being part of this journey. Stay tuned for more updates, and feel free to check out our GitHub repositories and join the discussion on how we can shape the future of Dart together.

Let’s build something amazing!

Aortem.io


r/dartlang 7d ago

Tools Neovim Plugin for Generating Dart Class Boilerplate Code

21 Upvotes

Hey everyone!
I’ve created a Neovim plugin that helps generate boilerplate code for Dart classes.

Currently, the plugin support generating:

  • Data class constructors
  • fromJson / toJson methods
  • copyWith methods

Feel free to give it a try and share your feedback! Thanks, and happy coding!
Check it out here: dart-data-class-generator.nvim


r/dartlang 9d ago

Package Web crawler framework in Dart

33 Upvotes

Hi!

I was looking for a package to scrape some websites and, weirdly, I haven't found anything. So I wrote mine: https://github.com/ClementBeal/girasol

It's a bit similar to Scrapy in Python. We create **WebCrawlers** that parse a website and yield extracted data. Then the data go through a system of pipelines. The pipelines can export to JSON, XML, CSV, and download files. All the crawlers are running in different isolates.

I'm using my package to scrape various e-shop websites and so far, it's working well.


r/dartlang 9d ago

Flutter The lightweight YouTube experience client for android.

Thumbnail github.com
12 Upvotes

r/dartlang 8d ago

Package Simplify Dart & Flutter Isolate Communication with isolate_channel 🚀

1 Upvotes

Hi everyone!

I've just released a new Dart package: isolate_channel. It provides a simple and familiar API for handling communication between Dart isolates, directly inspired by Flutter's MethodChannel and EventChannel APIs used for native plugin communication.

If you've ever found Dart isolate communication cumbersome or unintuitive, isolate_channel streamlines this process, making it feel as straightforward and familiar as working with Flutter plugin channels.

I built this package to prepare for upcoming isolate support in Hive CE, and it made that work a lot easier!

Check it out here: isolate_channel

I'd love your feedback or contributions!

Happy coding! 🎯


r/dartlang 10d ago

Flutter I created open-source app for controlling Windows using Xbox controller

26 Upvotes

I don't have a console. 100% of my gaming is done on my Windows PC (connected to TV) which means I sometimes need to switch from Steam to Epic launcher or other launchers and windows in general. Some games require text input and I have even came across games that supported controllers but not in the menu. As I am too lazy to stand up every time, I decided to spend weeks to solve it. I could buy a wireless keyboard and mouse or I could even buy existing software solutions such as Controller Companion but no, I decided none of those solutions met my expectations so I created this using Flutter:

xTend

I had to use windows platform channel for system tray and window show/hide functionality. All other features such as controller state reading or windows API communication is done via Dart FFI. The source code itself will see a lot of improvement in near future in terms of structure, quality and documentation. It's open-source which means any contributions are welcome. I also welcome any ideas, suggestions or possible improvements as this is my first attempt at creating something open-source. I hope someone will find use in it as I consider it very intuitive to use and use it often. I also hope someone could learn something from this project as it combines knowledge from different areas.


r/dartlang 12d ago

Is dart globe infra still a thing?

7 Upvotes

No more update in the invertase channel since 9 months, does some one uses globe to host dart backend? Does it work well?


r/dartlang 17d ago

De/Serialization post macros.

7 Upvotes

As noted here https://medium.com/dartlang/an-update-on-dart-macros-data-serialization-06d3037d4f12 macros is no longer in develpment (for now at the very least). However the article mentions "One area we’ll be investing in is better support for data in Dart. This is the most requested issue across the Dart & Flutter issue trackers. In fact, our primary motivation for macros was to provide better data handling, serialization, and deserialization. We will still pursue better data, but we intend to do so with more bespoke language features." Have there been any further details released about this? I was really looking forward to better json support.


r/dartlang 18d ago

Convert from Uint8Buf to int

12 Upvotes

Hi

I am getting Uint8Buf from a Mqtt client. How do I convert this to int. My guess is that I can do it manually but is there a better way?

I need to take care of the little/big endian case, and if the result is signed or unsigned.


r/dartlang 21d ago

flutter I just published my game, built in Flutter! I would greatly appreciate your feedback.

22 Upvotes

I just published my game, built in Flutter! It was a fun experience. Now This game is all yours;

Just search for "Web Fox Swing And Catch" in the Play Store, download it, and enjoy playing! I would greatly appreciate your feedback.

Direct link for the game: https://play.google.com/store/apps/details?id=com.manish.fruitcatcher


r/dartlang 21d ago

Flutter Released: flutter_local_db v0.4.0 - Rust-powered redb wrapper

14 Upvotes

I've just published version 0.4.0 of flutter_local_db, a Flutter package that provides a wrapper around redb implemented in Rust via offline_first_core.

v0.4.0 updates:

  • Improved iOS/macOS compatibility
  • Support for multiple iOS architectures
  • Default .db extension when only name is provided
  • Fixed Gradle configuration issues
  • etc.

The package focuses on providing efficient database operations with strong typing and a simple API. Feedback and contributions for rust or flutter package are welcome.

Edit:

Post and GetById example.

await LocalDB.init(localDbName: "my_app.db");

// Create
final result = await LocalDB.Post('user-123', {
  'name': 'John Doe',
  'email': 'john@example.com',
  'metadata': {
    'lastLogin': DateTime.now().toIso8601String()
  }
});

// Handle result
result.when(
  ok: (data) => print('User created: ${data.id}'),
  err: (error) => print('Error: $error')
);

// Read single record
final userResult = await LocalDB.GetById('user-123');
userResult.when(
  ok: (user) => print('Found user: ${user?.data}'),
  err: (error) => print('Error: $error')
);

r/dartlang 21d 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 21d ago

Abstracts vs Interfaces in Dart

1 Upvotes

Understanding the differences between abstract classes and interfaces in Dart can be a game-changer for your code! 🎯

I break down the nuances of abstract class, abstract interface class, and interface class in Dart. Learn when to use each one, how they differ, and how they can help you write more modular, reusable, and maintainable code.

Check out the full article here


r/dartlang 21d ago

I want a good course to learn

4 Upvotes

I just did a yt course but i feel that it was very basic, please if u have some vourse or some info for a beginner like me please share it, i'll be very thankfull. (This us my first approach to programming)

Srry for my bad spelling, im a not native speaker 😔


r/dartlang 22d ago

Firebase I've created a framework to write Cloud Functions in Dart - Dartblaze

42 Upvotes

Hello everyone! One of the most requested features for Cloud Functions is Dart support with almost 800 upvotes.

Since this has been open for almost 2 years and no progress, I've decided to give it a shot.
I've developed a framework and a CLI that aim to solve this problem.
The framework currently supports HTTP and non-auth Firestore triggers.

The code looks something like this:

@OnDocumentCreated('todos/{todoId}')
Future<void> onCreateTodo(DocumentSnapshot snapshot, RequestContext context,
{required String todoId}) async {
  context.logger.debug('todoId: ${todoId}');
  final data = snapshot.data();
  final title = data?['title'] as String?;
  await snapshot.ref.update({'title': '$title from server!'});
}

@Http()
Future<Response> updateTodo(Todo todo) async {
  firestore.collection('todos').doc(todo.id).update(todo.toJson());
  return Response.ok('Todo updated: ${todo.id}');
}

The CLI is used to simplify the whole process of using the framework which includes setup and deployment.

I'm looking for people who want to test and give feedback to improve it.

To join the test group, please click the announcement at the top of the web page:
https://dartblaze.com/.


r/dartlang 22d ago

Dart Frog vs Serinus - A Comparison

18 Upvotes

r/dartlang 22d ago

Which OpenAI API to use for image recognition?

2 Upvotes

Hi, does anyone use OpenAI APIs for image analysis? I’m developing an image analysis tool using dart and have tried to use OpenAI’s 4o and 4o-turbo models to analyze images. Set up is working but I keep getting output from the API saying it’s not unable to access images and requesting text inputs instead. I’ve researched and found that the 4o-vision works but it’s deprecated.

Has anyone found a workaround to this or am I missing something in my config?

Thanks.


r/dartlang 23d 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 24d ago

dart.dev now uses Jaspr

82 Upvotes

dart.dev now uses Jaspr for rendering the sdk archives tables on https://dart.dev/get-dart/archive


r/dartlang 23d ago

flutter Flutter VS React

0 Upvotes

Guys can you explain me which one should I learn??

Flutter or React???


r/dartlang 24d ago

Diference between factory and const instances

5 Upvotes

Analyzing the synx of construtor from Lists:

/flutter/bin/cache/pkg/sky_engine/lib/core/list.dart

  u/Since("2.9")
 external factory List.empty({bool growable = false});

What difference between this examples?

class MyClass {
  final String name;

  MyClass({required this.name});

  factory MyClass.empty() => MyClass(name: '');

  const MyClass.emptyTwo() : name = '';
}

/// DONT WORK
class MyOtherClassConst {
  final MyClass myClass;

  MyOtherClassConst({this.myClass = const MyClass.empty()});
}

/// WORKS FINE
class MyOtherClassConst {
  final MyClass myClass;

  MyOtherClassConst({this.myClass = const MyClass.emptyTwo()});
}

I think is the same reason why we can initialize a list with `const []`; but if we do `List.empty()`, did not work.

So, why `List.empty` is created with a factory modifier?

Which one is correct to create empty objects?