Explain Dart code

Paste Dart, Flutter app code included, and Vibe explains where null is allowed, what a constructor does with its arguments and what each type cast checks.

track.dart

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe25 lines selected

Press Explain it for the sample, or paste your own code first.

What this Dart sample shows

null safety
String? artist may be null and the other three fields may not. json['artist'] as String? lets a missing or null artist through, and artist ?? 'unknown artist' fills in for it in the label. Write track.artist.toUpperCase() and the program doesn't compile: Method 'toUpperCase' cannot be called on 'String?' because it is potentially null.
constructors
const Track({required this.id, ...}) takes named arguments and puts each one straight into its field. Leave out a required one and the call doesn't compile, while this.artist can be left out and stays null. factory Track.fromJson is a constructor that runs code first: it reads the map, then calls the main constructor.
collections
jsonDecode returns dynamic, so as List<dynamic> says the body is a list. items.map(...) builds nothing yet: it is a lazy Iterable that makes each Track only when it is read. .toList() makes all of them at once into a List<Track>.

Good to know

  • Run on [{"id":"t1","title":"Night Drive","seconds":215,"artist":"Lumen"},{"id":"t2","title":"Intro","seconds":9}], parseTracks gives two tracks labelled Night Drive by Lumen, 3:35 and Intro by unknown artist, 0:09.
  • seconds ~/ 60 divides and drops the remainder, 3 for 215, and % 60 is the 35 left over. padLeft(2, '0') turns 9 into 09, so the label reads 0:09, not 0:9.
  • A missing seconds becomes 0. A decimal like 95.9 is cut to 95 by toInt(), not rounded, so that track shows as 1:35.
  • Track doesn't define ==, so two tracks parsed from the same JSON are not equal. Two const Track(...) written with the same values are the same object.
  • The file imports only dart:convert, not Flutter, so it was run with the plain Dart SDK, and a Flutter app can use it as it is.

Watch out: as checks the type when the code runs and throws if it's wrong. An API that sends "seconds": "215" as text makes parseTracks throw type 'String' is not a subtype of type 'num?' in type cast, and one track with no id gives type 'Null' is not a subtype of type 'String' in type cast. Either way the whole list fails, not just that track.

Explain Dart code beside your editor

Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).

Install on Mac

curl -fsSL https://unvibe.site/install.sh | bash

Paste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.

Opening the .dmg the first time
  1. Open the .dmg and drag Unvibe to Applications.
  2. Open it once; macOS says it can't verify it. Click Done.
    macOS dialog: Unvibe Not Opened, with Done and Move to Trash
    Real screen, macOS 15
  3. System Settings › Privacy & Security › Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.
    macOS Privacy & Security, Security section: Unvibe was blocked to protect your Mac, with the Open Anyway button
    Real screen, macOS 15

The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open