|
1 | 1 | ---
|
2 | 2 | title: Local Setup
|
3 |
| -description: Learn how to set up and run the Flutter mobile client on your local machine. |
| 3 | +description: A step-by-step guide to configuring and running the Flutter mobile client locally. |
4 | 4 | ---
|
5 |
| -import { Steps } from '@astrojs/starlight/components'; |
| 5 | +import { Steps, Aside } from '@astrojs/starlight/components'; |
6 | 6 |
|
7 |
| -This guide provides step-by-step instructions to get the Flutter mobile client running on your local machine for development and testing. |
| 7 | +This guide will walk you through setting up and running the Flutter News App Mobile Client on your local machine. |
8 | 8 |
|
9 |
| -## Prerequisites |
| 9 | +<Steps> |
| 10 | +1. **Prerequisites** |
10 | 11 |
|
11 |
| -Before you begin, ensure you have the following installed on your system: |
12 |
| -- **Flutter SDK**: The mobile client is a Flutter application. Please follow the official [Flutter installation guide](https://flutter.dev/docs/get-started/install) for your operating system. |
13 |
| -- **An IDE**: A code editor like [VS Code](https://code.visualstudio.com/) with the Flutter extension or [Android Studio](https://developer.android.com/studio). |
| 12 | + Before you begin, you must have the Flutter SDK installed on your system. To ensure you are using the most up-to-date and accurate installation instructions, we recommend following the official guide directly from the Flutter team. |
14 | 13 |
|
15 |
| -## Understanding the Environments |
| 14 | + - **Flutter SDK:** Please follow the [Official Flutter Installation Guide](https://flutter.dev/docs/get-started/install) for your specific operating system. |
16 | 15 |
|
17 |
| -The application can be run in three different environments, configured in `lib/main.dart`: |
| 16 | +2. **Clone the Repository** |
18 | 17 |
|
19 |
| -- `AppEnvironment.demo`: This is the default environment. It uses an in-memory data store (`DataInMemory`) populated with mock data. This is perfect for quickly running the app and exploring the UI without needing a live backend. The app also wraps itself in the `DevicePreview` package in this mode, allowing you to see how it looks on various devices. |
20 |
| -- `AppEnvironment.development`: This environment is configured to connect to a local instance of the API server. It uses the `DataApi` client to make live HTTP requests. |
21 |
| -- `AppEnvironment.production`: This environment points to your live, deployed API server. |
| 18 | + Open your terminal, navigate to your desired workspace directory, and clone the mobile client repository: |
22 | 19 |
|
23 |
| -You can change the active environment by modifying the `appEnvironment` constant in `lib/main.dart`: |
| 20 | + ```bash |
| 21 | + git clone https://github.com/flutter-news-app-full-source-code/flutter-news-app-mobile-client-full-source-code.git |
| 22 | + cd apps/flutter-news-app-mobile-client-full-source-code |
| 23 | + ``` |
24 | 24 |
|
25 |
| -```dart title="lib/main.dart" |
26 |
| -// Define the current application environment (production/development/demo). |
27 |
| -const appEnvironment = AppEnvironment.demo; |
28 |
| -``` |
| 25 | +3. **Install Dependencies** |
29 | 26 |
|
30 |
| -## Dependency Injection |
| 27 | + Fetch all the required Dart and Flutter packages for the project: |
31 | 28 |
|
32 |
| -The application's dependencies, such as repositories and data clients, are initialized in the `bootstrap.dart` file. This function reads the selected `AppEnvironment` and injects the appropriate data clients. |
| 29 | + ```bash |
| 30 | + flutter pub get |
| 31 | + ``` |
33 | 32 |
|
34 |
| -For example, in `demo` mode, it injects `AuthInmemory` and `DataInMemory` clients. In `development` or `production` mode, it sets up an `HttpClient` and injects `AuthApi` and `DataApi` clients to communicate with the backend. This clean separation makes the app highly testable and configurable. |
| 33 | +4. **Configure the Environment** |
35 | 34 |
|
36 |
| -## Running the Application |
| 35 | + The mobile client can be run in different environments, allowing you to connect it to a live API, a local API, or run it with mock data for UI development. |
37 | 36 |
|
38 |
| -<Steps> |
39 |
| -1. **Navigate to the Project Directory** |
| 37 | + - Open the file `lib/main.dart`. |
| 38 | + - Locate the `appEnvironment` constant. |
| 39 | + - Set its value to one of the following: |
| 40 | + - `AppEnvironment.demo`: **(Recommended for UI development)** Runs the app with in-memory mock data. No backend API is required, making it perfect for focusing on UI changes and component testing. |
| 41 | + - `AppEnvironment.development`: Connects the app to a locally running instance of the API server (typically at `http://localhost:8080`). |
| 42 | + - `AppEnvironment.production`: Connects the app to your live, deployed backend API. |
40 | 43 |
|
41 |
| - Open your terminal and navigate to the mobile client's root directory: |
42 |
| - ```sh |
43 |
| - cd apps/flutter-news-app-mobile-client-full-source-code |
| 44 | + ```dart title="lib/main.dart" |
| 45 | + // Use `AppEnvironment.demo` to run with in-memory data (no API needed). |
| 46 | + // Use `AppEnvironment.development` to connect to a local backend API. |
| 47 | + // Use `AppEnvironment.production` to connect to a live backend API. |
| 48 | + const appEnvironment = AppEnvironment.demo; |
44 | 49 | ```
|
45 | 50 |
|
46 |
| -2. **Get Dependencies** |
| 51 | + <Aside> |
| 52 | + For the `development` environment, you must have the [API Server running locally](/docs/api-server/local-setup/) first. |
| 53 | + </Aside> |
47 | 54 |
|
48 |
| - Run the following command to fetch all the required packages from `pubspec.yaml`: |
49 |
| - ```sh |
50 |
| - flutter pub get |
51 |
| - ``` |
| 55 | +5. **Run the Application** |
52 | 56 |
|
53 |
| -3. **Select a Device** |
| 57 | + Start the Flutter development server. Ensure you have a simulator/emulator running or a physical device connected. |
54 | 58 |
|
55 |
| - Ensure you have a simulator running (iOS) or an emulator running (Android), or a physical device connected. You can see a list of available devices with: |
56 |
| - ```sh |
57 |
| - flutter devices |
| 59 | + ```bash |
| 60 | + flutter run |
58 | 61 | ```
|
59 | 62 |
|
60 |
| -4. **Run the App** |
| 63 | + The application will now be running on your selected device. |
61 | 64 |
|
62 |
| - Start the application using the `flutter run` command. By default, this will launch the app in `demo` mode. |
63 |
| - ```sh |
64 |
| - flutter run |
65 |
| - ``` |
66 | 65 | </Steps>
|
67 |
| - |
68 |
| -The application should now be running on your selected device. Because it's in `demo` mode, you can immediately start exploring the UI and features with the pre-loaded mock data. |
0 commit comments