Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 79318f9

Browse files
authored
Merge pull request #26 from flutter-news-app-full-source-code/chore/docs
docs(local-setup): update mobile client and web dashboard environment...
2 parents 9acee94 + 24fb5c6 commit 79318f9

File tree

3 files changed

+112
-34
lines changed

3 files changed

+112
-34
lines changed

‎src/content/docs/mobile-client/local-setup.mdx‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ This guide will walk you through setting up and running the Flutter News App Mob
3131

3232
4. **Configure the Environment**
3333

34-
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.
35-
36-
- Open the file `lib/main.dart`.
37-
- Locate the `appEnvironment` constant.
38-
- Set its value to one of the following:
39-
- `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.
40-
- `AppEnvironment.development`: Connects the app to a locally running instance of the API server (typically at `http://localhost:8080`).
41-
- `AppEnvironment.production`: Connects the app to your live, deployed backend API.
42-
43-
```dart title="lib/main.dart"
44-
// Use `AppEnvironment.demo` to run with in-memory data (no API needed).
45-
// Use `AppEnvironment.development` to connect to a local backend API.
46-
// Use `AppEnvironment.production` to connect to a live backend API.
47-
const appEnvironment = AppEnvironment.demo;
48-
```
34+
The mobile client uses compile-time variables to configure its environment. This allows you to easily switch between mock data, a local API, or a live production API without changing the code.
35+
36+
You can specify the environment by passing a `--dart-define` flag to the `flutter run` command.
37+
38+
- **Demo (Default):** Runs the app with in-memory mock data. No backend API is required, making it perfect for focusing on UI changes and component testing.
39+
```bash
40+
flutter run
41+
```
42+
- **Development:** Connects the app to a locally running instance of the API server.
43+
```bash
44+
flutter run --dart-define=APP_ENVIRONMENT=development
45+
```
46+
- **Production:** Connects the app to your live, deployed backend API. You must also provide the base URL for your API.
47+
```bash
48+
flutter run --dart-define=APP_ENVIRONMENT=production --dart-define=BASE_URL=https://your.api.com
49+
```
50+
51+
<Aside type="tip">
52+
For an even easier workflow, you can configure your editor to run these commands for you. Check out the [Configuring VS Code Launch Environments](/docs/vscode-launch-configurations/) guide.
53+
</Aside>
4954

5055
<Aside>
5156
For the `development` environment, you must have the [API Server running locally](/docs/api-server/local-setup/) first.
@@ -57,12 +62,14 @@ This guide will walk you through setting up and running the Flutter News App Mob
5762

5863
5. **Run the Application**
5964

60-
Start the Flutter development server. Ensure you have a simulator/emulator running or a physical device connected.
65+
Start the application using one of the commands from the previous step. Ensure you have a simulator/emulator running or a physical device connected.
66+
67+
For example, to run in `demo` mode:
6168

6269
```bash
6370
flutter run
6471
```
6572

66-
The application will now be running on your selected device.
73+
The application will now launch on your selected device.
6774

6875
</Steps>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Configuring VS Code Launch Environments
3+
description: A guide to setting up VS Code launch configurations for different app environments.
4+
---
5+
6+
import { Aside } from '@astrojs/starlight/components';
7+
8+
To streamline the development process, you can configure Visual Studio Code to easily run your Flutter application in different environments (`demo`, `development`, or `production`) directly from the "Run and Debug" panel. This avoids the need to manually type the `flutter run` command with the correct `--dart-define` arguments each time.
9+
10+
<Aside type="caution" title="Important Security Note">
11+
The `launch.json` file can contain sensitive information, such as production API URLs or other secrets. To prevent accidentally exposing these values, it is strongly recommended to add `.vscode/launch.json` to your project's `.gitignore` file.
12+
13+
This ensures it remains a local-only configuration and is not committed to your version control system.
14+
</Aside>
15+
16+
17+
### Create a `launch.json` File
18+
19+
1. In your project's root directory, create a folder named `.vscode` if it doesn't already exist.
20+
2. Inside the `.vscode` folder, create a new file named `launch.json`.
21+
3. Copy and paste the following JSON configuration into your `launch.json` file.
22+
23+
```json title=".vscode/launch.json"
24+
{
25+
"version": "0.2.0",
26+
"configurations": [
27+
{
28+
"name": "Demo - Flutter News App",
29+
"request": "launch",
30+
"type": "dart",
31+
"program": "lib/main.dart",
32+
"args": [
33+
"--dart-define=APP_ENVIRONMENT=demo"
34+
]
35+
},
36+
{
37+
"name": "Development - Flutter News App",
38+
"request": "launch",
39+
"type": "dart",
40+
"program": "lib/main.dart",
41+
"args": [
42+
"--dart-define=APP_ENVIRONMENT=development",
43+
"--dart-define=BASE_URL=http://localhost:8080"
44+
]
45+
},
46+
{
47+
"name": "Production - Flutter News App",
48+
"request": "launch",
49+
"type": "dart",
50+
"program": "lib/main.dart",
51+
"args": [
52+
"--dart-define=APP_ENVIRONMENT=production",
53+
"--dart-define=BASE_URL=https://api.your-production-domain.com"
54+
]
55+
}
56+
]
57+
}
58+
```
59+
60+
### How to Use
61+
62+
After saving the file, open the "Run and Debug" panel in VS Code (you can use the shortcut `Ctrl+Shift+D`). You will now see a dropdown menu at the top with the launch configurations: "Demo - Flutter News App", "Development - Flutter News App", and "Production - Flutter News App".
63+
64+
Simply select the environment you want to run and press the green play button (or `F5`) to launch the application with the correct settings.

‎src/content/docs/web-dashboard/local-setup.mdx‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,26 @@ This guide will walk you through setting up and running the Flutter News App Web
3232

3333
4. **Configure the Environment**
3434

35-
The dashboard 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.
36-
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 dashboard 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 dashboard to a locally running instance of the API server (typically at `http://localhost:8080`).
42-
- `AppEnvironment.production`: Connects the dashboard to your live, deployed backend API.
43-
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;
49-
```
35+
The web dashboard uses compile-time variables to configure its environment. This allows you to easily switch between mock data, a local API, or a live production API without changing the code.
36+
37+
You can specify the environment by passing a `--dart-define` flag to the `flutter run` command.
38+
39+
- **Demo (Default):** Runs the dashboard with in-memory mock data. No backend API is required, making it perfect for focusing on UI changes and component testing.
40+
```bash
41+
flutter run -d chrome
42+
```
43+
- **Development:** Connects the dashboard to a locally running instance of the API server.
44+
```bash
45+
flutter run -d chrome --dart-define=APP_ENVIRONMENT=development
46+
```
47+
- **Production:** Connects the dashboard to your live, deployed backend API. You must also provide the base URL for your API.
48+
```bash
49+
flutter run -d chrome --dart-define=APP_ENVIRONMENT=production --dart-define=BASE_URL=https://your.api.com
50+
```
51+
52+
<Aside type="tip">
53+
For an even easier workflow, you can configure your editor to run these commands for you. Check out the [Configuring VS Code Launch Environments](/docs/vscode-launch-configurations/) guide.
54+
</Aside>
5055

5156
<Aside>
5257
For the `development` environment, you must have the [API Server running locally](/docs/api-server/local-setup/) first.
@@ -58,12 +63,14 @@ This guide will walk you through setting up and running the Flutter News App Web
5863

5964
5. **Run the Development Server**
6065

61-
Start the Flutter development server, targeting the Chrome browser:
66+
Start the application using one of the commands from the previous step, targeting the Chrome browser.
67+
68+
For example, to run in `demo` mode:
6269

6370
```bash
6471
flutter run -d chrome
6572
```
6673

67-
The web dashboard will now be running and accessible in your Chrome browser.
74+
The web dashboard will now be running and accessible in your Chrome browser. The `<Aside>` about connecting from a physical device has been removed as it is not relevant for a web-only dashboard.
6875

6976
</Steps>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /