{"dataset":{"id":"00000000-0000-0000-0000-000000000053","slug":"flutter-best-practices","name":"Flutter best practices","description":"Source-linked guidance on Flutter fundamentals: widgets, layout, state management, async Dart, and testing. Scoped to current Flutter and Dart docs.","visibility":"public","version":1,"documentCount":5,"publisher":"Koskamo editorial","license":"Original summaries; linked sources retain their own terms.","reviewedAt":"2026-10-04T00:00:00.000Z","readOnly":true,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},"total":5,"documents":[{"title":"Testing Flutter apps","sourceUrl":"https://docs.flutter.dev/testing/overview","text":"Automated tests ensure an app performs correctly before publication while retaining velocity. Well-tested apps have many unit and widget tests tracked by code coverage, plus integration tests covering all important use cases. Unit tests verify a unit of logic under varied conditions, mocking external dependencies and avoiding disk I/O or screen rendering. Widget tests verify a widget's UI looks and interacts as expected, in an environment simpler than a full-blown UI system. Integration tests check a complete app or large part. Trade-offs: unit tests offer low confidence and maintenance cost, run quick, and have few dependencies; widget tests rank higher on confidence, cost, and dependencies while staying quick; integration tests rank highest on all three but run slow. Recipes cover Mockito and finders. Scope: Flutter. Reviewed October 4, 2026.","id":"flutter-best-practices:Testing Flutter apps","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"Async Dart with futures and await","sourceUrl":"https://dart.dev/libraries/async/async-await","text":"Enable the discarded_futures and unawaited_futures lints, and use the async and await keywords to interact with asynchronous results, usually provided as a Future or, for multi-part results, a Stream; common asynchronous operations include fetching data over a network, writing to a database, and reading data from a file. Asynchronous operations let your program complete work while waiting for another operation to finish. Calling an asynchronous function without awaiting yields an uncompleted future, a representation of pending work rather than the eventual value, so code prints \"Instance of '_Future<String>'\" instead of the result. Plain Dart functions also need to become asynchronous to accommodate initial asynchrony. Handle errors from an asynchronous call using try-catch expressions in async functions. Scope: Flutter. Reviewed October 4, 2026.","id":"flutter-best-practices:Async Dart with futures and await","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"State management approaches","sourceUrl":"https://docs.flutter.dev/data-and-backend/state-mgmt/ephemeral-vs-app","text":"Ephemeral state, sometimes called UI or local state, is neatly contained in a single widget — the current page in a PageView or the selected tab in a BottomNavigationBar. Other widget tree parts seldom access it, it needs no serialization, and it doesn't change in complex ways, so techniques like ScopedModel or Redux are unnecessary; a StatefulWidget with setState() suffices, as with a bottom navigation bar's _index field. App state, or shared state, is shared across many app parts and kept between user sessions — user preferences, login info, shopping carts. State and setState() can manage all app state, but complex cases warrant researching options. No clear-cut rule distinguishes the types; ephemeral state may need refactoring into app state as features grow. Scope: Flutter. Reviewed October 4, 2026.","id":"flutter-best-practices:State management approaches","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"Layout with rows, columns, and constraints","sourceUrl":"https://docs.flutter.dev/ui/layout","text":"Flutter’s core layout mechanism relies entirely on widgets, including invisible layout models like rows, columns, and grids that arrange, constrain, and align visible elements. Build complex UIs by composing simple widgets, such as placing Text widgets inside Container widgets to add margins, or wrapping Rows in Containers for padding. Customize UIs via properties: use the color property for Icons, Text.style for font, color, and weight, and specific properties for Columns and Rows to control vertical/horizontal alignment and space occupation. Enable debugPaintSizeEnabled to visualize layouts for debugging purposes. Select layout widgets based on desired alignment or constraint characteristics, which are typically passed to contained widgets. For example, use Center to position a widget horizontally and vertically. This composition-based approach ensures that almost everything in the interface, from images to structural containers, functions as a widget. Scope: Flutter. Reviewed October 4, 2026.","id":"flutter-best-practices:Layout with rows, columns, and constraints","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"},{"title":"Widgets: the building blocks of UI","sourceUrl":"https://docs.flutter.dev/ui/widgets-intro","text":"Flutter widgets are built using a modern framework that takes inspiration from React: widgets describe what their view should look like given their current configuration and state, and when state changes the widget rebuilds its description, which the framework diffs against the previous description to determine minimal render tree changes. Flutter's UI layer has two tiers: the style-neutral core widgets library (package:flutter/widgets.dart) from the Flutter SDK, and design system packages material_ui and cupertino_ui on pub.dev. Use the widgets package for custom design systems, design-agnostic packages, or embedded devices where minimal bundle size is critical; material_ui implements Material 3, cupertino_ui Apple's Human Interface Guidelines. Authors commonly subclass StatelessWidget or StatefulWidget and implement build(), describing the widget in terms of lower-level widgets down to RenderObject. Scope: Flutter. Reviewed October 4, 2026.","id":"flutter-best-practices:Widgets: the building blocks of UI","version":1,"createdAt":"2026-10-04T00:00:00.000Z","updatedAt":"2026-10-04T00:00:00.000Z"}]}