Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

8668 bites

Page 167

Flutter & Dart2 min read

How do you safely add a non-nullable column in sqflite?

Tests onCreate for fresh installs vs onUpgrade for existing data. Outline: bump version; in onUpgrade use ALTER TABLE ADD COLUMN NOT NULL DEFAULT for existing rows; keep onCreate as latest schema. Red flag: only changing onCreate so old users crash.

Flutter & Dart2 min read

What is an sqflite transaction? Provide a practical example.

Tests atomicity in SQLite and isolate safety. A strong answer defines all-or-nothing execution, gives a fund-transfer example updating both, and warns sqflite transactions are not cross-isolate safe. Red flag: omitting rollback or multi-isolate writes.

Flutter & Dart2 min read

Key difference between shared_preferences and flutter_secure_storage for tokens

Tests at-rest encryption: shared_preferences stores plain text XML/plist, while secure storage uses iOS Keychain and Keystore with RSA OAEP plus AES-GCM. Answers cite backup risks and hardware keys. Red flag: calling prefs safe or relying on obfuscation.

Flutter & Dart2 min read

Why is Flutter local storage async and how do you use shared_preferences?

Tests why disk I/O must avoid blocking Dart's UI thread. A strong answer shows async/await with getInstance and setters, notes legacy getters are sync-after-cache, and warns writes may not persist instantly.

Flutter & Dart2 min read

When to use SQLite over key-value storage?

Tests structured-vs-flat storage judgment. Good answers cite relational data, complex queries, or multi-table schemas, then list adding the dependency, getting a path, opening with onCreate, and keeping a singleton.

Flutter & Dart2 min read

Why are stale search requests problematic and how do you cancel them?

This tests race conditions and resource waste in async UI. Strong answers note stale requests waste bandwidth and overwrite newer results; cancel the previous call with a CancelToken before issuing the next.

Implement an API caching layer with offline support and storage trade-offs
Flutter & Dart2 min read

Implement an API caching layer with offline support and storage trade-offs

Use in-memory for hot data and disk for offline, pick Hive or SQLite by shape, and use TTL with a sync queue.

Flutter & Dart2 min read

Explain Dio interceptors and automatic token refresh

Define interceptors as hooks; queue concurrent 401s during refresh; retry with Bearer header via token manager.

Flutter & Dart2 min read

How would you manage network request state in a Flutter widget?

This tests whether you separate ephemeral widget state from business logic. A good answer defines a state class, uses setState in initState, then shows how a library moves logic out for testing and reuse. Red flag: fetch inside build or using boolean flags.

Flutter & Dart2 min read

Compare manual JSON serialization versus json_serializable

It tests build automation versus manual control in Dart serialization. Manual methods avoid build steps but risk drift; code generation cuts boilerplate but adds compile latency. Claiming code gen slows runtime or that manual is always simpler.

Flutter & Dart2 min read

Describe a robust error handling strategy for network requests

Tests whether you classify failures by layer rather than catching everything generically. Inspect DioExceptionType for connectivity, check HTTP status before parsing, and isolate JSON decode errors. Never show the same message for timeouts and 500s.

Flutter & Dart2 min read

Purpose of factory fromJson constructor in Dart models

Factory fromJson centralizes deserialization, preprocesses Map values before instantiation, and keeps the primary constructor clean.

Flutter & Dart2 min read

Explain FutureBuilder and how it manages async UI states

This tests declarative async UI state management. Obtain the Future before build, pass it to FutureBuilder, and branch on snapshot.connectionState and hasError to render loading, data, or error states.

Flutter & Dart2 min read

Make a GET request with http and parse JSON in Dart

Practical Dart async networking with package:http and dart:convert. Import http, await get(Uri.parse(url)), verify statusCode is 200, then jsonDecode(response.body) as List<Map<String, dynamic>>. Skipping status checks or decoding without a cast.

Flutter & Dart2 min read

Explain lifting state up in Flutter and how Provider simplifies it

Tests declarative state ownership and prop-drilling cost. A strong answer names the lowest common ancestor, contrasts callback threading with Provider lookup, and avoids root-level state.

Flutter & Dart2 min read

How do you manage product list and favorite state without full rebuilds?

This tests granular rebuild control in Flutter lists. A strong answer isolates item state with ValueNotifier or ChangeNotifier per item plus const constructors with keys. Red flag: calling setState on the parent list rebuilds every ListTile on each tap.

Flutter & Dart2 min read

Difference between context.watch, context.read, and Selector in Provider and Riverpod

Tests rebuild granularity in Flutter. A strong answer distinguishes listening versus one-time lookup, explains that Selector filters rebuilds by comparing sub-values, and warns that context.read inside build causes missed updates.

Flutter & Dart2 min read

Explain ephemeral vs app state and when to use setState

This tests state scoping judgment. Ephemeral state is local to one widget, like a page index or checkbox value, and setState fits perfectly. App state is shared, like a user profile or cart, and needs a state management solution.

Flutter & Dart2 min read

Custom fade-and-scale transition with PageRouteBuilder and GoRoute

Tests bridging imperative transitions to declarative routers. Use PageRouteBuilder with FadeTransition and ScaleTransition, set globally in theme or per route via GoRoute pageBuilder with CustomTransitionPage. Red flag: omitting child rebuilds the page.

Flutter & Dart2 min read

Implement a GoRouter path parameter route and access userId in a widget

This tests GoRouter declarative routing and GoRouterState. Define a GoRoute with path '/users/:userId', read state.params['userId'] in the builder, and handle null-safety. A red flag is parsing the URI manually or using ModalRoute.of instead of state.params.