TGViewer
Channel Public Channel
DART 🎯 FLUTTER

DART 🎯 FLUTTER

@dartside

A community of Dart and Flutter lovers ❤️

Russian chat: @ru_dart
News: @dartside
Jobs: @dartlang_jobs
Contacts: @plugfox https://plugfox.dev
Subscribers
2.78K
Photos
401
Videos
10
Links
3.3K

Showing posts older than #3078 · Back to latest

Older Posts 20 shown
Post #3077 460
Post #3076 419
Post #3070 428
Post #3069 345

Forwarded from Dart: Tips Of The Day

Flutter forms without packages — everything is already in the SDK

Listenable.merge combines any controllers into a single subscription point. One listener — all validation:

final username = TextEditingController();
final agreed = ValueNotifier<bool>(false);
final focus = FocusNode();

final form = Listenable.merge([username, agreed, focus]);
form.addListener(_validate);


In _validate — all rules in one place, cross-field logic included. Results go into two notifiers:

formError.value = 'Username is required';
formValid.value = false;


Wrap only the submit button in ValueListenableBuilder<bool> — nothing else rebuilds.
Dispose in one pass:

[username, agreed, focus]
.whereType<ChangeNotifier>()
.forEach((c) => c.dispose());


Works with TextEditingController, ValueNotifier<T>, FocusNode, AnimationController, and any ChangeNotifier.
No packages, no new mental model.

Full article with a breakdown of all field types and a live DartPad example

#TipOfTheDay #Dart #Flutter #plugfox #form #state #managment
Plague Fox Form State Management Flutter's SDK already has everything you need to manage complex forms — no packages required. Listenable.merge turns any combination of ValueNotifier, TextEditingController, FocusNode, and ChangeNotifier into a single reactive form controller.
  • 🔥 6
Post #3065 402
Post #3062 309

Forwarded from Dart: Tips Of The Day

Safe Resource Cleanup with Closure Chains

Ever had a multi-step async init where step 5 fails and you need to clean up steps 1–4 in reverse order — even if some cleanups throw too? Nested try/catch/finally turns into an unreadable mess fast.

Other languages solved this: Go has defer, C++ has RAII, C# has using. Dart has none of these. But you can build the equivalent in 6 lines:

void Function() dispose = () { dispose = () {}; };

void disposable(void Function() fn) {
final prev = dispose;
dispose = () {
try { fn(); } finally { prev(); }
};
}


Each disposable() call wraps the previous dispose into a closure chain — a linked list of cleanups in LIFO order. try/finally guarantees every cleanup runs even if one throws. The first line is double-dispose protection.

Usage is dead simple:

final db = await openDatabase();
disposable(() => db.close());

final ws = await WebSocket.connect(url);
disposable(() => ws.close());

// If anything fails here — dispose()
// unwinds: ws.close() → db.close()


Works great with a CancellationToken — just cancel.addListener(dispose) before the streaming phase, and user cancel tears down exactly what was initialized.

The async variant looks identical, just add async/await. Extract into a mixin for reuse.

Full article with detailed examples, cancellation pattern, and edge cases

#TipOfTheDay #Dart #Flutter #plugfox #cleanup
Plague Fox Safe Resource Cleanup with Closure Chains Dart has no defer, no RAII, no scope guards. When multi-step async initialization fails midway, you need to unwind only what was set up — in reverse order, crash-safe. Here's a 6-line closure chain pattern that gives you transactional init, safe teardown…
Post #3061 376
Post #3060 388
Post #3059 411
🐙 Trending Repository: fl_chart ⭐7490

FL Chart is a highly customizable Flutter chart library that supports Line
Chart, Bar Chart, Pie Chart, Scatter Chart, Radar Chart and Candlestick Chart.

#dart #flutter #github #repository #trends
GitHub GitHub - imaNNeo/fl_chart: FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart… FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, Radar Chart and Candlestick Chart. - imaNNeo/fl_chart
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →