tgindex
Dart: Tips Of The Day

Dart: Tips Of The Day

Статистика
@dart_tipsанглийский

Author: @plugfox Chats: @en_dart @ru_dart

Последний пост
24 мар.
Последнее чтение
14 авг.
Постов за неделю
0
Всего постов
20
Тип
открытый
Язык
английский
В каталоге с
14 авг.
Подписчики
895
0 за 1 дн.
Сутки
0
0,00%
Неделя
 
Месяц
 
Просмотров на пост
2 312
20 постов
Вовлечённость
258,3%
к подписчикам
Постов в день
0,0
всего 20
Упоминаний
0
каналов
Охват размещения
оценка
1/24сутки в ленте
1/48двое суток
1/72трое суток

Оценка по просмотрам недавних постов: пост набирает почти всё за первые сутки.

Посты

  • 24 мар.1 3852432

    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: form // [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

  • 23 мар.1 3271320

    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

  • 🎯 Tip of the Day: Using Extensions in Dart Extensions in Dart enhance existing types with new methods, making your code cleaner and more readable. Here's a quick look at two useful extensions: let and ifNull. Example 1: Let Extension The let extension wraps an object in a function, allowing you to perform operations and return the result. extension LetX<T extends Object?> on T { R let<R extends Object?>(R Function(T it) callback) => callback(this); } void main() { print(14.let((it) => it * 3)); // Outputs 42 } Example 2: IfNull Extension The ifNull extension provides a default value if the object is null, ensuring safe handling of nullable types. extension IfNullX<T extends Object> on T? { T ifNull(T Function() callback) => this ?? callback(); } void main() { int? value; print(value.ifNull(() => 14) * 3); // Outputs 42 } #TipOfTheDay #Dart #Flutter #extension #let #ifNull #plugfox

  • 🚀 Tip of the Day: To avoid potential errors when handling dialog and bottom sheet navigations in your application, consider the following advice: When displaying a dialog or a bottom sheet, it is shown by default from the ROOT navigator: showDialog(...); showModalBottomSheet(...); However, when calling pop(), it is called from the NEAREST navigator by default: Navigator.of(context).pop(...); Navigator.pop(context, ...); This discrepancy leads to issues where a modal route is added to one navigator and pop is called from another. To ensure consistency and avoid errors, use: Navigator.of(context, rootNavigator: true).pop(...); Alternatively, create a helper function to manage the top modal route effectively: void popDialog(BuildContext context, [Object? result]) { final state = Navigator.maybeOf(context, rootNavigator: true); if (state == null || !state.mounted) return; state.maybePop(result); } void popDialogs(BuildContext context) { final state = Navigator.maybeOf(context, rootNavigator: true); if (state == null || !state.mounted) return; state.popUntil((route) => route is! RawDialogRoute<Object?> && route is! ModalBottomSheetRoute<Object?>); } Following this approach ensures that pop calls are correctly aligned with the appropriate navigator, preventing wrong and unexpected behavior. #TipOfTheDay #Dart #Flutter #navigator #pop #plugfox

  • Tip of the Day: 🚀 To improve performance in your Flutter apps, use the ListView.builder instead of simply using ListView when dealing with long lists. It only creates items that are visible on the screen and recycles them when they scroll out of view, saving memory and reducing lagging! 🌟 ListView.builder( itemCount: itemCount, itemBuilder: (context, index) { return YourListItemWidget(index); }, ); Happy coding! 🔥 #TipOfTheDay #Dart #Flutter #Performance #ListViewBuilder #ChatGPT #n8n

  • Since Flutter 3.7, you can store all your API keys inside a JSON file and pass it to a new --dart-define-from-file flag from the command line. E.g. --dart-define-from-file=keys.json #TipOfTheDay #Dart #Flutter #PlugFox

  • Discover how to leverage Dart isolates for effective concurrency, enabling efficient parallelism in your applications. Learn about creating isolates, handling communication, and implementing a watchdog timer. https://plugfox.dev/mastering-isolates/ #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #isolate

  • Explore the world of singletons in Dart & Flutter with this comprehensive guide. https://plugfox.dev/singleton #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #singleton

  • Explore the power of anonymous functions in Dart to create flexible, expressive, and context-aware code. Learn their use as arguments, closures, value initialization, UI widget building, and conditional execution. Enhance your programming toolkit with these versatile solutions. https://plugfox.dev/harness-the-power-of-anonymous-functions-in-dart/ #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #closure #anonymous #function

  • In Flutter and Dart applications, it is common to encounter scenarios where a class depends on an asynchronous operation. For instance, a client or service may need to fetch data from a network, or a database may need to establish a connection before being utilized. There are various ways to handle these dependencies efficiently. This article will explore five different approaches to managing asynchronous dependencies in your Dart code. https://plugfox.dev/handling-asynchronous-dependencies-tips/ #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox

  • 16 мар. 2023 г.1 430159из dartside

    #dart #flutter #benchmark #note #performance #bytes Performance benchmark of different ways to append data to a list in dart. BytesBuilder vs AddAll vs Spread vs Concatenation https://gist.github.com/PlugFox/9849994d1f229967ef5dc408cb6b7647

  • видео или голосовое, без подписи

  • #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox

  • adb shell "input keyevent 61 \ && input text user@gmail.com \ && input keyevent 61 \ && input text password \ && input keyevent 66" #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox

  • Most developers don't know how to debug WebView and CustomTabs and track network requests, layouts, and errors. But it's very simple 1) Start debugging on your phone or emulator as usual 2) Open in chrome ON YOUR DESKTOP the link chrome://inspect/#devices 3) Find the web view of the SMARTPHONE on this page 4) Click “inspect” 5) Debug with DevTools like a regular website, console, network requests, etc. You can also see what's happening on the screen #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #devtools #webview

  • #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #ci #cd #pipeline #github #gitlab

  • #tipoftheday #debugger #inspect #dart #dartdev #dartlang #flutter #flutterdev #plugfox https://api.dart.dev/dev/2.8.0-dev.7.0/dart-developer/debugger.html https://api.dart.dev/dev/2.8.0-dev.7.0/dart-developer/inspect.html

  • #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #dartpad #share https://dart.dev/tools/dartpad https://github.com/dart-lang/dart-pad/wiki https://dart.dev/resources/dartpad-best-practices https://dart.dev/tutorials/web/low-level-html/connect-dart-html

  • #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #inherited #widget #scope

  • #tipoftheday #dart #dartdev #dartlang #flutter #flutterdev #plugfox #text #richtext

Dart: Tips Of The Day — tgindex