1
0
mirror of https://github.com/flutter/samples.git synced 2026-06-25 07:38:26 +00:00
Files
samples/compass_app
Mozammal Hossain 5f4c795695 [compass_app] Scope LogoutViewModel to route builder — fix #2604 (#2819)
## Description

**Problem:** `LogoutViewModel` was built inside `HomeHeader.build()`, so
each rebuild could create a new instance and a new `logout` command.
That does not match how other Compass view models are scoped (created in
the GoRouter route `builder` and passed in), and it can affect an
in-flight logout when the home screen rebuilds.

**Change:** Create `LogoutViewModel` once in the `/home` route next to
`HomeViewModel`, pass it through `HomeScreen` → `HomeHeader` →
`LogoutButton`, and remove inline construction in `home_title.dart`.
Update `home_screen_test.dart` to build `LogoutViewModel` with fakes and
remove `Provider` wrappers that only supported `context.read()` in the
header.

**Result:** Logout view model lifetime aligns with the home route; no
visual or copy changes (screenshots not needed).

Fixes https://github.com/flutter/samples/issues/2604

---

## Pre-launch Checklist

- [x] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [x] I signed the [CLA].
- [x] I read the [Contributors Guide].
- [x] I have added sample code updates to the [changelog].
- [x] I updated/added relevant documentation (doc comments with `///`).

If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md
[CLA]: https://cla.developers.google.com/
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
[changelog]: ../CHANGELOG.md

---------

Co-authored-by: Eric Windmill <eric@ericwindmill.com>
2026-06-19 14:11:27 -07:00
..
2024-09-28 08:49:27 +10:00
2024-09-28 08:49:27 +10:00

compass_app

The Compass sample application is an app that helps users build and book itineraries for trips. Its a robust sample application with many features, routes, and screens. The app communicates with an HTTP server, has development and production environments, brand-specific styling, and high test coverage. In these ways and more, it simulates a real-world, feature rich Flutter application.

The code in this application is used for explaining architecture in a Flutter application.

compass app splash screen compass app activities screen compass app home screen compass app booking screen

The Compass app was originally designed and built by the Firebase GenKit team.

Running the app

This app contains multiple environments.

  • Development environment - This environment uses data from a JSON file, which is stored in the assets directory, and simulates developing locally.
$ cd app
$ flutter run --target lib/main_development.dart
  • Staging environment - This environment uses an HTTP server to get data, simulating a real app experience. This is a "dummy" server, that has endpoints that simply return fake data. The server can be found in the compass_app/server directory. You need to run the server locally before running the Flutter application.
$ cd server
$ dart run
# => Server listening on port 8080
 
$ cd ../compass_app/app
$ flutter run --target lib/main_staging.dart 

Integration Tests

Integration tests must be run from the app directory.

Integration tests with local data

cd app
$ flutter test integration_test/app_local_data_test.dart

Integration tests with background server and remote data

cd app
$ flutter test integration_test/app_server_data_test.dart

Running the tests together with flutter test integration_test will fail. See: https://github.com/flutter/flutter/issues/101031