Sub topic 7
Tour of the Generated Flutter Project
This chapter assumes that you know basic programming concepts, can use a terminal, and have a working Flutter SDK. You should also know how to create a project with flutter create and run it with flutter run.
The project at a glance
After running flutter create my_first_app, Flutter creates a directory with source code, tests, dependency metadata, and platform-specific host projects.
The most important application code is under lib/. The remaining folders support testing, dependency management, and running the same Dart application on different platforms.
Application code in `lib`
The generated lib/main.dart contains the program entry point and a small counter application. Dart starts at the top-level main() function. Flutter's runApp() function then places the root widget into the application window.
A widget is an object that describes part of the user interface. The root widget usually creates a MaterialApp or CupertinoApp, which provides navigation, themes, and platform conventions. Its home property identifies the first screen.
As the application grows, split screens and reusable widgets into separate files:
lib/
main.dart
screens/
home_screen.dart
widgets/
counter_display.dartThe directory names are conventions, not requirements. Dart imports files by path, so a file can use code from another file with an import statement.
Dependencies and project metadata
pubspec.yaml is the project manifest. It declares the application name, description, SDK constraints, dependencies, development dependencies, assets, and fonts. flutter pub add http edits this file and resolves the package.
pubspec.lock records the exact versions selected for dependencies. Applications normally commit this file so that different developers and build systems resolve the same versions. Flutter also creates .dart_tool/, which contains local tool state and package resolution data. Do not edit it manually.
dependencies:
flutter:
sdk: flutter
http: ^1.2.0
dev_dependencies:
flutter_test:
sdk: flutterThe version shown is an example constraint. Use flutter pub add when possible because it chooses a compatible current version.
Tests and platform folders
The test/ directory contains Dart tests. A generated widget test pumps the application into a test environment and checks visible behavior. Keep tests close to the feature they verify, even if you later create subdirectories.
The android/, ios/, web/, macos/, linux/, and windows/ directories contain host projects. They provide platform entry points and build configuration while Flutter renders most of the interface from Dart. Edit these folders when you need native permissions, application identifiers, icons, signing, or platform-specific code.
build/ contains generated build output. .gitignore normally excludes it, and deleting it is safe when you need a clean rebuild.
A practical inspection routine
From the project root, inspect the important files before changing code:
- Read
pubspec.yamlto understand dependencies and assets. - Open
lib/main.dartto find the root widget. - Run the tests in
test/to see the expected behavior. - Check the platform folder only when the feature requires native configuration.
Exercise
Which file should you edit to add a Dart package, and which directory should contain a widget test?
Show answer
Edit pubspec.yaml to add the package. Put the widget test in the test/ directory.