Mobile Development 24 min read

Flutter Project Setup Guide: Networking, Persistence, Routing, Screen Adaptation, Splash Screen, State Management, and Widget Lifecycle

This article provides a comprehensive step‑by‑step guide for setting up a new Flutter project, covering network request handling with Dio and protobuf, data persistence using shared_preferences, mmkv and ObjectBox, routing with GoRouter, screen adaptation via flutter_screenutil, splash‑screen configuration, state‑management techniques with Provider and GetX, and detailed explanations of widget lifecycle and key usage.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
Flutter Project Setup Guide: Networking, Persistence, Routing, Screen Adaptation, Splash Screen, State Management, and Widget Lifecycle

The author, after a year away from Flutter, shares practical experience for quickly bootstrapping a new Flutter project, emphasizing the maturity of the ecosystem and how many common pain points have been solved.

1. Network Request Handling – Discusses entity class encapsulation, introduces protobuf as a zero‑code‑generation binary protocol, and compares it with JSON. Shows how to generate Dart models with @JsonSerializable() and run flutter pub run build_runner build to create serialization functions. Explains generic request wrappers, the limitation of Dart generics at runtime, and the workaround using function references. Details the use of the dio library, required interceptor configuration, and cache strategies (e.g., CacheMode.refreshForceCache and CacheMode.noCache ), including code snippets for request/response wrapping.

2. Data Persistence – Covers three storage types: file I/O (handled by the framework), key‑value storage with shared_preferences (highlighting its async‑only API and single‑file limitation), and the alternative mmkv plugin which offers synchronous writes, configurable file locations, and AES encryption. Also compares SQLite ( sqflite ) with the lightweight ObjectBox, presenting performance charts and recommending ObjectBox for small‑to‑medium projects.

3. Routing – Reviews Navigator 1.0 vs. Navigator 2.0, noting the complexity of the latter, and introduces the go_router package that abstracts route information providers and parsers for easier navigation.

4. Multi‑Device Screen Adaptation – Introduces flutter_screenutil for separating width and height units, using .w , .h , .sp , and .r extensions, and shows how to initialize it with the design draft dimensions.

5. Splash Screen Configuration – Recommends the flutter_native_splash package, describing the two‑step setup in pubspec.yaml and runtime removal after initialization.

6. State Management – Explains the purpose of state management, then dives into Provider (built on InheritedWidget ) and GetX. For Provider, the summary outlines how data is stored in InheritedElement , how Consumer rebuilds only dependent widgets, and the limitations of InheritedWidget . For GetX, it describes the singleton GetInstance , controller lifecycle, GetBuilder refresh mechanisms (including filter and id based updates), and automatic controller disposal.

7. Widget Lifecycle and Key Usage – Clarifies the distinction between StatelessWidget and StatefulWidget lifecycles, the role of Element , and how Key influences element reuse. Details local keys ( ValueKey , ObjectKey , UniqueKey ) versus global keys, and provides concrete examples showing how missing keys can cause state mismatches, while proper key usage enables efficient element recycling across navigation and dynamic widget trees.

In conclusion, the author stresses leveraging existing packages to avoid reinventing the wheel and mastering widget lifecycle and key concepts to build robust, performant Flutter applications.

Fluttermobile developmentstate-managementroutingNetworkingData Persistence
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.