├── .gitignore
├── .metadata
├── .vscode
├── launch.json
└── settings.json
├── README.md
├── analysis_options.yaml
├── android
├── .gitignore
├── app
│ ├── build.gradle
│ └── src
│ │ ├── debug
│ │ └── AndroidManifest.xml
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── kotlin
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── hello_world
│ │ │ │ └── MainActivity.kt
│ │ └── res
│ │ │ ├── drawable-v21
│ │ │ └── launch_background.xml
│ │ │ ├── drawable
│ │ │ └── launch_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-night
│ │ │ └── styles.xml
│ │ │ └── values
│ │ │ └── styles.xml
│ │ └── profile
│ │ └── AndroidManifest.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
└── settings.gradle
├── ios
├── .gitignore
├── Flutter
│ ├── AppFrameworkInfo.plist
│ ├── Debug.xcconfig
│ └── Release.xcconfig
├── Runner.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ └── WorkspaceSettings.xcsettings
│ └── xcshareddata
│ │ └── xcschemes
│ │ └── Runner.xcscheme
├── Runner.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ ├── IDEWorkspaceChecks.plist
│ │ └── WorkspaceSettings.xcsettings
└── Runner
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── Icon-App-1024x1024@1x.png
│ │ ├── Icon-App-20x20@1x.png
│ │ ├── Icon-App-20x20@2x.png
│ │ ├── Icon-App-20x20@3x.png
│ │ ├── Icon-App-29x29@1x.png
│ │ ├── Icon-App-29x29@2x.png
│ │ ├── Icon-App-29x29@3x.png
│ │ ├── Icon-App-40x40@1x.png
│ │ ├── Icon-App-40x40@2x.png
│ │ ├── Icon-App-40x40@3x.png
│ │ ├── Icon-App-60x60@2x.png
│ │ ├── Icon-App-60x60@3x.png
│ │ ├── Icon-App-76x76@1x.png
│ │ ├── Icon-App-76x76@2x.png
│ │ └── Icon-App-83.5x83.5@2x.png
│ └── LaunchImage.imageset
│ │ ├── Contents.json
│ │ ├── LaunchImage.png
│ │ ├── LaunchImage@2x.png
│ │ ├── LaunchImage@3x.png
│ │ └── README.md
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ └── Runner-Bridging-Header.h
├── lib
├── Chapter01
│ └── main.dart
├── Chapter02
│ ├── anonymous.dart
│ ├── happy_birthday_example.dart
│ ├── hello_example.dart
│ ├── main.dart
│ ├── records.dart
│ └── scope.dart
├── Chapter04
│ ├── abstract.dart
│ ├── enum.dart
│ ├── futures.dart
│ ├── generics.dart
│ ├── isolate.dart
│ ├── mixin.dart
│ ├── person_version1.dart
│ ├── person_version2.dart
│ └── person_version3.dart
├── Chapter05
│ ├── destination_widget.dart
│ ├── main_column.dart
│ ├── main_column_too_long.dart
│ └── main_list_view.dart
├── Chapter06
│ ├── destination_like.dart
│ ├── destination_widget.dart
│ ├── main.dart
│ └── main_form.dart
├── Chapter07
│ ├── destination_list_tile.dart
│ ├── destination_widget_container.dart
│ ├── destination_widget_textstyle.dart
│ ├── main.dart
│ └── sliver_page.dart
├── Chapter08
│ ├── main.dart
│ ├── main_named.dart
│ ├── main_named_arguments.dart
│ ├── main_navigator2.dart
│ ├── main_result.dart
│ ├── main_transition.dart
│ └── main_transition_class.dart
├── Chapter09
│ ├── destination_description.dart
│ └── main.dart
├── Chapter11
│ ├── animated_builder.dart
│ ├── composed_button.dart
│ ├── main.dart
│ ├── rotated_button.dart
│ ├── rotation_bouncein_button.dart
│ ├── rotation_button.dart
│ ├── scale_button.dart
│ ├── scaled_button.dart
│ └── translated_button.dart
└── Chapter12
│ ├── calculator.dart
│ └── calculator_fail.dart
├── linux
├── .gitignore
├── CMakeLists.txt
├── flutter
│ ├── CMakeLists.txt
│ ├── generated_plugin_registrant.cc
│ ├── generated_plugin_registrant.h
│ └── generated_plugins.cmake
├── main.cc
├── my_application.cc
└── my_application.h
├── macos
├── .gitignore
├── Flutter
│ ├── Flutter-Debug.xcconfig
│ ├── Flutter-Release.xcconfig
│ └── GeneratedPluginRegistrant.swift
├── Runner.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata
│ │ └── xcschemes
│ │ └── Runner.xcscheme
├── Runner.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── Runner
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── app_icon_1024.png
│ │ ├── app_icon_128.png
│ │ ├── app_icon_16.png
│ │ ├── app_icon_256.png
│ │ ├── app_icon_32.png
│ │ ├── app_icon_512.png
│ │ └── app_icon_64.png
│ ├── Base.lproj
│ └── MainMenu.xib
│ ├── Configs
│ ├── AppInfo.xcconfig
│ ├── Debug.xcconfig
│ ├── Release.xcconfig
│ └── Warnings.xcconfig
│ ├── DebugProfile.entitlements
│ ├── Info.plist
│ ├── MainFlutterWindow.swift
│ └── Release.entitlements
├── pubspec.lock
├── pubspec.yaml
├── test
├── calculator_fail_test.dart
├── calculator_test.dart
└── widget_test.dart
├── web
├── favicon.png
├── icons
│ ├── Icon-192.png
│ ├── Icon-512.png
│ ├── Icon-maskable-192.png
│ └── Icon-maskable-512.png
├── index.html
└── manifest.json
└── windows
├── .gitignore
├── CMakeLists.txt
├── flutter
├── CMakeLists.txt
├── generated_plugin_registrant.cc
├── generated_plugin_registrant.h
└── generated_plugins.cmake
└── runner
├── CMakeLists.txt
├── Runner.rc
├── flutter_window.cpp
├── flutter_window.h
├── main.cpp
├── resource.h
├── resources
└── app_icon.ico
├── runner.exe.manifest
├── utils.cpp
├── utils.h
├── win32_window.cpp
└── win32_window.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | **/doc/api/
26 | **/ios/Flutter/.last_build_id
27 | .dart_tool/
28 | .flutter-plugins
29 | .flutter-plugins-dependencies
30 | .packages
31 | .pub-cache/
32 | .pub/
33 | /build/
34 |
35 | # Symbolication related
36 | app.*.symbols
37 |
38 | # Obfuscation related
39 | app.*.map.json
40 |
41 | # Android Studio will place build artifacts here
42 | /android/app/debug
43 | /android/app/profile
44 | /android/app/release
45 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled.
5 |
6 | version:
7 | revision: 135454af32477f815a7525073027a3ff9eff1bfd
8 | channel: stable
9 |
10 | project_type: app
11 |
12 | # Tracks metadata for the flutter migrate command
13 | migration:
14 | platforms:
15 | - platform: root
16 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
17 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
18 | - platform: android
19 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
20 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
21 | - platform: ios
22 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
23 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
24 | - platform: linux
25 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
26 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
27 | - platform: macos
28 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
29 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
30 | - platform: web
31 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
32 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
33 | - platform: windows
34 | create_revision: 135454af32477f815a7525073027a3ff9eff1bfd
35 | base_revision: 135454af32477f815a7525073027a3ff9eff1bfd
36 |
37 | # User provided section
38 |
39 | # List of Local paths (relative to this file) that should be
40 | # ignored by the migrate tool.
41 | #
42 | # Files that are not part of the templates will be ignored by default.
43 | unmanaged_files:
44 | - 'lib/main.dart'
45 | - 'ios/Runner.xcodeproj/project.pbxproj'
46 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "Chapter 01",
9 | "request": "launch",
10 | "type": "dart",
11 | "program": "lib/Chapter01/main.dart"
12 | },
13 | {
14 | "name": "Chapter 01 (profile mode example)",
15 | "request": "launch",
16 | "type": "dart",
17 | "flutterMode": "profile",
18 | "program": "lib/Chapter01/main.dart"
19 | },
20 | {
21 | "name": "Chapter 01 (release mode example)",
22 | "request": "launch",
23 | "type": "dart",
24 | "flutterMode": "release"
25 | },
26 | {
27 | "name": "Chapter 05 - main_column",
28 | "request": "launch",
29 | "type": "dart",
30 | "program": "lib/Chapter05/main_column.dart"
31 | },
32 | {
33 | "name": "Chapter 05 - main_column_too_long",
34 | "request": "launch",
35 | "type": "dart",
36 | "program": "lib/Chapter05/main_column_too_long.dart"
37 | },
38 | {
39 | "name": "Chapter 05 - main_list_view",
40 | "request": "launch",
41 | "type": "dart",
42 | "program": "lib/Chapter05/main_list_view.dart"
43 | },
44 | {
45 | "name": "Chapter 06 - main",
46 | "request": "launch",
47 | "type": "dart",
48 | "program": "lib/Chapter06/main.dart"
49 | },
50 | {
51 | "name": "Chapter 06 - main_form",
52 | "request": "launch",
53 | "type": "dart",
54 | "program": "lib/Chapter06/main_form.dart"
55 | },
56 | {
57 | "name": "Chapter 07 - main",
58 | "request": "launch",
59 | "type": "dart",
60 | "program": "lib/Chapter07/main.dart"
61 | },
62 | {
63 | "name": "Chapter 08 - main",
64 | "request": "launch",
65 | "type": "dart",
66 | "program": "lib/Chapter08/main.dart"
67 | },
68 | {
69 | "name": "Chapter 08 - main_named",
70 | "request": "launch",
71 | "type": "dart",
72 | "program": "lib/Chapter08/main_named.dart"
73 | },
74 | {
75 | "name": "Chapter 08 - main_named_arguments",
76 | "request": "launch",
77 | "type": "dart",
78 | "program": "lib/Chapter08/main_named_arguments.dart"
79 | },
80 | {
81 | "name": "Chapter 08 - main_result",
82 | "request": "launch",
83 | "type": "dart",
84 | "program": "lib/Chapter08/main_result.dart"
85 | },
86 | {
87 | "name": "Chapter 08 - main_navigator2",
88 | "request": "launch",
89 | "type": "dart",
90 | "program": "lib/Chapter08/main_navigator2.dart"
91 | },
92 | {
93 | "name": "Chapter 08 - main_transition",
94 | "request": "launch",
95 | "type": "dart",
96 | "program": "lib/Chapter08/main_transition.dart"
97 | },
98 | {
99 | "name": "Chapter 08 - main_transition_class",
100 | "request": "launch",
101 | "type": "dart",
102 | "program": "lib/Chapter08/main_transition_class.dart"
103 | },
104 | {
105 | "name": "Chapter 09 - main",
106 | "request": "launch",
107 | "type": "dart",
108 | "program": "lib/Chapter09/main.dart"
109 | },
110 | {
111 | "name": "Chapter 11 - main",
112 | "request": "launch",
113 | "type": "dart",
114 | "program": "lib/Chapter11/main.dart"
115 | }
116 | ]
117 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.configureOnOpen": false
3 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Flutter for Beginners - Third Edition
2 |
3 |
4 |
5 | This is the code repository for [Flutter for Beginners - Third Edition](https://www.packtpub.com/product/flutter-for-beginners-third-edition/9781837630387), published by Packt.
6 |
7 | **Cross-platform mobile development from Hello, World! to app release with Flutter 3.10+ and Dart 3.x**
8 |
9 | ## What is this book about?
10 | There have been many attempts at creating frameworks that are truly cross-platform, but most struggle to create a native-like experience at high performance levels. Flutter achieves this with an elegant design and a wealth of third-party plugins, making it the future of mobile app development. If you are a mobile developer who wants to create rich and expressive native apps with the latest Google Flutter framework, this book is for you.
11 |
12 | This book covers the following exciting features:
13 | * Understand the Flutter framework and cross-platform development
14 | * Acclimate the fundamentals of the Dart programming language
15 | * Explore Flutter widgets, the core widget library, and stateful and stateless widgets
16 | * Discover the complete development lifecycle, including testing and debugging
17 | * Get familiar with both the mobile and web app release processes
18 | * Dig deeper into more advanced Flutter concepts like animation
19 | * Explore common Flutter plugins ad how to use them
20 | * Discover the Flutter community and how to stay up-to-date
21 |
22 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1837630380) today!
23 |
24 |
26 |
27 |
28 | ## Instructions and Navigations
29 | All of the code is organized into sub-folders within either the lib or test top-level folders. For example, Chapter01.
30 |
31 | The code will look like the following:
32 | ```
33 | void main() {
34 | for (int i = 0; i < 5; i++) {
35 | print('hello ${i + 1}');
36 | }
37 | }
38 |
39 | ```
40 |
41 | ## Running the code
42 | To run the code you will need to specify which chapter you wish to run, and which main method to run within the chapter, because the code is split by chapter and, in some chapters, there are multiple files with main methods within them.
43 | Use the following command with the correct chapter number and main file name:
44 | flutter run -t lib/Chapter01/main.dart
45 |
46 | **Following is what you need for this book:**
47 |
48 | This book is for developers looking to learn Google's revolutionary framework Flutter from scratch. No prior knowledge of Flutter or Dart is required.
49 |
50 | With the following software and hardware list you can run all code files present in the book (Chapter 1-13).
51 |
52 | ### Software and Hardware List
53 |
54 | | Chapter | Software required | OS required |
55 | | -------- | ----------------------------------------------| -----------------------------------|
56 | | 1-13 | IDE - Visual Studio Code or Android Studio | Windows, Mac OS X, and Linux (Any) |
57 | | 1-13 | SDK - Flutter | Windows, Mac OS X, and Linux (Any) |
58 |
59 | ## Errata
60 |
61 | * Page 153 (Paragraph 3, under GenstureDetector line 1): **stateless widget** _should be_ **StatefulWidget**
62 |
63 | ### Related products
64 | * Flutter Projects [[Packt]](https://www.packtpub.com/product/flutter-projects/9781838647773?utm_source=github&utm_medium=repository&utm_campaign=9781838647773) [[Amazon]](https://www.amazon.com/dp/1838647775)
65 |
66 | * Flutter Cookbook [[Packt]](https://www.packtpub.com/product/flutter-cookbook/9781838823382?utm_source=github&utm_medium=repository&utm_campaign=9781838823382) [[Amazon]](https://www.amazon.com/dp/1838823387)
67 |
68 | ## Get to Know the Authors
69 | **Thomas Bailey**
70 | has an extensive background in tech, working for companies and high-profile firms as a senior developer, solutions architect, and IT director. His education technology company uses Flutter as the sole technology powering their education apps, and he has enjoyed watching Flutter move from its initial beta release to the fully fledged and highly popular framework we see today. He loves to talk tech over a hot chocolate with anyone who will listen and is constantly exploring the cutting edge of tech and how it will shape our industry in the future.
71 |
72 | **Alessandro Biessek**
73 | was born in the beautiful city of Chapecó, in the state of Santa Catarina, southern Brazil, in 1993. He is currently working on mobile application development for Android and iOS in his hometown. He has more than 9 years of experience in development, from desktop development with Delphi to backend with PHP, Node.js, Golang, mobile development with Apache Flex, and Java/Kotlin. Most of his time is devoted to the development of Android apps. Always interested in new technologies, he has been following the Flutter framework for a long time, shown through its growth and adoption in recent months.
74 |
75 | ## Other books by the author
76 | * [Flutter for Beginners - First Edition](https://www.packtpub.com/product/flutter-for-beginners/9781788996082)
77 | * [Flutter for Beginners - Second Edition](https://www.packtpub.com/product/flutter-for-beginners-second-edition/9781800565999?utm_source=github&utm_medium=repository&utm_campaign=9781800565999)
78 |
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | # This file configures the analyzer, which statically analyzes Dart code to
2 | # check for errors, warnings, and lints.
3 | #
4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6 | # invoked from the command line by running `flutter analyze`.
7 |
8 | # The following line activates a set of recommended lints for Flutter apps,
9 | # packages, and plugins designed to encourage good coding practices.
10 | include: package:flutter_lints/flutter.yaml
11 |
12 | linter:
13 | # The lint rules applied to this project can be customized in the
14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15 | # included above or to enable additional rules. A list of all available lints
16 | # and their documentation is published at
17 | # https://dart-lang.github.io/linter/lints/index.html.
18 | #
19 | # Instead of disabling a lint rule for the entire project in the
20 | # section below, it can also be suppressed for a single line of code
21 | # or a specific dart file by using the `// ignore: name_of_lint` and
22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file
23 | # producing the lint.
24 | rules:
25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule
26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27 |
28 | # Additional information about this file can be found at
29 | # https://dart.dev/guides/language/analysis-options
30 |
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 | **/*.keystore
13 | **/*.jks
14 |
--------------------------------------------------------------------------------
/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | compileSdkVersion flutter.compileSdkVersion
30 | ndkVersion flutter.ndkVersion
31 |
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_1_8
34 | targetCompatibility JavaVersion.VERSION_1_8
35 | }
36 |
37 | kotlinOptions {
38 | jvmTarget = '1.8'
39 | }
40 |
41 | sourceSets {
42 | main.java.srcDirs += 'src/main/kotlin'
43 | }
44 |
45 | defaultConfig {
46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
47 | applicationId "com.example.hello_world"
48 | // You can update the following values to match your application needs.
49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
50 | minSdkVersion flutter.minSdkVersion
51 | targetSdkVersion flutter.targetSdkVersion
52 | versionCode flutterVersionCode.toInteger()
53 | versionName flutterVersionName
54 | }
55 |
56 | buildTypes {
57 | release {
58 | // TODO: Add your own signing config for the release build.
59 | // Signing with the debug keys for now, so `flutter run --release` works.
60 | signingConfig signingConfigs.debug
61 | }
62 | }
63 | }
64 |
65 | flutter {
66 | source '../..'
67 | }
68 |
69 | dependencies {
70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
71 | }
72 |
--------------------------------------------------------------------------------
/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
15 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/android/app/src/main/kotlin/com/example/hello_world/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.hello_world
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.6.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.1.2'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
6 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4 | def properties = new Properties()
5 |
6 | assert localPropertiesFile.exists()
7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8 |
9 | def flutterSdkPath = properties.getProperty("flutter.sdk")
10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12 |
--------------------------------------------------------------------------------
/ios/.gitignore:
--------------------------------------------------------------------------------
1 | **/dgph
2 | *.mode1v3
3 | *.mode2v3
4 | *.moved-aside
5 | *.pbxuser
6 | *.perspectivev3
7 | **/*sync/
8 | .sconsign.dblite
9 | .tags*
10 | **/.vagrant/
11 | **/DerivedData/
12 | Icon?
13 | **/Pods/
14 | **/.symlinks/
15 | profile
16 | xcuserdata
17 | **/.generated/
18 | Flutter/App.framework
19 | Flutter/Flutter.framework
20 | Flutter/Flutter.podspec
21 | Flutter/Generated.xcconfig
22 | Flutter/ephemeral/
23 | Flutter/app.flx
24 | Flutter/app.zip
25 | Flutter/flutter_assets/
26 | Flutter/flutter_export_environment.sh
27 | ServiceDefinitions.json
28 | Runner/GeneratedPluginRegistrant.*
29 |
30 | # Exceptions to above rules.
31 | !default.mode1v3
32 | !default.mode2v3
33 | !default.pbxuser
34 | !default.perspectivev3
35 |
--------------------------------------------------------------------------------
/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 11.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleDisplayName
8 | Hello World
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | hello_world
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(FLUTTER_BUILD_NUMBER)
25 | LSRequiresIPhoneOS
26 |
27 | UILaunchStoryboardName
28 | LaunchScreen
29 | UIMainStoryboardFile
30 | Main
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | UIViewControllerBasedStatusBarAppearance
45 |
46 | CADisableMinimumFrameDurationOnPhone
47 |
48 | UIApplicationSupportsIndirectInputEvents
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/lib/Chapter01/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | // This widget is the root of your application.
11 | @override
12 | Widget build(BuildContext context) {
13 | return MaterialApp(
14 | title: 'Flutter Demo',
15 | theme: ThemeData(
16 | // This is the theme of your application.
17 | //
18 | // Try running your application with "flutter run". You'll see the
19 | // application has a blue toolbar. Then, without quitting the app, try
20 | // changing the primarySwatch below to Colors.green and then invoke
21 | // "hot reload" (press "r" in the console where you ran "flutter run",
22 | // or simply save your changes to "hot reload" in a Flutter IDE).
23 | // Notice that the counter didn't reset back to zero; the application
24 | // is not restarted.
25 | primarySwatch: Colors.blue,
26 | ),
27 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
28 | );
29 | }
30 | }
31 |
32 | class MyHomePage extends StatefulWidget {
33 | const MyHomePage({super.key, required this.title});
34 |
35 | // This widget is the home page of your application. It is stateful, meaning
36 | // that it has a State object (defined below) that contains fields that affect
37 | // how it looks.
38 |
39 | // This class is the configuration for the state. It holds the values (in this
40 | // case the title) provided by the parent (in this case the App widget) and
41 | // used by the build method of the State. Fields in a Widget subclass are
42 | // always marked "final".
43 |
44 | final String title;
45 |
46 | @override
47 | State createState() => _MyHomePageState();
48 | }
49 |
50 | class _MyHomePageState extends State {
51 | int _counter = 0;
52 |
53 | void _incrementCounter() {
54 | setState(() {
55 | // This call to setState tells the Flutter framework that something has
56 | // changed in this State, which causes it to rerun the build method below
57 | // so that the display can reflect the updated values. If we changed
58 | // _counter without calling setState(), then the build method would not be
59 | // called again, and so nothing would appear to happen.
60 | _counter++;
61 | });
62 | }
63 |
64 | @override
65 | Widget build(BuildContext context) {
66 | // This method is rerun every time setState is called, for instance as done
67 | // by the _incrementCounter method above.
68 | //
69 | // The Flutter framework has been optimized to make rerunning build methods
70 | // fast, so that you can just rebuild anything that needs updating rather
71 | // than having to individually change instances of widgets.
72 | return Scaffold(
73 | appBar: AppBar(
74 | // Here we take the value from the MyHomePage object that was created by
75 | // the App.build method, and use it to set our appbar title.
76 | title: Text(widget.title),
77 | ),
78 | body: Center(
79 | // Center is a layout widget. It takes a single child and positions it
80 | // in the middle of the parent.
81 | child: Column(
82 | // Column is also a layout widget. It takes a list of children and
83 | // arranges them vertically. By default, it sizes itself to fit its
84 | // children horizontally, and tries to be as tall as its parent.
85 | //
86 | // Invoke "debug painting" (press "p" in the console, choose the
87 | // "Toggle Debug Paint" action from the Flutter Inspector in Android
88 | // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
89 | // to see the wireframe for each widget.
90 | //
91 | // Column has various properties to control how it sizes itself and
92 | // how it positions its children. Here we use mainAxisAlignment to
93 | // center the children vertically; the main axis here is the vertical
94 | // axis because Columns are vertical (the cross axis would be
95 | // horizontal).
96 | mainAxisAlignment: MainAxisAlignment.center,
97 | children: [
98 | const Text(
99 | 'You have pushed the button this many times:',
100 | ),
101 | Text(
102 | '$_counter',
103 | style: Theme.of(context).textTheme.headline4,
104 | ),
105 | ],
106 | ),
107 | ),
108 | floatingActionButton: FloatingActionButton(
109 | onPressed: _incrementCounter,
110 | tooltip: 'Increment',
111 | child: const Icon(Icons.add),
112 | ), // This trailing comma makes auto-formatting nicer for build methods.
113 | );
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/lib/Chapter02/anonymous.dart:
--------------------------------------------------------------------------------
1 | void main() {
2 | List list = [1, 2, 3, 4];
3 | list.forEach((number) => print('hello $number'));
4 | }
5 |
--------------------------------------------------------------------------------
/lib/Chapter02/happy_birthday_example.dart:
--------------------------------------------------------------------------------
1 | sayHappyBirthdayPositional(String name, int age) {
2 | return "$name is ${age.toString()} years old";
3 | }
4 |
5 | sayHappyBirthdayOptional(String name, [int? age]) {
6 | return "$name is $age years old";
7 | }
8 |
9 | sayHappyBirthdayOptionalDefault(String name, [int age = 21]) {
10 | return "Happy birthday $name! You are $age years old.";
11 | }
12 |
13 | void main() {
14 | var hello = sayHappyBirthdayOptionalDefault('Robert');
15 | print(hello);
16 | }
17 | // Prints Happy birthday Robert! You are 21 years old.
18 |
19 | sayHappyBirthdayNamedParameters(String name, {int age = 7}) {
20 | return "Happy birthday $name! You are $age years old.";
21 | }
22 |
23 | sayHappyBirthdayNamedRequired(String name, {required int age}) {
24 | return "Happy birthday $name! You are $age years old.";
25 | }
26 |
--------------------------------------------------------------------------------
/lib/Chapter02/hello_example.dart:
--------------------------------------------------------------------------------
1 | void main() {
2 | String helloMessage = sayHello();
3 | print(helloMessage);
4 | }
5 |
6 | String sayHello() {
7 | return "Hello world!";
8 | }
9 |
--------------------------------------------------------------------------------
/lib/Chapter02/main.dart:
--------------------------------------------------------------------------------
1 | void main() {
2 | for (int i = 0; i < 5; i++) {
3 | print('hello ${i + 1}');
4 | }
5 | }
6 |
7 | void variables() {
8 | var inferredString = "Hello"; // Type inferred as String
9 | String explicitString = "World"; // Type is explicit
10 | }
11 |
12 | void nullSafety() {
13 | // Old null unsafe code:
14 | //int newNumber; // newNumber is initialized to null
15 | //print(newNumber); // Prints null
16 | //newNumber = 42; // Update the value of newNumber
17 | //print(newNumber); // Prints 42
18 |
19 | int? newNumber; // newNumber type allows nullability
20 | print(newNumber); // Prints null
21 | newNumber = 42; // Update the value of newNumber
22 | print(newNumber); // Prints 42
23 | }
24 |
25 | void lateVariables() {
26 | late int newNumber; // newNumber type allows nullability
27 | // Do some initialisation stuff
28 | newNumber = 42; // Update the value of newNumber
29 | print(newNumber); // Prints 42
30 |
31 | int? goals;
32 |
33 | // Invalid print statement due to nullability
34 | //print(goals + 2);
35 |
36 | // Corrected by testing for null
37 | if (goals != null) {
38 | print(goals + 2);
39 | }
40 | }
41 |
42 | void lists() {
43 | List dynamicList = []; // Create an empty List
44 | print(dynamicList.length); // Prints 0
45 | dynamicList.add("Hello");
46 | print(dynamicList[0]); // Prints “World”
47 | print(dynamicList.length); // Prints 1
48 | List preFilledDynamicList = [1, 2, 3];
49 | print(preFilledDynamicList[0]); // Prints 1
50 | print(preFilledDynamicList.length); // Prints 3
51 |
52 | List fixedList = List.filled(3, "World");
53 | fixedList.add("Hello"); // Error
54 | fixedList[0] = "Hello";
55 | print(fixedList[0]); // Prints "“Hello"”;
56 | print(fixedList[1]); // Prints "“World"”;
57 | }
58 |
59 | void maps() {
60 | Map nameAgeMap = {}; // Create an empty Map
61 | nameAgeMap["Alice"] = 23;
62 | print(nameAgeMap["Alice"]); // Prints 23
63 | Map preFilledMap = {"Sarah": 1, "Alex": 2};
64 | print(preFilledMap["Sarah"]); // Prints 1
65 | print(preFilledMap.length); // Prints 2
66 | preFilledMap.remove("Alex");
67 | print(preFilledMap.length); // Prints 1
68 | }
69 |
70 | void strings() {
71 | String singleQuoteString = 'Here is a single quote string';
72 | String doubleQuoteString = "Here is a double quote string";
73 |
74 | String multiLineString = '''Here is a multi-line single
75 | quote string''';
76 |
77 | String str1 = 'Here is a ';
78 | String str2 = str1 + 'concatenated string';
79 | print(str2); // Prints Here is a concatenated string
80 | print(str2[0]); // Prints the single character 'H'
81 |
82 | String someString = "Happy string";
83 | print("The string is: $someString");
84 | // prints The string is: Happy string
85 | // No curly brackets were required
86 | print("The string length is: ${someString.length}");
87 | // prints The string length is: 16
88 | // Curly brackets were required
89 | print("The string length is: $someString.length");
90 | // prints The string length is: Happy string.length
91 | // Omitting the curly brackets meant only the variable was evaluated, not the method on the variable.
92 | }
93 |
94 | void finalAndConst() {
95 | final String defaultLocation = "Staithes";
96 | const int defaultStars = 3;
97 | }
98 |
99 | void dynamicAndAs() {
100 | Map json = {};
101 | final id = json['id'] as String;
102 | }
103 |
104 | void operators() {
105 | int totalGoals = 2;
106 | totalGoals = totalGoals + 3; // Without shortcut
107 | totalGoals += 3; // With shortcut
108 | print("The goal total is: $totalGoals"); // Prints 8
109 | }
110 |
111 | void ifElse() {
112 | String winners = "Middlesbrough";
113 | if (winners == "Everton") {
114 | print("Everton win");
115 | } else if (winners == "Middlesbrough") {
116 | print("Middlesbrough win");
117 | } else {
118 | print("Draw");
119 | }
120 | // Prints Middlesbrough win
121 | if (winners == "Middlesbrough") print("Middlesbrough win again");
122 | // Prints Middlesbrough win again
123 |
124 | String test = "true";
125 | // Invalid test - truthy is not supported by Dart
126 | // if (test) {
127 | // print("Truthy");
128 | //}
129 | }
130 |
131 | void whileLoops() {
132 | int counter = 0;
133 | while (counter < 2) {
134 | print(counter);
135 | counter++;
136 | }
137 | // Prints 0, 1
138 | do {
139 | print(counter);
140 | counter++;
141 | } while (counter < 2);
142 | // Prints 2
143 | }
144 |
145 | void forLoop() {
146 | for (int index = 0; index < 2; index++) {
147 | print(index);
148 | }
149 | // Prints 0, 1
150 | }
151 |
152 | void breakContinue() {
153 | int counter = 0;
154 | while (counter < 10) {
155 | counter++;
156 | if (counter == 4) {
157 | break;
158 | } else if (counter == 2) {
159 | continue;
160 | }
161 | print(counter);
162 | }
163 | // Prints 1, 3
164 | }
165 |
166 | void switchStatement() {
167 | String location = "Whitby";
168 | switch (location) {
169 | case "Whitby":
170 | // Show Whitby information
171 | break;
172 | case "Saltburn":
173 | // Show Saltburn information
174 | break;
175 | default:
176 | // Show error message, no location information found
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/lib/Chapter02/records.dart:
--------------------------------------------------------------------------------
1 | (String, int, String, int) getFinalScore() {
2 | return ("Middlesbrough", 4, "Manchester City", 0);
3 | }
4 |
5 | void main() {
6 | {
7 | var finalScore = getFinalScore();
8 | var homeTeam = finalScore.$1;
9 | }
10 |
11 | {
12 | var (homeTeam, homeScore, awayTeam, awayScore) = getFinalScore();
13 | print(homeTeam);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lib/Chapter02/scope.dart:
--------------------------------------------------------------------------------
1 | globalFunction() {
2 | print("Top-level globalFunction");
3 | }
4 |
5 | simpleFunction() {
6 | print("SimpleFunction");
7 | globalFunction() {
8 | print("Nested globalFunction");
9 | }
10 |
11 | globalFunction();
12 | }
13 |
14 | main() {
15 | simpleFunction();
16 | globalFunction();
17 | }
18 |
--------------------------------------------------------------------------------
/lib/Chapter04/abstract.dart:
--------------------------------------------------------------------------------
1 | abstract class Person {
2 | String firstName;
3 | String lastName;
4 | Person(this.firstName, this.lastName);
5 | String get fullName;
6 | }
7 |
8 | class Student extends Person {
9 | String nickName;
10 | Student(
11 | String firstName,
12 | String lastName,
13 | this.nickName,
14 | ) : super(firstName, lastName);
15 |
16 | @override
17 | String get fullName => "$firstName $lastName";
18 |
19 | @override
20 | String toString() => "$fullName, aka $nickName";
21 | }
22 |
23 | class Student2 implements Person {
24 | String nickName;
25 | @override
26 | String firstName;
27 | @override
28 | String lastName;
29 | Student2(this.firstName, this.lastName, this.nickName);
30 | @override
31 | String get fullName => "$firstName $lastName";
32 | @override
33 | String toString() => "$fullName, also known as $nickName";
34 | }
35 |
36 | abstract interface class Person2 {
37 | String get fullName;
38 | String toString();
39 | }
40 |
41 | main() {
42 | Person student = Student("Clark", "Kent", "Kal-El");
43 | // Works because we are instantiating the subtype
44 | // Person p = new Person();
45 | // abstract classes cannot be instantiated
46 | print(student);
47 | }
48 |
--------------------------------------------------------------------------------
/lib/Chapter04/enum.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/foundation.dart';
2 |
3 | enum PersonType { student, employee }
4 |
5 | class Person {
6 | PersonType type;
7 |
8 | String? firstName;
9 | String? lastName;
10 |
11 | Person(this.type);
12 |
13 | String get fullName => "$firstName $lastName";
14 | set fullName(String fullName) {
15 | var parts = fullName.split(" ");
16 | this.firstName = parts.first;
17 | this.lastName = parts.last;
18 | }
19 | }
20 |
21 | main() {
22 | print(PersonType.values);
23 | Person somePerson = Person(PersonType.student);
24 | somePerson.type = PersonType.employee;
25 | print(somePerson.type);
26 | print(somePerson.type.index);
27 | print(describeEnum(PersonType.employee));
28 |
29 | switch (somePerson.type) {
30 | case PersonType.student:
31 | print('Learning time!');
32 | break;
33 | case PersonType.employee:
34 | print('Meeting time!');
35 | break;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/lib/Chapter04/futures.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | void longRunningOperation() {
4 | for (int i = 0; i < 5; i++) {
5 | sleep(Duration(seconds: 1));
6 | print("Index: $i");
7 | }
8 | }
9 |
10 | Future longRunningOperation2() async {
11 | for (int i = 0; i < 5; i++) {
12 | sleep(Duration(seconds: 1));
13 | print("Index: $i");
14 | }
15 | }
16 |
17 | Future longRunningOperation3() async {
18 | for (int i = 0; i < 5; i++) {
19 | await Future.delayed(Duration(seconds: 1));
20 | print("Index: $i");
21 | }
22 | }
23 |
24 | main() {
25 | print("Start of long running operation");
26 | longRunningOperation();
27 | print("Continuing main body");
28 | for (int i = 10; i < 15; i++) {
29 | sleep(Duration(seconds: 1));
30 | print("Index from main: $i");
31 | }
32 | print("End of main");
33 | }
34 |
35 | main2() async {
36 | print("Start of long running operation");
37 | longRunningOperation3();
38 | print("Continuing main body");
39 | for (int i = 10; i < 15; i++) {
40 | await Future.delayed(Duration(seconds: 1));
41 | print("Index from main: $i");
42 | }
43 | print("End of main");
44 | }
45 |
--------------------------------------------------------------------------------
/lib/Chapter04/generics.dart:
--------------------------------------------------------------------------------
1 | main() {
2 | List placeNames = ["Middlesbrough", "New York"];
3 | placeNames.add(1);
4 | print("Place names: $placeNames");
5 | }
6 | // prints Place names: [Middlesbrough, New York, 1]
7 |
8 | main2() {
9 | var placeNames = ["Middlesbrough", "New York"];
10 | var landmarks = {
11 | "Middlesbrough": "Transporter bridge",
12 | "New York": "Statue of Liberty",
13 | };
14 | }
15 |
16 | main3() {
17 | var landmarks = {
18 | "Middlesbrough": "Transporter bridge",
19 | "New York": "Statue of Liberty",
20 | "Barnmouth": null,
21 | };
22 | }
23 |
--------------------------------------------------------------------------------
/lib/Chapter04/isolate.dart:
--------------------------------------------------------------------------------
1 | import 'dart:isolate';
2 |
3 | Future longRunningOperation(String message) async {
4 | for (int i = 0; i < 5; i++) {
5 | await Future.delayed(Duration(seconds: 1));
6 | print("$message: $i");
7 | }
8 | }
9 |
10 | void main() async {
11 | print("start of long running operation");
12 | Isolate.spawn(longRunningOperation, "Hello");
13 | print("Continuing main body");
14 | for (int i = 10; i < 15; i++) {
15 | await Future.delayed(Duration(seconds: 1));
16 | print("Index from main: $i");
17 | }
18 | print("End of main");
19 | }
20 |
--------------------------------------------------------------------------------
/lib/Chapter04/mixin.dart:
--------------------------------------------------------------------------------
1 | abstract class Person {
2 | String firstName;
3 | String lastName;
4 | Person(this.firstName, this.lastName);
5 | }
6 |
7 | mixin class ProgrammingSkills {
8 | coding() {
9 | print("writing code...");
10 | }
11 | }
12 |
13 | mixin class ManagementSkills {
14 | manage() {
15 | print("managing project...");
16 | }
17 | }
18 |
19 | class SeniorDeveloper extends Person with ProgrammingSkills, ManagementSkills {
20 | SeniorDeveloper(String firstName, String lastName) : super(firstName, lastName);
21 | }
22 |
23 | class JuniorDeveloper extends Person with ProgrammingSkills {
24 | JuniorDeveloper(String firstName, String lastName) : super(firstName, lastName);
25 | }
26 |
--------------------------------------------------------------------------------
/lib/Chapter04/person_version1.dart:
--------------------------------------------------------------------------------
1 | class Person {
2 | String? firstName;
3 | String? lastName;
4 |
5 | String get fullName => "$firstName $lastName";
6 | set fullName(String fullName) {
7 | var parts = fullName.split(" ");
8 | this.firstName = parts.first;
9 | this.lastName = parts.last;
10 | }
11 | }
12 |
13 | main() {
14 | Person somePerson = Person();
15 | somePerson.firstName = "Clark";
16 | somePerson.lastName = "Kent";
17 |
18 | print(somePerson.fullName); // prints Clark Kent
19 | somePerson.fullName = "peter parker";
20 | }
21 |
--------------------------------------------------------------------------------
/lib/Chapter04/person_version2.dart:
--------------------------------------------------------------------------------
1 | class Person {
2 | String? firstName;
3 | String? lastName;
4 |
5 | static String personLabel = "Person name :";
6 | String get fullName => "$personLabel $firstName $lastName";
7 |
8 | set fullName(String fullName) {
9 | var parts = fullName.split(" ");
10 | this.firstName = parts.first;
11 | this.lastName = parts.last;
12 | }
13 |
14 | static void printsPerson(Person person) {
15 | print("$personLabel ${person.firstName} ${person.lastName}");
16 | }
17 | }
18 |
19 | main() {
20 | Person somePerson = Person();
21 | somePerson.firstName = "Clark";
22 | somePerson.lastName = "Kent";
23 | Person anotherPerson = Person();
24 | anotherPerson.firstName = "Peter";
25 | anotherPerson.lastName = "Parker";
26 | print(somePerson.fullName);
27 | // prints Person name: Clark kent
28 | print(anotherPerson.fullName);
29 | // prints Person name: Peter Parker
30 | Person.personLabel = "name:";
31 | print(somePerson.fullName);
32 | // prints name: Clark Kent
33 | print(anotherPerson.fullName);
34 | // prints name: Peter Parker
35 | }
36 |
--------------------------------------------------------------------------------
/lib/Chapter04/person_version3.dart:
--------------------------------------------------------------------------------
1 | class Person {
2 | String firstName;
3 | String lastName;
4 | Person(this.firstName, this.lastName);
5 | String getFullName() => "$firstName $lastName";
6 | }
7 |
8 | class Student extends Person {
9 | String nickName;
10 | Student(
11 | String firstName,
12 | String lastName,
13 | this.nickName,
14 | ) : super(firstName, lastName);
15 |
16 | @override
17 | String toString() => "${getFullName()}, aka $nickName";
18 | }
19 |
20 | main() {
21 | Student student = Student("Clark", "Kent", "Kal-El");
22 | print(student);
23 | }
24 |
--------------------------------------------------------------------------------
/lib/Chapter05/destination_widget.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class DestinationWidget extends StatelessWidget {
4 | DestinationWidget({required this.destinationName});
5 |
6 | final String destinationName;
7 |
8 | @override
9 | Widget build(BuildContext context) {
10 | return Text(destinationName);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/lib/Chapter05/main_column.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hello_world/Chapter05/destination_widget.dart';
3 |
4 | void main() {
5 | runApp(const MyApp());
6 | }
7 |
8 | class MyApp extends StatelessWidget {
9 | const MyApp({super.key});
10 |
11 | // This widget is the root of your application.
12 | @override
13 | Widget build(BuildContext context) {
14 | return MaterialApp(
15 | title: 'Flutter Demo',
16 | theme: ThemeData(
17 | // This is the theme of your application.
18 | //
19 | // Try running your application with "flutter run". You'll see the
20 | // application has a blue toolbar. Then, without quitting the app, try
21 | // changing the primarySwatch below to Colors.green and then invoke
22 | // "hot reload" (press "r" in the console where you ran "flutter run",
23 | // or simply save your changes to "hot reload" in a Flutter IDE).
24 | // Notice that the counter didn't reset back to zero; the application
25 | // is not restarted.
26 | primarySwatch: Colors.blue,
27 | ),
28 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
29 | );
30 | }
31 | }
32 |
33 | class MyHomePage extends StatefulWidget {
34 | const MyHomePage({super.key, required this.title});
35 |
36 | // This widget is the home page of your application. It is stateful, meaning
37 | // that it has a State object (defined below) that contains fields that affect
38 | // how it looks.
39 |
40 | // This class is the configuration for the state. It holds the values (in this
41 | // case the title) provided by the parent (in this case the App widget) and
42 | // used by the build method of the State. Fields in a Widget subclass are
43 | // always marked "final".
44 |
45 | final String title;
46 |
47 | @override
48 | State createState() => _MyHomePageState();
49 | }
50 |
51 | class _MyHomePageState extends State {
52 | @override
53 | Widget build(BuildContext context) {
54 | return Scaffold(
55 | appBar: AppBar(
56 | title: Text(widget.title),
57 | ),
58 | body: Center(
59 | child: Column(
60 | crossAxisAlignment: CrossAxisAlignment.start,
61 | mainAxisSize: MainAxisSize.min,
62 | children: [
63 | DestinationWidget(destinationName: 'Staithes'),
64 | DestinationWidget(destinationName: 'Saltburn'),
65 | DestinationWidget(destinationName: 'Whitby'),
66 | ],
67 | )),
68 | );
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/lib/Chapter05/main_column_too_long.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hello_world/Chapter05/destination_widget.dart';
3 |
4 | void main() {
5 | runApp(const MyApp());
6 | }
7 |
8 | class MyApp extends StatelessWidget {
9 | const MyApp({super.key});
10 |
11 | // This widget is the root of your application.
12 | @override
13 | Widget build(BuildContext context) {
14 | return MaterialApp(
15 | title: 'Flutter Demo',
16 | theme: ThemeData(
17 | // This is the theme of your application.
18 | //
19 | // Try running your application with "flutter run". You'll see the
20 | // application has a blue toolbar. Then, without quitting the app, try
21 | // changing the primarySwatch below to Colors.green and then invoke
22 | // "hot reload" (press "r" in the console where you ran "flutter run",
23 | // or simply save your changes to "hot reload" in a Flutter IDE).
24 | // Notice that the counter didn't reset back to zero; the application
25 | // is not restarted.
26 | primarySwatch: Colors.blue,
27 | ),
28 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
29 | );
30 | }
31 | }
32 |
33 | class MyHomePage extends StatefulWidget {
34 | const MyHomePage({super.key, required this.title});
35 |
36 | // This widget is the home page of your application. It is stateful, meaning
37 | // that it has a State object (defined below) that contains fields that affect
38 | // how it looks.
39 |
40 | // This class is the configuration for the state. It holds the values (in this
41 | // case the title) provided by the parent (in this case the App widget) and
42 | // used by the build method of the State. Fields in a Widget subclass are
43 | // always marked "final".
44 |
45 | final String title;
46 |
47 | @override
48 | State createState() => _MyHomePageState();
49 | }
50 |
51 | class _MyHomePageState extends State {
52 | @override
53 | Widget build(BuildContext context) {
54 | return Scaffold(
55 | appBar: AppBar(
56 | title: Text(widget.title),
57 | ),
58 | body: Center(
59 | child: Column(
60 | crossAxisAlignment: CrossAxisAlignment.start,
61 | mainAxisSize: MainAxisSize.min,
62 | children: [
63 | Padding(
64 | padding: const EdgeInsets.all(16),
65 | child: DestinationWidget(destinationName: 'Staithes'),
66 | ),
67 | Padding(
68 | padding: const EdgeInsets.all(16),
69 | child: DestinationWidget(destinationName: 'Staithes'),
70 | ),
71 | Padding(
72 | padding: const EdgeInsets.all(16),
73 | child: DestinationWidget(destinationName: 'Staithes'),
74 | ),
75 | Padding(
76 | padding: const EdgeInsets.all(16),
77 | child: DestinationWidget(destinationName: 'Staithes'),
78 | ),
79 | Padding(
80 | padding: const EdgeInsets.all(16),
81 | child: DestinationWidget(destinationName: 'Staithes'),
82 | ),
83 | Padding(
84 | padding: const EdgeInsets.all(16),
85 | child: DestinationWidget(destinationName: 'Staithes'),
86 | ),
87 | Padding(
88 | padding: const EdgeInsets.all(16),
89 | child: DestinationWidget(destinationName: 'Staithes'),
90 | ),
91 | Padding(
92 | padding: const EdgeInsets.all(16),
93 | child: DestinationWidget(destinationName: 'Staithes'),
94 | ),
95 | Padding(
96 | padding: const EdgeInsets.all(16),
97 | child: DestinationWidget(destinationName: 'Staithes'),
98 | ),
99 | Padding(
100 | padding: const EdgeInsets.all(16),
101 | child: DestinationWidget(destinationName: 'Staithes'),
102 | ),
103 | Padding(
104 | padding: const EdgeInsets.all(16),
105 | child: DestinationWidget(destinationName: 'Staithes'),
106 | ),
107 | Padding(
108 | padding: const EdgeInsets.all(16),
109 | child: DestinationWidget(destinationName: 'Staithes'),
110 | ),
111 | ],
112 | ),
113 | ),
114 | );
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/lib/Chapter05/main_list_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hello_world/Chapter05/destination_widget.dart';
3 |
4 | void main() {
5 | runApp(const MyApp());
6 | }
7 |
8 | class MyApp extends StatelessWidget {
9 | const MyApp({super.key});
10 |
11 | // This widget is the root of your application.
12 | @override
13 | Widget build(BuildContext context) {
14 | return MaterialApp(
15 | title: 'Flutter Demo',
16 | theme: ThemeData(
17 | // This is the theme of your application.
18 | //
19 | // Try running your application with "flutter run". You'll see the
20 | // application has a blue toolbar. Then, without quitting the app, try
21 | // changing the primarySwatch below to Colors.green and then invoke
22 | // "hot reload" (press "r" in the console where you ran "flutter run",
23 | // or simply save your changes to "hot reload" in a Flutter IDE).
24 | // Notice that the counter didn't reset back to zero; the application
25 | // is not restarted.
26 | primarySwatch: Colors.blue,
27 | ),
28 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
29 | );
30 | }
31 | }
32 |
33 | class MyHomePage extends StatefulWidget {
34 | const MyHomePage({super.key, required this.title});
35 |
36 | // This widget is the home page of your application. It is stateful, meaning
37 | // that it has a State object (defined below) that contains fields that affect
38 | // how it looks.
39 |
40 | // This class is the configuration for the state. It holds the values (in this
41 | // case the title) provided by the parent (in this case the App widget) and
42 | // used by the build method of the State. Fields in a Widget subclass are
43 | // always marked "final".
44 |
45 | final String title;
46 |
47 | @override
48 | State createState() => _MyHomePageState();
49 | }
50 |
51 | class _MyHomePageState extends State {
52 | @override
53 | Widget build(BuildContext context) {
54 | return Scaffold(
55 | appBar: AppBar(
56 | title: Text(widget.title),
57 | ),
58 | body: Center(
59 | child: ListView(
60 | children: [
61 | Padding(
62 | padding: const EdgeInsets.all(16),
63 | child: DestinationWidget(destinationName: 'Staithes'),
64 | ),
65 | Padding(
66 | padding: const EdgeInsets.all(16),
67 | child: DestinationWidget(destinationName: 'Staithes'),
68 | ),
69 | Padding(
70 | padding: const EdgeInsets.all(16),
71 | child: DestinationWidget(destinationName: 'Staithes'),
72 | ),
73 | Padding(
74 | padding: const EdgeInsets.all(16),
75 | child: DestinationWidget(destinationName: 'Staithes'),
76 | ),
77 | Padding(
78 | padding: const EdgeInsets.all(16),
79 | child: DestinationWidget(destinationName: 'Staithes'),
80 | ),
81 | Padding(
82 | padding: const EdgeInsets.all(16),
83 | child: DestinationWidget(destinationName: 'Staithes'),
84 | ),
85 | Padding(
86 | padding: const EdgeInsets.all(16),
87 | child: DestinationWidget(destinationName: 'Staithes'),
88 | ),
89 | Padding(
90 | padding: const EdgeInsets.all(16),
91 | child: DestinationWidget(destinationName: 'Staithes'),
92 | ),
93 | Padding(
94 | padding: const EdgeInsets.all(16),
95 | child: DestinationWidget(destinationName: 'Staithes'),
96 | ),
97 | Padding(
98 | padding: const EdgeInsets.all(16),
99 | child: DestinationWidget(destinationName: 'Staithes'),
100 | ),
101 | Padding(
102 | padding: const EdgeInsets.all(16),
103 | child: DestinationWidget(destinationName: 'Staithes'),
104 | ),
105 | Padding(
106 | padding: const EdgeInsets.all(16),
107 | child: DestinationWidget(destinationName: 'Staithes'),
108 | ),
109 | ],
110 | ),
111 | ),
112 | );
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/lib/Chapter06/destination_like.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class DestinationLike extends StatefulWidget {
4 | DestinationLike({Key? key}) : super(key: key);
5 |
6 | @override
7 | State createState() => _DestinationLikeState();
8 | }
9 |
10 | class _DestinationLikeState extends State {
11 | int _likeCounter = 0;
12 | @override
13 | Widget build(BuildContext context) {
14 | return GestureDetector(
15 | onTap: () {
16 | setState(() {
17 | _likeCounter++;
18 | });
19 | },
20 | child: Container(
21 | color: Colors.grey,
22 | child: Text(
23 | "Like count: $_likeCounter",
24 | ),
25 | ),
26 | );
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/lib/Chapter06/destination_widget.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class DestinationWidget extends StatefulWidget {
4 | DestinationWidget({required this.destinationName});
5 |
6 | final String destinationName;
7 |
8 | @override
9 | State createState() => _DestinationWidgetState();
10 | }
11 |
12 | class _DestinationWidgetState extends State {
13 | late int _likeCounter;
14 |
15 | @override
16 | void initState() {
17 | super.initState();
18 |
19 | _likeCounter = 0;
20 | }
21 |
22 | @override
23 | Widget build(BuildContext context) {
24 | return Row(
25 | children: [
26 | Text(widget.destinationName),
27 | Column(
28 | children: [
29 | IconButton(
30 | onPressed: () {
31 | setState(() {
32 | _likeCounter++;
33 | });
34 | },
35 | icon: const Icon(Icons.thumb_up),
36 | ),
37 | Text(_likeCounter.toString()),
38 | ],
39 | ),
40 | ],
41 | );
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/lib/Chapter06/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return MaterialApp(
13 | title: 'Flutter Demo',
14 | theme: ThemeData(
15 | primarySwatch: Colors.blue,
16 | ),
17 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
18 | );
19 | }
20 | }
21 |
22 | class MyHomePage extends StatefulWidget {
23 | const MyHomePage({super.key, required this.title});
24 |
25 | final String title;
26 |
27 | @override
28 | State createState() => _MyHomePageState();
29 | }
30 |
31 | class _MyHomePageState extends State {
32 | final _key = GlobalKey();
33 | @override
34 | Widget build(BuildContext context) {
35 | return Scaffold(
36 | appBar: AppBar(
37 | title: Text(widget.title),
38 | ),
39 | body: Center(
40 | child: Form(
41 | key: _key,
42 | child: Column(
43 | children: [
44 | TextFormField(),
45 | Builder(
46 | builder: (BuildContext subContext) => TextButton(
47 | onPressed: () {
48 | final valid = Form.of(subContext).validate();
49 | print("valid: $valid");
50 | },
51 | child: Text("validate"),
52 | ),
53 | ),
54 | ],
55 | ),
56 | ),
57 | ),
58 | );
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/lib/Chapter06/main_form.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter/services.dart';
3 |
4 | void main() {
5 | runApp(const MyApp());
6 | }
7 |
8 | class MyApp extends StatelessWidget {
9 | const MyApp({super.key});
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | return MaterialApp(
14 | title: 'Flutter Demo',
15 | theme: ThemeData(
16 | primarySwatch: Colors.blue,
17 | ),
18 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
19 | );
20 | }
21 | }
22 |
23 | class MyHomePage extends StatefulWidget {
24 | const MyHomePage({super.key, required this.title});
25 |
26 | final String title;
27 |
28 | @override
29 | State createState() => _MyHomePageState();
30 | }
31 |
32 | class _MyHomePageState extends State {
33 | final _key = GlobalKey();
34 |
35 | @override
36 | Widget build(BuildContext context) {
37 | return Scaffold(
38 | appBar: AppBar(
39 | title: Text(widget.title),
40 | ),
41 | body: Center(
42 | child: Form(
43 | key: _key,
44 | child: Column(
45 | children: [
46 | VerificationCodeFormField(
47 | validator: (val) => val == null || val.isEmpty ? "Need a value" : null,
48 | ),
49 | Builder(
50 | builder: (BuildContext subContext) => TextButton(
51 | onPressed: () {
52 | final valid = Form.of(subContext).validate();
53 | print("valid: $valid");
54 | },
55 | child: Text("validate"),
56 | ),
57 | ),
58 | ],
59 | ),
60 | ),
61 | ),
62 | );
63 | }
64 | }
65 |
66 | class VerificationCodeInput extends StatefulWidget {
67 | VerificationCodeInput({required this.borderSide, required this.onChanged, required this.controller});
68 | final BorderSide borderSide;
69 | final Function(String) onChanged;
70 | final TextEditingController controller;
71 |
72 | @override
73 | State createState() => _VerificationCodeInputState();
74 | }
75 |
76 | class _VerificationCodeInputState extends State {
77 | @override
78 | Widget build(BuildContext context) {
79 | return TextField(
80 | controller: widget.controller,
81 | inputFormatters: [
82 | FilteringTextInputFormatter.allow(RegExp("[0-9]")),
83 | LengthLimitingTextInputFormatter(6),
84 | ],
85 | textAlign: TextAlign.center,
86 | decoration: InputDecoration(
87 | border: OutlineInputBorder(
88 | borderSide: widget.borderSide,
89 | ),
90 | ),
91 | keyboardType: TextInputType.number,
92 | onChanged: widget.onChanged,
93 | );
94 | }
95 | }
96 |
97 | class VerificationCodeFormField extends FormField {
98 | VerificationCodeFormField({
99 | Key? key,
100 | FormFieldSetter? onSaved,
101 | FormFieldValidator? validator,
102 | }) : super(
103 | key: key,
104 | validator: validator,
105 | onSaved: onSaved,
106 | builder: (FormFieldState field) {
107 | _VerificationCodeFormFieldState state = field as _VerificationCodeFormFieldState;
108 | return VerificationCodeInput(
109 | controller: state._controller,
110 | borderSide: BorderSide.none,
111 | onChanged: (_) => print(_),
112 | );
113 | },
114 | );
115 | @override
116 | FormFieldState createState() => _VerificationCodeFormFieldState();
117 | }
118 |
119 | class _VerificationCodeFormFieldState extends FormFieldState {
120 | final TextEditingController _controller = TextEditingController(text: "");
121 | @override
122 | void initState() {
123 | super.initState();
124 | _controller.addListener(_controllerChanged);
125 | }
126 |
127 | void _controllerChanged() {
128 | didChange(_controller.text);
129 | }
130 |
131 | @override
132 | void reset() {
133 | super.reset();
134 | _controller.text = "";
135 | }
136 |
137 | @override
138 | void dispose() {
139 | _controller.removeListener(_controllerChanged);
140 | super.dispose();
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/lib/Chapter07/destination_list_tile.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class DestinationListTile extends StatelessWidget {
4 | const DestinationListTile({Key? key}) : super(key: key);
5 |
6 | @override
7 | Widget build(BuildContext context) {
8 | return Scaffold(
9 | appBar: AppBar(title: Text("List view")),
10 | body: ListView(
11 | children: [
12 | ListTile(
13 | title: Text("Teesside"),
14 | subtitle: Text("The home of the Lemon Top ice cream"),
15 | leading: Icon(Icons.location_on),
16 | onTap: () {},
17 | trailing: IconButton(
18 | icon: Icon(Icons.thumb_up),
19 | onPressed: () {},
20 | ),
21 | ),
22 | ],
23 | ),
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib/Chapter07/destination_widget_container.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class DestinationWidgetContainer extends StatefulWidget {
4 | DestinationWidgetContainer({required this.name, required this.description});
5 |
6 | final String name;
7 | final String description;
8 |
9 | @override
10 | State createState() => _DestinationWidgetContainerState();
11 | }
12 |
13 | class _DestinationWidgetContainerState extends State {
14 | late int _likeCounter;
15 |
16 | @override
17 | void initState() {
18 | super.initState();
19 |
20 | _likeCounter = 0;
21 | }
22 |
23 | @override
24 | Widget build(BuildContext context) {
25 | return Scaffold(
26 | appBar: AppBar(title: Text("Destination")),
27 | body: Column(
28 | children: [
29 | Container(
30 | decoration: ShapeDecoration(
31 | shape: StadiumBorder(
32 | side: BorderSide(
33 | color: Colors.green,
34 | width: 6,
35 | ),
36 | ),
37 | ),
38 | child: Text(
39 | widget.name,
40 | ),
41 | ),
42 | Text(
43 | widget.description,
44 | style: TextStyle(backgroundColor: Color(0x32a852)),
45 | ),
46 | IconButton(
47 | onPressed: () {
48 | setState(() {
49 | _likeCounter++;
50 | });
51 | },
52 | icon: const Icon(Icons.thumb_up),
53 | ),
54 | Text(_likeCounter.toString()),
55 | ElevatedButton(
56 | child: Text("Back"),
57 | onPressed: () {
58 | Navigator.of(context).pop();
59 | },
60 | ),
61 | ],
62 | ),
63 | );
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/lib/Chapter07/destination_widget_textstyle.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class DestinationWidgetTextStyle extends StatefulWidget {
4 | DestinationWidgetTextStyle({required this.name, required this.description});
5 |
6 | final String name;
7 | final String description;
8 |
9 | @override
10 | State createState() => _DestinationWidgetTextStyleState();
11 | }
12 |
13 | class _DestinationWidgetTextStyleState extends State {
14 | late int _likeCounter;
15 |
16 | @override
17 | void initState() {
18 | super.initState();
19 |
20 | _likeCounter = 0;
21 | }
22 |
23 | @override
24 | Widget build(BuildContext context) {
25 | return Scaffold(
26 | appBar: AppBar(title: Text("Destination")),
27 | body: Column(
28 | children: [
29 | Row(
30 | children: [
31 | Flexible(
32 | child: Text(
33 | "asdf asdf asdf asdf asdf asdf asdf adsf asdf asdf sadf asdf asdf ${widget.name}",
34 | style: TextStyle(
35 | backgroundColor: Color.fromRGBO(50, 168, 82, 1),
36 | color: Colors.red,
37 | fontSize: 14,
38 | fontWeight: FontWeight.w300,
39 | fontStyle: FontStyle.italic,
40 | letterSpacing: 2,
41 | wordSpacing: 3,
42 | overflow: TextOverflow.fade,
43 | decoration: TextDecoration.underline,
44 | ),
45 | ),
46 | ),
47 | ],
48 | ),
49 | Text(
50 | widget.description,
51 | style: TextStyle(backgroundColor: Color(0x32a852)),
52 | ),
53 | IconButton(
54 | onPressed: () {
55 | setState(() {
56 | _likeCounter++;
57 | });
58 | },
59 | icon: const Icon(Icons.thumb_up),
60 | ),
61 | Text(_likeCounter.toString()),
62 | ElevatedButton(
63 | child: Text("Back"),
64 | onPressed: () {
65 | Navigator.of(context).pop();
66 | },
67 | ),
68 | ],
69 | ),
70 | );
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/lib/Chapter07/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hello_world/Chapter07/destination_list_tile.dart';
3 | import 'package:hello_world/Chapter07/destination_widget_container.dart';
4 | import 'package:hello_world/Chapter07/destination_widget_textstyle.dart';
5 | import 'package:hello_world/Chapter07/sliver_page.dart';
6 |
7 | void main() {
8 | runApp(const MyApp());
9 | }
10 |
11 | class MyApp extends StatelessWidget {
12 | const MyApp({super.key});
13 |
14 | @override
15 | Widget build(BuildContext context) {
16 | return MaterialApp(
17 | title: 'Flutter Demo',
18 | theme: ThemeData(
19 | primarySwatch: Colors.blue,
20 | ),
21 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
22 | );
23 | }
24 | }
25 |
26 | class MyHomePage extends StatefulWidget {
27 | const MyHomePage({super.key, required this.title});
28 |
29 | final String title;
30 |
31 | @override
32 | State createState() => _MyHomePageState();
33 | }
34 |
35 | class _MyHomePageState extends State {
36 | int _counter = 0;
37 | final _scaffoldKey = GlobalKey();
38 |
39 | void _incrementCounter() {
40 | setState(() {
41 | _counter++;
42 | });
43 | }
44 |
45 | @override
46 | Widget build(BuildContext context) {
47 | return Scaffold(
48 | key: _scaffoldKey,
49 | appBar: AppBar(
50 | title: Text(widget.title),
51 | ),
52 | drawer: Drawer(
53 | child: Column(
54 | children: [
55 | IconButton(
56 | onPressed: () => _scaffoldKey.currentState!.closeDrawer(),
57 | icon: Icon(Icons.close),
58 | ),
59 | TextButton(
60 | child: Text("Whitby"),
61 | onPressed: () {},
62 | ),
63 | TextButton(
64 | child: Text("Saltburn"),
65 | onPressed: () {},
66 | ),
67 | ],
68 | ),
69 | ),
70 | body: Center(
71 | child: Column(
72 | mainAxisAlignment: MainAxisAlignment.center,
73 | children: [
74 | const Text(
75 | 'You have pushed the button this many times:',
76 | ),
77 | Text(
78 | '$_counter',
79 | style: Theme.of(context).textTheme.headline4,
80 | ),
81 | ElevatedButton(
82 | child: Text('TextStyle'),
83 | onPressed: () {
84 | Navigator.of(context).push(
85 | MaterialPageRoute(builder: (context) {
86 | return DestinationWidgetTextStyle(
87 | name: "Whitby",
88 | description: "Whitby is a town in the North East of England where Dracula first arrived, taking the form of a dog.",
89 | );
90 | }),
91 | );
92 | },
93 | ),
94 | ElevatedButton(
95 | child: Text('Container decoration'),
96 | onPressed: () {
97 | Navigator.of(context).push(
98 | MaterialPageRoute(builder: (context) {
99 | return DestinationWidgetContainer(
100 | name: "Saltburn",
101 | description: "Saltburn-by-the-Sea, normally referred to as Saltburn, is the North East's best known location for surfing.",
102 | );
103 | }),
104 | );
105 | },
106 | ),
107 | ElevatedButton(
108 | onPressed: () => _scaffoldKey.currentState!.openDrawer(),
109 | child: Text("Open drawer"),
110 | ),
111 | ElevatedButton(
112 | onPressed: () {
113 | ScaffoldMessenger.of(context).showSnackBar(
114 | const SnackBar(
115 | content: Text('The parmo is a famous food of Teesside.'),
116 | ),
117 | );
118 | },
119 | child: const Text('Show SnackBar'),
120 | ),
121 | ElevatedButton(
122 | child: Text('List view'),
123 | onPressed: () {
124 | Navigator.of(context).push(
125 | MaterialPageRoute(builder: (context) {
126 | return DestinationListTile();
127 | }),
128 | );
129 | },
130 | ),
131 | ElevatedButton(
132 | child: Text('Sliver page'),
133 | onPressed: () {
134 | Navigator.of(context).push(
135 | MaterialPageRoute(builder: (context) {
136 | return SliverPage();
137 | }),
138 | );
139 | },
140 | ),
141 | ],
142 | ),
143 | ),
144 | floatingActionButton: FloatingActionButton(
145 | onPressed: _incrementCounter,
146 | tooltip: 'Increment',
147 | child: const Icon(Icons.add),
148 | ),
149 | );
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/lib/Chapter07/sliver_page.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class SliverPage extends StatelessWidget {
4 | const SliverPage({Key? key}) : super(key: key);
5 |
6 | @override
7 | Widget build(BuildContext context) {
8 | return Scaffold(
9 | body: CustomScrollView(
10 | slivers: [
11 | SliverAppBar(
12 | expandedHeight: 100.0,
13 | floating: true,
14 | title: Text("Sliver page"),
15 | flexibleSpace: FlexibleSpaceBar(
16 | title: Text('Flexible part'),
17 | ),
18 | actions: [
19 | IconButton(
20 | icon: Icon(Icons.delete),
21 | tooltip: 'Example button',
22 | onPressed: () {},
23 | ),
24 | ],
25 | ),
26 | SliverFixedExtentList(
27 | itemExtent: 100.0,
28 | delegate: SliverChildBuilderDelegate(
29 | (BuildContext context, int index) {
30 | return Container(
31 | color: index.isEven ? Colors.red : Colors.black,
32 | );
33 | },
34 | childCount: 8,
35 | ),
36 | ),
37 | SliverFillRemaining(
38 | child: Column(
39 | mainAxisAlignment: MainAxisAlignment.end,
40 | children: [
41 | TextButton(
42 | child: Text("Next"),
43 | onPressed: () {},
44 | ),
45 | ],
46 | ),
47 | ),
48 | ],
49 | ),
50 | );
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/lib/Chapter08/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return MaterialApp(
13 | title: 'Flutter Demo',
14 | theme: ThemeData(
15 | primarySwatch: Colors.blue,
16 | ),
17 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
18 | );
19 | }
20 | }
21 |
22 | class MyHomePage extends StatefulWidget {
23 | const MyHomePage({super.key, required this.title});
24 |
25 | final String title;
26 |
27 | @override
28 | State createState() => _MyHomePageState();
29 | }
30 |
31 | class _MyHomePageState extends State {
32 | int _counter = 0;
33 |
34 | void _incrementCounter() {
35 | setState(() {
36 | _counter++;
37 | });
38 | }
39 |
40 | @override
41 | Widget build(BuildContext context) {
42 | return Scaffold(
43 | appBar: AppBar(
44 | title: Text(widget.title),
45 | ),
46 | body: Center(
47 | child: Column(
48 | mainAxisAlignment: MainAxisAlignment.center,
49 | children: [
50 | const Text(
51 | 'You have pushed the button this many times:',
52 | ),
53 | Text(
54 | '$_counter',
55 | style: Theme.of(context).textTheme.headline4,
56 | ),
57 | ElevatedButton(
58 | child: Text('Press this'),
59 | onPressed: () {
60 | Navigator.of(context).push(
61 | MaterialPageRoute(builder: (context) {
62 | return DestinationDetails(title: "Whitby");
63 | }),
64 | );
65 | },
66 | ),
67 | ],
68 | ),
69 | ),
70 | floatingActionButton: FloatingActionButton(
71 | onPressed: _incrementCounter,
72 | tooltip: 'Increment',
73 | child: const Icon(Icons.add),
74 | ),
75 | );
76 | }
77 | }
78 |
79 | class DestinationDetails extends StatelessWidget {
80 | DestinationDetails({required this.title});
81 | final String title;
82 | @override
83 | Widget build(BuildContext context) {
84 | return Scaffold(
85 | appBar: AppBar(title: Text(title)),
86 | body: Center(
87 | child: ElevatedButton(
88 | child: Text("Back"),
89 | onPressed: () {
90 | Navigator.of(context).pop();
91 | },
92 | ),
93 | ),
94 | );
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/lib/Chapter08/main_named.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return MaterialApp(
13 | title: 'Flutter Demo',
14 | routes: {
15 | '/': (context) => MyHomePage(title: 'Flutter Demo Home Page'),
16 | '/destination': (context) => DestinationDetails(title: "Whitby"),
17 | },
18 | theme: ThemeData(
19 | primarySwatch: Colors.blue,
20 | ),
21 | );
22 | }
23 | }
24 |
25 | class MyHomePage extends StatefulWidget {
26 | const MyHomePage({super.key, required this.title});
27 |
28 | final String title;
29 |
30 | @override
31 | State createState() => _MyHomePageState();
32 | }
33 |
34 | class _MyHomePageState extends State {
35 | int _counter = 0;
36 |
37 | void _incrementCounter() {
38 | setState(() {
39 | _counter++;
40 | });
41 | }
42 |
43 | @override
44 | Widget build(BuildContext context) {
45 | return Scaffold(
46 | appBar: AppBar(
47 | title: Text(widget.title),
48 | ),
49 | body: Center(
50 | child: Column(
51 | mainAxisAlignment: MainAxisAlignment.center,
52 | children: [
53 | const Text(
54 | 'You have pushed the button this many times:',
55 | ),
56 | Text(
57 | '$_counter',
58 | style: Theme.of(context).textTheme.headline4,
59 | ),
60 | ElevatedButton(
61 | child: Text('Press this'),
62 | onPressed: () {
63 | Navigator.of(context).pushNamed("/destination");
64 | },
65 | ),
66 | ],
67 | ),
68 | ),
69 | floatingActionButton: FloatingActionButton(
70 | onPressed: _incrementCounter,
71 | tooltip: 'Increment',
72 | child: const Icon(Icons.add),
73 | ),
74 | );
75 | }
76 | }
77 |
78 | class DestinationDetails extends StatelessWidget {
79 | DestinationDetails({required this.title});
80 | final String title;
81 | @override
82 | Widget build(BuildContext context) {
83 | return Scaffold(
84 | appBar: AppBar(title: Text(title)),
85 | body: Center(
86 | child: ElevatedButton(
87 | child: Text("Back"),
88 | onPressed: () {
89 | Navigator.of(context).pop();
90 | },
91 | ),
92 | ),
93 | );
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/lib/Chapter08/main_named_arguments.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return MaterialApp(
13 | title: 'Flutter Demo',
14 | onGenerateRoute: (settings) {
15 | if (settings.name == '/') {
16 | return MaterialPageRoute(builder: (context) => MyHomePage(title: "Flutter Demo Home Page"));
17 | } else if (settings.name == '/destination') {
18 | return MaterialPageRoute(builder: (context) => DestinationDetails(title: settings.arguments as String));
19 | }
20 | },
21 | theme: ThemeData(
22 | primarySwatch: Colors.blue,
23 | ),
24 | );
25 | }
26 | }
27 |
28 | class MyHomePage extends StatefulWidget {
29 | const MyHomePage({super.key, required this.title});
30 |
31 | final String title;
32 |
33 | @override
34 | State createState() => _MyHomePageState();
35 | }
36 |
37 | class _MyHomePageState extends State {
38 | int _counter = 0;
39 |
40 | void _incrementCounter() {
41 | setState(() {
42 | _counter++;
43 | });
44 | }
45 |
46 | @override
47 | Widget build(BuildContext context) {
48 | return Scaffold(
49 | appBar: AppBar(
50 | title: Text(widget.title),
51 | ),
52 | body: Center(
53 | child: Column(
54 | mainAxisAlignment: MainAxisAlignment.center,
55 | children: [
56 | const Text(
57 | 'You have pushed the button this many times:',
58 | ),
59 | Text(
60 | '$_counter',
61 | style: Theme.of(context).textTheme.headline4,
62 | ),
63 | ElevatedButton(
64 | child: Text('Press this'),
65 | onPressed: () {
66 | Navigator.of(context).pushNamed('/destination', arguments: "Staithes");
67 | },
68 | ),
69 | ],
70 | ),
71 | ),
72 | floatingActionButton: FloatingActionButton(
73 | onPressed: _incrementCounter,
74 | tooltip: 'Increment',
75 | child: const Icon(Icons.add),
76 | ),
77 | );
78 | }
79 | }
80 |
81 | class DestinationDetails extends StatelessWidget {
82 | DestinationDetails({required this.title});
83 | final String title;
84 | @override
85 | Widget build(BuildContext context) {
86 | return Scaffold(
87 | appBar: AppBar(title: Text(title)),
88 | body: Center(
89 | child: ElevatedButton(
90 | child: Text("Back"),
91 | onPressed: () {
92 | Navigator.of(context).pop();
93 | },
94 | ),
95 | ),
96 | );
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/lib/Chapter08/main_navigator2.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatefulWidget {
8 | const MyApp({super.key});
9 | @override
10 | State createState() => _MyAppState();
11 | }
12 |
13 | class _MyAppState extends State {
14 | String? _selectedDestination;
15 |
16 | void _setDestination(String destination) {
17 | this.setState(() {
18 | _selectedDestination = destination;
19 | });
20 | }
21 |
22 | @override
23 | Widget build(BuildContext context) {
24 | return MaterialApp(
25 | title: 'Flutter Demo',
26 | home: Navigator(
27 | pages: [
28 | MaterialPage(
29 | child: MyHomePage(
30 | title: "Press this",
31 | destinationCallback: _setDestination,
32 | )),
33 | if (_selectedDestination != null)
34 | MaterialPage(
35 | child: DestinationDetails(title: _selectedDestination!),
36 | ),
37 | ],
38 | onPopPage: (route, result) {
39 | if (!route.didPop(result)) {
40 | return false;
41 | }
42 | setState(() {
43 | _selectedDestination = null;
44 | });
45 | return true;
46 | },
47 | ),
48 | );
49 | }
50 | }
51 |
52 | class MyHomePage extends StatefulWidget {
53 | MyHomePage({required this.title, required this.destinationCallback});
54 | final void Function(String) destinationCallback;
55 |
56 | final String title;
57 |
58 | @override
59 | State createState() => _MyHomePageState();
60 | }
61 |
62 | class _MyHomePageState extends State {
63 | @override
64 | Widget build(BuildContext context) {
65 | return Scaffold(
66 | appBar: AppBar(
67 | title: Text(widget.title),
68 | ),
69 | body: Center(
70 | child: Column(
71 | mainAxisAlignment: MainAxisAlignment.center,
72 | children: [
73 | ElevatedButton(
74 | child: Text('Whitby'),
75 | onPressed: () {
76 | widget.destinationCallback("Whitby");
77 | },
78 | ),
79 | ElevatedButton(
80 | child: Text('Scarborough'),
81 | onPressed: () async {
82 | widget.destinationCallback("Scarborough");
83 | },
84 | ),
85 | ],
86 | ),
87 | ),
88 | );
89 | }
90 | }
91 |
92 | class DestinationDetails extends StatelessWidget {
93 | DestinationDetails({required this.title});
94 | final String title;
95 | @override
96 | Widget build(BuildContext context) {
97 | return Scaffold(
98 | appBar: AppBar(title: Text(title)),
99 | body: Center(
100 | child: Column(
101 | mainAxisAlignment: MainAxisAlignment.center,
102 | children: [
103 | ElevatedButton(
104 | child: Text('Favorite'),
105 | onPressed: () {
106 | Navigator.of(context).pop(true);
107 | },
108 | ),
109 | ElevatedButton(
110 | child: Text("Close"),
111 | onPressed: () {
112 | Navigator.of(context).pop(false);
113 | },
114 | ),
115 | ],
116 | ),
117 | ),
118 | );
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/lib/Chapter08/main_result.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return MaterialApp(
13 | title: 'Flutter Demo',
14 | theme: ThemeData(
15 | primarySwatch: Colors.blue,
16 | ),
17 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
18 | );
19 | }
20 | }
21 |
22 | class MyHomePage extends StatefulWidget {
23 | const MyHomePage({super.key, required this.title});
24 |
25 | final String title;
26 |
27 | @override
28 | State createState() => _MyHomePageState();
29 | }
30 |
31 | class _MyHomePageState extends State {
32 | int _counter = 0;
33 |
34 | void _incrementCounter() {
35 | setState(() {
36 | _counter++;
37 | });
38 | }
39 |
40 | @override
41 | Widget build(BuildContext context) {
42 | return Scaffold(
43 | appBar: AppBar(
44 | title: Text(widget.title),
45 | ),
46 | body: Center(
47 | child: Column(
48 | mainAxisAlignment: MainAxisAlignment.center,
49 | children: [
50 | const Text(
51 | 'You have pushed the button this many times:',
52 | ),
53 | Text(
54 | '$_counter',
55 | style: Theme.of(context).textTheme.headline4,
56 | ),
57 | ElevatedButton(
58 | child: Text('Explore Whitby'),
59 | onPressed: () async {
60 | bool? outcome = await Navigator.of(context).push(
61 | MaterialPageRoute(builder: (context) {
62 | return DestinationDetails(title: "Whitby");
63 | }),
64 | );
65 | ScaffoldMessenger.of(context).showSnackBar(
66 | SnackBar(content: Text("Favorite: $outcome")),
67 | );
68 | },
69 | ),
70 | ],
71 | ),
72 | ),
73 | floatingActionButton: FloatingActionButton(
74 | onPressed: _incrementCounter,
75 | tooltip: 'Increment',
76 | child: const Icon(Icons.add),
77 | ),
78 | );
79 | }
80 | }
81 |
82 | class DestinationDetails extends StatelessWidget {
83 | DestinationDetails({required this.title});
84 | final String title;
85 | @override
86 | Widget build(BuildContext context) {
87 | return Scaffold(
88 | appBar: AppBar(title: Text(title)),
89 | body: Center(
90 | child: Column(
91 | mainAxisAlignment: MainAxisAlignment.center,
92 | children: [
93 | ElevatedButton(
94 | child: Text('Favorite'),
95 | onPressed: () {
96 | Navigator.of(context).pop(true);
97 | },
98 | ),
99 | ElevatedButton(
100 | child: Text("Close"),
101 | onPressed: () {
102 | Navigator.of(context).pop(false);
103 | },
104 | ),
105 | ],
106 | ),
107 | ),
108 | );
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/lib/Chapter08/main_transition.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return MaterialApp(
13 | title: 'Flutter Demo',
14 | theme: ThemeData(
15 | primarySwatch: Colors.blue,
16 | ),
17 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
18 | );
19 | }
20 | }
21 |
22 | class MyHomePage extends StatefulWidget {
23 | const MyHomePage({super.key, required this.title});
24 |
25 | final String title;
26 |
27 | @override
28 | State createState() => _MyHomePageState();
29 | }
30 |
31 | class _MyHomePageState extends State {
32 | int _counter = 0;
33 |
34 | void _incrementCounter() {
35 | setState(() {
36 | _counter++;
37 | });
38 | }
39 |
40 | @override
41 | Widget build(BuildContext context) {
42 | return Scaffold(
43 | appBar: AppBar(
44 | title: Text(widget.title),
45 | ),
46 | body: Center(
47 | child: Column(
48 | mainAxisAlignment: MainAxisAlignment.center,
49 | children: [
50 | const Text(
51 | 'You have pushed the button this many times:',
52 | ),
53 | Text(
54 | '$_counter',
55 | style: Theme.of(context).textTheme.headline4,
56 | ),
57 | ElevatedButton(
58 | child: Text('Explore Whitby'),
59 | onPressed: () async {
60 | Navigator.of(context).push(PageRouteBuilder(
61 | pageBuilder: (context, animation, secondaryAnimation) => DestinationDetails(title: "Whitby"),
62 | transitionsBuilder: (context, animation, secondaryAnimation, child) {
63 | return SlideTransition(
64 | position: Tween(
65 | begin: const Offset(-1, 0),
66 | end: Offset.zero,
67 | ).animate(animation),
68 | child: child,
69 | );
70 | },
71 | ));
72 | },
73 | ),
74 | ],
75 | ),
76 | ),
77 | floatingActionButton: FloatingActionButton(
78 | onPressed: _incrementCounter,
79 | tooltip: 'Increment',
80 | child: const Icon(Icons.add),
81 | ),
82 | );
83 | }
84 | }
85 |
86 | class DestinationDetails extends StatelessWidget {
87 | DestinationDetails({required this.title});
88 | final String title;
89 | @override
90 | Widget build(BuildContext context) {
91 | return Scaffold(
92 | appBar: AppBar(title: Text(title)),
93 | body: Center(
94 | child: ElevatedButton(
95 | child: Text("Back"),
96 | onPressed: () {
97 | Navigator.of(context).pop();
98 | },
99 | ),
100 | ),
101 | );
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/lib/Chapter08/main_transition_class.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | void main() {
4 | runApp(const MyApp());
5 | }
6 |
7 | class MyApp extends StatelessWidget {
8 | const MyApp({super.key});
9 |
10 | @override
11 | Widget build(BuildContext context) {
12 | return MaterialApp(
13 | title: 'Flutter Demo',
14 | theme: ThemeData(
15 | primarySwatch: Colors.blue,
16 | ),
17 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
18 | );
19 | }
20 | }
21 |
22 | class MyHomePage extends StatefulWidget {
23 | const MyHomePage({super.key, required this.title});
24 |
25 | final String title;
26 |
27 | @override
28 | State createState() => _MyHomePageState();
29 | }
30 |
31 | class _MyHomePageState extends State {
32 | int _counter = 0;
33 |
34 | void _incrementCounter() {
35 | setState(() {
36 | _counter++;
37 | });
38 | }
39 |
40 | @override
41 | Widget build(BuildContext context) {
42 | return Scaffold(
43 | appBar: AppBar(
44 | title: Text(widget.title),
45 | ),
46 | body: Center(
47 | child: Column(
48 | mainAxisAlignment: MainAxisAlignment.center,
49 | children: [
50 | const Text(
51 | 'You have pushed the button this many times:',
52 | ),
53 | Text(
54 | '$_counter',
55 | style: Theme.of(context).textTheme.headline4,
56 | ),
57 | ElevatedButton(
58 | child: Text('Explore Whitby'),
59 | onPressed: () async {
60 | Navigator.of(context).push(
61 | MySlideTransition(
62 | transitionPage: DestinationDetails(title: "Whitby"),
63 | ),
64 | );
65 | },
66 | ),
67 | ],
68 | ),
69 | ),
70 | floatingActionButton: FloatingActionButton(
71 | onPressed: _incrementCounter,
72 | tooltip: 'Increment',
73 | child: const Icon(Icons.add),
74 | ),
75 | );
76 | }
77 | }
78 |
79 | class DestinationDetails extends StatelessWidget {
80 | DestinationDetails({required this.title});
81 | final String title;
82 | @override
83 | Widget build(BuildContext context) {
84 | return Scaffold(
85 | appBar: AppBar(title: Text(title)),
86 | body: Center(
87 | child: ElevatedButton(
88 | child: Text("Back"),
89 | onPressed: () {
90 | Navigator.of(context).pop();
91 | },
92 | ),
93 | ),
94 | );
95 | }
96 | }
97 |
98 | class MySlideTransition extends PageRouteBuilder {
99 | final Widget transitionPage;
100 | MySlideTransition({required this.transitionPage})
101 | : super(
102 | pageBuilder: (
103 | BuildContext context,
104 | Animation animation,
105 | Animation secondaryAnimation,
106 | ) =>
107 | transitionPage,
108 | transitionsBuilder: (
109 | BuildContext context,
110 | Animation animation,
111 | Animation secondaryAnimation,
112 | Widget child,
113 | ) =>
114 | SlideTransition(
115 | position: Tween(
116 | begin: const Offset(-1, 0),
117 | end: Offset.zero,
118 | ).animate(animation),
119 | child: child,
120 | ),
121 | );
122 | }
123 |
--------------------------------------------------------------------------------
/lib/Chapter09/destination_description.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:auto_size_text/auto_size_text.dart';
3 |
4 | class DestinationDescriptionWidget extends StatelessWidget {
5 | final String description;
6 |
7 | DestinationDescriptionWidget({required this.description});
8 |
9 | @override
10 | Widget build(BuildContext context) {
11 | return AutoSizeText(
12 | description,
13 | style: TextStyle(color: Colors.red),
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/lib/Chapter09/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hello_world/Chapter09/destination_description.dart';
3 |
4 | void main() {
5 | runApp(const MyApp());
6 | }
7 |
8 | class MyApp extends StatelessWidget {
9 | const MyApp({super.key});
10 |
11 | // This widget is the root of your application.
12 | @override
13 | Widget build(BuildContext context) {
14 | return MaterialApp(
15 | title: 'Flutter Demo',
16 | theme: ThemeData(
17 | // This is the theme of your application.
18 | //
19 | // Try running your application with "flutter run". You'll see the
20 | // application has a blue toolbar. Then, without quitting the app, try
21 | // changing the primarySwatch below to Colors.green and then invoke
22 | // "hot reload" (press "r" in the console where you ran "flutter run",
23 | // or simply save your changes to "hot reload" in a Flutter IDE).
24 | // Notice that the counter didn't reset back to zero; the application
25 | // is not restarted.
26 | primarySwatch: Colors.blue,
27 | ),
28 | home: const MyHomePage(title: 'Flutter Demo Home Page'),
29 | );
30 | }
31 | }
32 |
33 | class MyHomePage extends StatefulWidget {
34 | const MyHomePage({super.key, required this.title});
35 |
36 | // This widget is the home page of your application. It is stateful, meaning
37 | // that it has a State object (defined below) that contains fields that affect
38 | // how it looks.
39 |
40 | // This class is the configuration for the state. It holds the values (in this
41 | // case the title) provided by the parent (in this case the App widget) and
42 | // used by the build method of the State. Fields in a Widget subclass are
43 | // always marked "final".
44 |
45 | final String title;
46 |
47 | @override
48 | State createState() => _MyHomePageState();
49 | }
50 |
51 | class _MyHomePageState extends State {
52 | int _counter = 0;
53 |
54 | void _incrementCounter() {
55 | setState(() {
56 | // This call to setState tells the Flutter framework that something has
57 | // changed in this State, which causes it to rerun the build method below
58 | // so that the display can reflect the updated values. If we changed
59 | // _counter without calling setState(), then the build method would not be
60 | // called again, and so nothing would appear to happen.
61 | _counter++;
62 | });
63 | }
64 |
65 | @override
66 | Widget build(BuildContext context) {
67 | // This method is rerun every time setState is called, for instance as done
68 | // by the _incrementCounter method above.
69 | //
70 | // The Flutter framework has been optimized to make rerunning build methods
71 | // fast, so that you can just rebuild anything that needs updating rather
72 | // than having to individually change instances of widgets.
73 | return Scaffold(
74 | appBar: AppBar(
75 | // Here we take the value from the MyHomePage object that was created by
76 | // the App.build method, and use it to set our appbar title.
77 | title: Text(widget.title),
78 | ),
79 | body: Center(
80 | // Center is a layout widget. It takes a single child and positions it
81 | // in the middle of the parent.
82 | child: Column(
83 | // Column is also a layout widget. It takes a list of children and
84 | // arranges them vertically. By default, it sizes itself to fit its
85 | // children horizontally, and tries to be as tall as its parent.
86 | //
87 | // Invoke "debug painting" (press "p" in the console, choose the
88 | // "Toggle Debug Paint" action from the Flutter Inspector in Android
89 | // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
90 | // to see the wireframe for each widget.
91 | //
92 | // Column has various properties to control how it sizes itself and
93 | // how it positions its children. Here we use mainAxisAlignment to
94 | // center the children vertically; the main axis here is the vertical
95 | // axis because Columns are vertical (the cross axis would be
96 | // horizontal).
97 | mainAxisAlignment: MainAxisAlignment.center,
98 | children: [
99 | const Text(
100 | 'You have pushed the button this many times:',
101 | ),
102 | Text(
103 | '$_counter',
104 | style: Theme.of(context).textTheme.headline4,
105 | ),
106 | ElevatedButton(
107 | child: Text('Press this'),
108 | onPressed: () {
109 | Navigator.of(context).push(
110 | MaterialPageRoute(builder: (context) {
111 | return DestinationDetails(title: "Whitby");
112 | }),
113 | );
114 | },
115 | ),
116 | ],
117 | ),
118 | ),
119 | floatingActionButton: FloatingActionButton(
120 | onPressed: _incrementCounter,
121 | tooltip: 'Increment',
122 | child: const Icon(Icons.add),
123 | ), // This trailing comma makes auto-formatting nicer for build methods.
124 | );
125 | }
126 | }
127 |
128 | class DestinationDetails extends StatelessWidget {
129 | DestinationDetails({required this.title});
130 | final String title;
131 | @override
132 | Widget build(BuildContext context) {
133 | return Scaffold(
134 | appBar: AppBar(title: Text(title)),
135 | body: Column(
136 | crossAxisAlignment: CrossAxisAlignment.center,
137 | children: [
138 | DestinationDescriptionWidget(
139 | description: "Whitby is a town in the North East of England where Dracula first arrived, taking the form of a dog.",
140 | ),
141 | ElevatedButton(
142 | child: Text("Back"),
143 | onPressed: () {
144 | Navigator.of(context).pop();
145 | },
146 | ),
147 | ],
148 | ),
149 | );
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/lib/Chapter11/animated_builder.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math' as math;
3 |
4 | class RotationBuilderAnimations extends StatefulWidget {
5 | RotationBuilderAnimations({Key? key}) : super(key: key);
6 |
7 | @override
8 | State createState() => _RotationBuilderAnimationsState();
9 | }
10 |
11 | class _RotationBuilderAnimationsState extends State with SingleTickerProviderStateMixin {
12 | late AnimationController _controller;
13 | late Animation _animation;
14 |
15 | @override
16 | void initState() {
17 | super.initState();
18 | final (localController, localAnimation) = _createBounceInRotationAnimation();
19 | _controller = localController;
20 | _animation = localAnimation;
21 | }
22 |
23 | (AnimationController, Animation) _createBounceInRotationAnimation() {
24 | final controller = AnimationController(
25 | vsync: this,
26 | debugLabel: "animations demo",
27 | duration: Duration(seconds: 3),
28 | );
29 | final animation = controller.drive(CurveTween(
30 | curve: Curves.bounceIn,
31 | ));
32 | return (controller, animation);
33 | }
34 |
35 | @override
36 | Widget build(BuildContext context) {
37 | return Center(
38 | child: AnimatedBuilder(
39 | animation: _animation,
40 | child: ElevatedButton(
41 | child: Text("Rotated button"),
42 | onPressed: () {
43 | print("Rotating");
44 | print("${_animation.status}");
45 | if (_animation.isCompleted || _animation.isDismissed) {
46 | _controller.reset();
47 | _controller.forward();
48 | }
49 | },
50 | ),
51 | builder: (context, child) {
52 | print("Building");
53 | return Transform.rotate(
54 | angle: _animation.value * 2.0 * math.pi,
55 | child: child,
56 | );
57 | },
58 | ),
59 | );
60 | }
61 |
62 | @override
63 | void dispose() {
64 | _controller.dispose();
65 | super.dispose();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/lib/Chapter11/composed_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math' as math;
3 |
4 | class ComposedButton extends StatelessWidget {
5 | const ComposedButton({Key? key}) : super(key: key);
6 |
7 | @override
8 | Widget build(BuildContext context) {
9 | return Scaffold(
10 | appBar: AppBar(title: Text("Composed button example")),
11 | body: Center(
12 | child: Column(
13 | mainAxisAlignment: MainAxisAlignment.start,
14 | children: [
15 | ElevatedButton(
16 | child: Text("Original button"),
17 | onPressed: () {},
18 | ),
19 | Transform.translate(
20 | offset: Offset(70, 200),
21 | child: Transform.rotate(
22 | angle: -45 * (math.pi / 180.0),
23 | child: Transform.scale(
24 | scale: 2.0,
25 | child: ElevatedButton(
26 | child: Text("multiple transformations"),
27 | onPressed: () {},
28 | ),
29 | ),
30 | ),
31 | ),
32 | ],
33 | ),
34 | ),
35 | );
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/lib/Chapter11/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:hello_world/Chapter11/animated_builder.dart';
3 | import 'package:hello_world/Chapter11/rotation_bouncein_button.dart';
4 | import 'package:hello_world/Chapter11/rotation_button.dart';
5 | import 'package:hello_world/Chapter11/composed_button.dart';
6 | import 'package:hello_world/Chapter11/rotated_button.dart';
7 | import 'package:hello_world/Chapter11/scaled_button.dart';
8 | import 'package:hello_world/Chapter11/translated_button.dart';
9 |
10 | void main() {
11 | runApp(const MyApp());
12 | }
13 |
14 | class MyApp extends StatelessWidget {
15 | const MyApp({super.key});
16 |
17 | @override
18 | Widget build(BuildContext context) {
19 | return MaterialApp(
20 | title: 'Flutter Animations',
21 | theme: ThemeData(
22 | primarySwatch: Colors.blue,
23 | ),
24 | home: const MyHomePage(title: 'Flutter Animations'),
25 | );
26 | }
27 | }
28 |
29 | class MyHomePage extends StatefulWidget {
30 | const MyHomePage({super.key, required this.title});
31 |
32 | final String title;
33 |
34 | @override
35 | State createState() => _MyHomePageState();
36 | }
37 |
38 | class _MyHomePageState extends State {
39 | @override
40 | Widget build(BuildContext context) {
41 | return Scaffold(
42 | appBar: AppBar(
43 | title: Text(widget.title),
44 | ),
45 | body: Center(
46 | child: Column(
47 | mainAxisAlignment: MainAxisAlignment.center,
48 | children: [
49 | ElevatedButton(
50 | child: Text('Rotated button'),
51 | onPressed: () {
52 | Navigator.of(context).push(
53 | MaterialPageRoute(builder: (context) {
54 | return RotatedButton();
55 | }),
56 | );
57 | },
58 | ),
59 | ElevatedButton(
60 | child: Text('Scaled button'),
61 | onPressed: () {
62 | Navigator.of(context).push(
63 | MaterialPageRoute(builder: (context) {
64 | return ScaledButton();
65 | }),
66 | );
67 | },
68 | ),
69 | ElevatedButton(
70 | child: Text('Translated button'),
71 | onPressed: () {
72 | Navigator.of(context).push(
73 | MaterialPageRoute(builder: (context) {
74 | return TranslatedButton();
75 | }),
76 | );
77 | },
78 | ),
79 | ElevatedButton(
80 | child: Text('Composed button'),
81 | onPressed: () {
82 | Navigator.of(context).push(
83 | MaterialPageRoute(builder: (context) {
84 | return ComposedButton();
85 | }),
86 | );
87 | },
88 | ),
89 | ElevatedButton(
90 | child: Text('Animation button'),
91 | onPressed: () {
92 | Navigator.of(context).push(
93 | MaterialPageRoute(builder: (context) {
94 | return Scaffold(appBar: AppBar(), body: RotationAnimations());
95 | }),
96 | );
97 | },
98 | ),
99 | ElevatedButton(
100 | child: Text('Animation bounce-in button'),
101 | onPressed: () {
102 | Navigator.of(context).push(
103 | MaterialPageRoute(builder: (context) {
104 | return Scaffold(appBar: AppBar(), body: RotationBounceInAnimations());
105 | }),
106 | );
107 | },
108 | ),
109 | ElevatedButton(
110 | child: Text('Animation builder'),
111 | onPressed: () {
112 | Navigator.of(context).push(
113 | MaterialPageRoute(builder: (context) {
114 | return Scaffold(appBar: AppBar(), body: RotationBuilderAnimations());
115 | }),
116 | );
117 | },
118 | ),
119 | ],
120 | ),
121 | ),
122 | );
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/lib/Chapter11/rotated_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math' as math;
3 |
4 | class RotatedButton extends StatelessWidget {
5 | const RotatedButton({Key? key}) : super(key: key);
6 |
7 | @override
8 | Widget build(BuildContext context) {
9 | return Scaffold(
10 | appBar: AppBar(title: Text("Rotated button example")),
11 | body: Center(
12 | child: Transform.rotate(
13 | angle: -45 * (math.pi / 180.0),
14 | child: ElevatedButton(
15 | child: Text("Rotated button"),
16 | onPressed: () {},
17 | ),
18 | ),
19 | ),
20 | );
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/lib/Chapter11/rotation_bouncein_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math' as math;
3 |
4 | class RotationBounceInAnimations extends StatefulWidget {
5 | RotationBounceInAnimations({Key? key}) : super(key: key);
6 |
7 | @override
8 | State createState() => _RotationBounceInAnimationsState();
9 | }
10 |
11 | class _RotationBounceInAnimationsState extends State with SingleTickerProviderStateMixin {
12 | double _angle = 0.0;
13 | late AnimationController _controller;
14 |
15 | @override
16 | void initState() {
17 | super.initState();
18 | _controller = _createBounceInRotationAnimation();
19 | _controller.forward();
20 | }
21 |
22 | AnimationController _createBounceInRotationAnimation() {
23 | var controller = AnimationController(
24 | vsync: this,
25 | debugLabel: "animations demo",
26 | duration: Duration(seconds: 3),
27 | );
28 | var animation = controller.drive(CurveTween(
29 | curve: Curves.bounceIn,
30 | ));
31 | animation.addListener(() {
32 | setState(() {
33 | _angle = (animation.value * 360.0) * (math.pi / 180);
34 | });
35 | });
36 | return controller;
37 | }
38 |
39 | @override
40 | Widget build(BuildContext context) {
41 | return Center(child: _rotationAnimationButton());
42 | }
43 |
44 | _rotationAnimationButton() {
45 | return Transform.rotate(
46 | angle: _angle,
47 | child: ElevatedButton(
48 | child: Text("Rotated button"),
49 | onPressed: () {
50 | if (_controller.status == AnimationStatus.completed) {
51 | _controller.reset();
52 | _controller.forward();
53 | }
54 | },
55 | ),
56 | );
57 | }
58 |
59 | @override
60 | void dispose() {
61 | _controller.dispose();
62 | super.dispose();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/lib/Chapter11/rotation_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math' as math;
3 |
4 | class RotationAnimations extends StatefulWidget {
5 | RotationAnimations({Key? key}) : super(key: key);
6 |
7 | @override
8 | State createState() => _RotationAnimationsState();
9 | }
10 |
11 | class _RotationAnimationsState extends State with SingleTickerProviderStateMixin {
12 | double _angle = 0.0;
13 | late AnimationController _controller;
14 |
15 | @override
16 | void initState() {
17 | super.initState();
18 | _controller = _createRotationAnimation();
19 | _controller.forward();
20 | }
21 |
22 | AnimationController _createRotationAnimation() {
23 | var controller = AnimationController(
24 | vsync: this,
25 | debugLabel: "animations demo",
26 | duration: Duration(seconds: 3),
27 | );
28 | controller.addListener(() {
29 | setState(() {
30 | _angle = (controller.value * 360.0) * (math.pi / 180);
31 | });
32 | });
33 | return controller;
34 | }
35 |
36 | @override
37 | Widget build(BuildContext context) {
38 | return Center(child: _rotationAnimationButton());
39 | }
40 |
41 | _rotationAnimationButton() {
42 | return Transform.rotate(
43 | angle: _angle,
44 | child: ElevatedButton(
45 | child: Text("Rotated button"),
46 | onPressed: () {
47 | if (_controller.status == AnimationStatus.completed) {
48 | _controller.reset();
49 | _controller.forward();
50 | }
51 | },
52 | ),
53 | );
54 | }
55 |
56 | @override
57 | void dispose() {
58 | _controller.dispose();
59 | super.dispose();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/lib/Chapter11/scale_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'dart:math' as math;
3 |
4 | class RotationAnimations extends StatefulWidget {
5 | RotationAnimations({Key? key}) : super(key: key);
6 |
7 | @override
8 | State createState() => _RotationAnimationsState();
9 | }
10 |
11 | class _RotationAnimationsState extends State with SingleTickerProviderStateMixin {
12 | double _angle = 0.0;
13 | late AnimationController _controller;
14 |
15 | @override
16 | void initState() {
17 | super.initState();
18 | _controller = _createRotationAnimation();
19 | _controller.forward();
20 | }
21 |
22 | AnimationController _createRotationAnimation() {
23 | var controller = AnimationController(
24 | vsync: this,
25 | debugLabel: "animations demo",
26 | duration: Duration(seconds: 3),
27 | );
28 | controller.addListener(() {
29 | setState(() {
30 | _angle = (controller.value * 360.0) * (math.pi / 180);
31 | });
32 | });
33 | return controller;
34 | }
35 |
36 | @override
37 | Widget build(BuildContext context) {
38 | return Center(child: _rotationAnimationButton());
39 | }
40 |
41 | _rotationAnimationButton() {
42 | return Transform.rotate(
43 | angle: _angle,
44 | child: ElevatedButton(
45 | child: Text("Rotated button"),
46 | onPressed: () {
47 | if (_controller.status == AnimationStatus.completed) {
48 | _controller.reset();
49 | _controller.forward();
50 | }
51 | },
52 | ),
53 | );
54 | }
55 |
56 | @override
57 | void dispose() {
58 | _controller.dispose();
59 | super.dispose();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/lib/Chapter11/scaled_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class ScaledButton extends StatelessWidget {
4 | const ScaledButton({Key? key}) : super(key: key);
5 |
6 | @override
7 | Widget build(BuildContext context) {
8 | return Scaffold(
9 | appBar: AppBar(title: Text("Scaled button example")),
10 | body: Center(
11 | child: Column(
12 | mainAxisAlignment: MainAxisAlignment.center,
13 | children: [
14 | ElevatedButton(
15 | child: Text("Original button"),
16 | onPressed: () {},
17 | ),
18 | Padding(padding: EdgeInsets.only(bottom: 20)),
19 | Transform.scale(
20 | scale: 2.0,
21 | child: ElevatedButton(
22 | child: Text("Scaled button"),
23 | onPressed: () {},
24 | ),
25 | ),
26 | ],
27 | ),
28 | ),
29 | );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib/Chapter11/translated_button.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 |
3 | class TranslatedButton extends StatelessWidget {
4 | const TranslatedButton({Key? key}) : super(key: key);
5 |
6 | @override
7 | Widget build(BuildContext context) {
8 | return Scaffold(
9 | appBar: AppBar(title: Text("Translated button example")),
10 | body: Center(
11 | child: Column(
12 | mainAxisAlignment: MainAxisAlignment.center,
13 | children: [
14 | ElevatedButton(
15 | child: Text("Original button"),
16 | onPressed: () {},
17 | ),
18 | Padding(padding: EdgeInsets.only(bottom: 20)),
19 | Transform.translate(
20 | offset: Offset(30, 30),
21 | child: ElevatedButton(
22 | child: Text("translated button"),
23 | onPressed: () {},
24 | ),
25 | ),
26 | ],
27 | ),
28 | ),
29 | );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib/Chapter12/calculator.dart:
--------------------------------------------------------------------------------
1 | class Calculator {
2 | num sumTwoNumbers(num a, num b) {
3 | return a + b;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/lib/Chapter12/calculator_fail.dart:
--------------------------------------------------------------------------------
1 | class Calculator {
2 | num sumTwoNumbers(num a, num b) {
3 | return 0; // TODO
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/linux/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral
2 |
--------------------------------------------------------------------------------
/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.10)
3 | project(runner LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "hello_world")
8 | # The unique GTK application identifier for this application. See:
9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID
10 | set(APPLICATION_ID "com.example.hello_world")
11 |
12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
13 | # versions of CMake.
14 | cmake_policy(SET CMP0063 NEW)
15 |
16 | # Load bundled libraries from the lib/ directory relative to the binary.
17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
18 |
19 | # Root filesystem for cross-building.
20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT)
21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27 | endif()
28 |
29 | # Define build configuration options.
30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
31 | set(CMAKE_BUILD_TYPE "Debug" CACHE
32 | STRING "Flutter build mode" FORCE)
33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
34 | "Debug" "Profile" "Release")
35 | endif()
36 |
37 | # Compilation settings that should be applied to most targets.
38 | #
39 | # Be cautious about adding new options here, as plugins use this function by
40 | # default. In most cases, you should add new options to specific targets instead
41 | # of modifying this function.
42 | function(APPLY_STANDARD_SETTINGS TARGET)
43 | target_compile_features(${TARGET} PUBLIC cxx_std_14)
44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror)
45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
47 | endfunction()
48 |
49 | # Flutter library and tool build rules.
50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
51 | add_subdirectory(${FLUTTER_MANAGED_DIR})
52 |
53 | # System-level dependencies.
54 | find_package(PkgConfig REQUIRED)
55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
56 |
57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
58 |
59 | # Define the application target. To change its name, change BINARY_NAME above,
60 | # not the value here, or `flutter run` will no longer work.
61 | #
62 | # Any new source files that you add to the application should be added here.
63 | add_executable(${BINARY_NAME}
64 | "main.cc"
65 | "my_application.cc"
66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
67 | )
68 |
69 | # Apply the standard set of build settings. This can be removed for applications
70 | # that need different build settings.
71 | apply_standard_settings(${BINARY_NAME})
72 |
73 | # Add dependency libraries. Add any application-specific dependencies here.
74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter)
75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
76 |
77 | # Run the Flutter tool portions of the build. This must not be removed.
78 | add_dependencies(${BINARY_NAME} flutter_assemble)
79 |
80 | # Only the install-generated bundle's copy of the executable will launch
81 | # correctly, since the resources must in the right relative locations. To avoid
82 | # people trying to run the unbundled copy, put it in a subdirectory instead of
83 | # the default top-level location.
84 | set_target_properties(${BINARY_NAME}
85 | PROPERTIES
86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
87 | )
88 |
89 | # Generated plugin build rules, which manage building the plugins and adding
90 | # them to the application.
91 | include(flutter/generated_plugins.cmake)
92 |
93 |
94 | # === Installation ===
95 | # By default, "installing" just makes a relocatable bundle in the build
96 | # directory.
97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
100 | endif()
101 |
102 | # Start with a clean build bundle directory every time.
103 | install(CODE "
104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
105 | " COMPONENT Runtime)
106 |
107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
109 |
110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
111 | COMPONENT Runtime)
112 |
113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
114 | COMPONENT Runtime)
115 |
116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
117 | COMPONENT Runtime)
118 |
119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
120 | install(FILES "${bundled_library}"
121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
122 | COMPONENT Runtime)
123 | endforeach(bundled_library)
124 |
125 | # Fully re-copy the assets directory on each build to avoid having stale files
126 | # from a previous install.
127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
128 | install(CODE "
129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
130 | " COMPONENT Runtime)
131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
133 |
134 | # Install the AOT library on non-Debug builds only.
135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
137 | COMPONENT Runtime)
138 | endif()
139 |
--------------------------------------------------------------------------------
/linux/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.10)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 |
12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
13 | # which isn't available in 3.10.
14 | function(list_prepend LIST_NAME PREFIX)
15 | set(NEW_LIST "")
16 | foreach(element ${${LIST_NAME}})
17 | list(APPEND NEW_LIST "${PREFIX}${element}")
18 | endforeach(element)
19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
20 | endfunction()
21 |
22 | # === Flutter Library ===
23 | # System-level dependencies.
24 | find_package(PkgConfig REQUIRED)
25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
28 |
29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
30 |
31 | # Published to parent scope for install step.
32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
36 |
37 | list(APPEND FLUTTER_LIBRARY_HEADERS
38 | "fl_basic_message_channel.h"
39 | "fl_binary_codec.h"
40 | "fl_binary_messenger.h"
41 | "fl_dart_project.h"
42 | "fl_engine.h"
43 | "fl_json_message_codec.h"
44 | "fl_json_method_codec.h"
45 | "fl_message_codec.h"
46 | "fl_method_call.h"
47 | "fl_method_channel.h"
48 | "fl_method_codec.h"
49 | "fl_method_response.h"
50 | "fl_plugin_registrar.h"
51 | "fl_plugin_registry.h"
52 | "fl_standard_message_codec.h"
53 | "fl_standard_method_codec.h"
54 | "fl_string_codec.h"
55 | "fl_value.h"
56 | "fl_view.h"
57 | "flutter_linux.h"
58 | )
59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
60 | add_library(flutter INTERFACE)
61 | target_include_directories(flutter INTERFACE
62 | "${EPHEMERAL_DIR}"
63 | )
64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
65 | target_link_libraries(flutter INTERFACE
66 | PkgConfig::GTK
67 | PkgConfig::GLIB
68 | PkgConfig::GIO
69 | )
70 | add_dependencies(flutter flutter_assemble)
71 |
72 | # === Flutter tool backend ===
73 | # _phony_ is a non-existent file to force this command to run every time,
74 | # since currently there's no way to get a full input/output list from the
75 | # flutter tool.
76 | add_custom_command(
77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_
79 | COMMAND ${CMAKE_COMMAND} -E env
80 | ${FLUTTER_TOOL_ENVIRONMENT}
81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
83 | VERBATIM
84 | )
85 | add_custom_target(flutter_assemble DEPENDS
86 | "${FLUTTER_LIBRARY}"
87 | ${FLUTTER_LIBRARY_HEADERS}
88 | )
89 |
--------------------------------------------------------------------------------
/linux/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 |
10 | void fl_register_plugins(FlPluginRegistry* registry) {
11 | }
12 |
--------------------------------------------------------------------------------
/linux/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void fl_register_plugins(FlPluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/linux/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
9 | )
10 |
11 | set(PLUGIN_BUNDLED_LIBRARIES)
12 |
13 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
18 | endforeach(plugin)
19 |
20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23 | endforeach(ffi_plugin)
24 |
--------------------------------------------------------------------------------
/linux/main.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | int main(int argc, char** argv) {
4 | g_autoptr(MyApplication) app = my_application_new();
5 | return g_application_run(G_APPLICATION(app), argc, argv);
6 | }
7 |
--------------------------------------------------------------------------------
/linux/my_application.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | #include
4 | #ifdef GDK_WINDOWING_X11
5 | #include
6 | #endif
7 |
8 | #include "flutter/generated_plugin_registrant.h"
9 |
10 | struct _MyApplication {
11 | GtkApplication parent_instance;
12 | char** dart_entrypoint_arguments;
13 | };
14 |
15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
16 |
17 | // Implements GApplication::activate.
18 | static void my_application_activate(GApplication* application) {
19 | MyApplication* self = MY_APPLICATION(application);
20 | GtkWindow* window =
21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22 |
23 | // Use a header bar when running in GNOME as this is the common style used
24 | // by applications and is the setup most users will be using (e.g. Ubuntu
25 | // desktop).
26 | // If running on X and not using GNOME then just use a traditional title bar
27 | // in case the window manager does more exotic layout, e.g. tiling.
28 | // If running on Wayland assume the header bar will work (may need changing
29 | // if future cases occur).
30 | gboolean use_header_bar = TRUE;
31 | #ifdef GDK_WINDOWING_X11
32 | GdkScreen* screen = gtk_window_get_screen(window);
33 | if (GDK_IS_X11_SCREEN(screen)) {
34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36 | use_header_bar = FALSE;
37 | }
38 | }
39 | #endif
40 | if (use_header_bar) {
41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42 | gtk_widget_show(GTK_WIDGET(header_bar));
43 | gtk_header_bar_set_title(header_bar, "hello_world");
44 | gtk_header_bar_set_show_close_button(header_bar, TRUE);
45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46 | } else {
47 | gtk_window_set_title(window, "hello_world");
48 | }
49 |
50 | gtk_window_set_default_size(window, 1280, 720);
51 | gtk_widget_show(GTK_WIDGET(window));
52 |
53 | g_autoptr(FlDartProject) project = fl_dart_project_new();
54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
55 |
56 | FlView* view = fl_view_new(project);
57 | gtk_widget_show(GTK_WIDGET(view));
58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
59 |
60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view));
61 |
62 | gtk_widget_grab_focus(GTK_WIDGET(view));
63 | }
64 |
65 | // Implements GApplication::local_command_line.
66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
67 | MyApplication* self = MY_APPLICATION(application);
68 | // Strip out the first argument as it is the binary name.
69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
70 |
71 | g_autoptr(GError) error = nullptr;
72 | if (!g_application_register(application, nullptr, &error)) {
73 | g_warning("Failed to register: %s", error->message);
74 | *exit_status = 1;
75 | return TRUE;
76 | }
77 |
78 | g_application_activate(application);
79 | *exit_status = 0;
80 |
81 | return TRUE;
82 | }
83 |
84 | // Implements GObject::dispose.
85 | static void my_application_dispose(GObject* object) {
86 | MyApplication* self = MY_APPLICATION(object);
87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
89 | }
90 |
91 | static void my_application_class_init(MyApplicationClass* klass) {
92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate;
93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
95 | }
96 |
97 | static void my_application_init(MyApplication* self) {}
98 |
99 | MyApplication* my_application_new() {
100 | return MY_APPLICATION(g_object_new(my_application_get_type(),
101 | "application-id", APPLICATION_ID,
102 | "flags", G_APPLICATION_NON_UNIQUE,
103 | nullptr));
104 | }
105 |
--------------------------------------------------------------------------------
/linux/my_application.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_MY_APPLICATION_H_
2 | #define FLUTTER_MY_APPLICATION_H_
3 |
4 | #include
5 |
6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7 | GtkApplication)
8 |
9 | /**
10 | * my_application_new:
11 | *
12 | * Creates a new Flutter-based application.
13 | *
14 | * Returns: a new #MyApplication.
15 | */
16 | MyApplication* my_application_new();
17 |
18 | #endif // FLUTTER_MY_APPLICATION_H_
19 |
--------------------------------------------------------------------------------
/macos/.gitignore:
--------------------------------------------------------------------------------
1 | # Flutter-related
2 | **/Flutter/ephemeral/
3 | **/Pods/
4 |
5 | # Xcode-related
6 | **/dgph
7 | **/xcuserdata/
8 |
--------------------------------------------------------------------------------
/macos/Flutter/Flutter-Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/macos/Flutter/Flutter-Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/macos/Flutter/GeneratedPluginRegistrant.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | import FlutterMacOS
6 | import Foundation
7 |
8 |
9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
10 | }
11 |
--------------------------------------------------------------------------------
/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/macos/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/macos/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | @NSApplicationMain
5 | class AppDelegate: FlutterAppDelegate {
6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
7 | return true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "16x16",
5 | "idiom" : "mac",
6 | "filename" : "app_icon_16.png",
7 | "scale" : "1x"
8 | },
9 | {
10 | "size" : "16x16",
11 | "idiom" : "mac",
12 | "filename" : "app_icon_32.png",
13 | "scale" : "2x"
14 | },
15 | {
16 | "size" : "32x32",
17 | "idiom" : "mac",
18 | "filename" : "app_icon_32.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "32x32",
23 | "idiom" : "mac",
24 | "filename" : "app_icon_64.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "128x128",
29 | "idiom" : "mac",
30 | "filename" : "app_icon_128.png",
31 | "scale" : "1x"
32 | },
33 | {
34 | "size" : "128x128",
35 | "idiom" : "mac",
36 | "filename" : "app_icon_256.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "256x256",
41 | "idiom" : "mac",
42 | "filename" : "app_icon_256.png",
43 | "scale" : "1x"
44 | },
45 | {
46 | "size" : "256x256",
47 | "idiom" : "mac",
48 | "filename" : "app_icon_512.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "512x512",
53 | "idiom" : "mac",
54 | "filename" : "app_icon_512.png",
55 | "scale" : "1x"
56 | },
57 | {
58 | "size" : "512x512",
59 | "idiom" : "mac",
60 | "filename" : "app_icon_1024.png",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
--------------------------------------------------------------------------------
/macos/Runner/Configs/AppInfo.xcconfig:
--------------------------------------------------------------------------------
1 | // Application-level settings for the Runner target.
2 | //
3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the
4 | // future. If not, the values below would default to using the project name when this becomes a
5 | // 'flutter create' template.
6 |
7 | // The application's name. By default this is also the title of the Flutter window.
8 | PRODUCT_NAME = hello_world
9 |
10 | // The application's bundle identifier
11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.helloWorld
12 |
13 | // The copyright displayed in application information
14 | PRODUCT_COPYRIGHT = Copyright © 2022 com.example. All rights reserved.
15 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Debug.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Release.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Warnings.xcconfig:
--------------------------------------------------------------------------------
1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings
2 | GCC_WARN_UNDECLARED_SELECTOR = YES
3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES
4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE
5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
6 | CLANG_WARN_PRAGMA_PACK = YES
7 | CLANG_WARN_STRICT_PROTOTYPES = YES
8 | CLANG_WARN_COMMA = YES
9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES
10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
12 | GCC_WARN_SHADOW = YES
13 | CLANG_WARN_UNREACHABLE_CODE = YES
14 |
--------------------------------------------------------------------------------
/macos/Runner/DebugProfile.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.cs.allow-jit
8 |
9 | com.apple.security.network.server
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/macos/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | $(PRODUCT_COPYRIGHT)
27 | NSMainNibFile
28 | MainMenu
29 | NSPrincipalClass
30 | NSApplication
31 |
32 |
33 |
--------------------------------------------------------------------------------
/macos/Runner/MainFlutterWindow.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | class MainFlutterWindow: NSWindow {
5 | override func awakeFromNib() {
6 | let flutterViewController = FlutterViewController.init()
7 | let windowFrame = self.frame
8 | self.contentViewController = flutterViewController
9 | self.setFrame(windowFrame, display: true)
10 |
11 | RegisterGeneratedPlugins(registry: flutterViewController)
12 |
13 | super.awakeFromNib()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/macos/Runner/Release.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: hello_world
2 | description: A new Flutter project.
3 |
4 | # The following line prevents the package from being accidentally published to
5 | # pub.dev using `flutter pub publish`. This is preferred for private packages.
6 | publish_to: "none" # Remove this line if you wish to publish to pub.dev
7 |
8 | # The following defines the version and build number for your application.
9 | # A version number is three numbers separated by dots, like 1.2.43
10 | # followed by an optional build number separated by a +.
11 | # Both the version and the builder number may be overridden in flutter
12 | # build by specifying --build-name and --build-number, respectively.
13 | # In Android, build-name is used as versionName while build-number used as versionCode.
14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
16 | # Read more about iOS versioning at
17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 | # In Windows, build-name is used as the major, minor, and patch parts
19 | # of the product and file versions while build-number is used as the build suffix.
20 | version: 1.0.0+1
21 |
22 | environment:
23 | sdk: ">=3.0.0 <4.0.0"
24 |
25 | # Dependencies specify other packages that your package needs in order to work.
26 | # To automatically upgrade your package dependencies to the latest versions
27 | # consider running `flutter pub upgrade --major-versions`. Alternatively,
28 | # dependencies can be manually updated by changing the version numbers below to
29 | # the latest version available on pub.dev. To see which dependencies have newer
30 | # versions available, run `flutter pub outdated`.
31 | dependencies:
32 | flutter:
33 | sdk: flutter
34 | auto_size_text: ^3.0.0
35 | # The following adds the Cupertino Icons font to your application.
36 | # Use with the CupertinoIcons class for iOS style icons.
37 | cupertino_icons: ^1.0.2
38 |
39 | dev_dependencies:
40 | flutter_test:
41 | sdk: flutter
42 | # The "flutter_lints" package below contains a set of recommended lints to
43 | # encourage good coding practices. The lint set provided by the package is
44 | # activated in the `analysis_options.yaml` file located at the root of your
45 | # package. See that file for information about deactivating specific lint
46 | # rules and activating additional ones.
47 | flutter_lints: ^2.0.0
48 |
49 | # For information on the generic Dart part of this file, see the
50 | # following page: https://dart.dev/tools/pub/pubspec
51 |
52 | # The following section is specific to Flutter packages.
53 | flutter:
54 | # The following line ensures that the Material Icons font is
55 | # included with your application, so that you can use the icons in
56 | # the material Icons class.
57 | uses-material-design: true
58 |
59 | # To add assets to your application, add an assets section, like this:
60 | # assets:
61 | # - images/a_dot_burr.jpeg
62 | # - images/a_dot_ham.jpeg
63 |
64 | # An image asset can refer to one or more resolution-specific "variants", see
65 | # https://flutter.dev/assets-and-images/#resolution-aware
66 |
67 | # For details regarding adding assets from package dependencies, see
68 | # https://flutter.dev/assets-and-images/#from-packages
69 |
70 | # To add custom fonts to your application, add a fonts section here,
71 | # in this "flutter" section. Each entry in this list should have a
72 | # "family" key with the font family name, and a "fonts" key with a
73 | # list giving the asset and other descriptors for the font. For
74 | # example:
75 | # fonts:
76 | # - family: Schyler
77 | # fonts:
78 | # - asset: fonts/Schyler-Regular.ttf
79 | # - asset: fonts/Schyler-Italic.ttf
80 | # style: italic
81 | # - family: Trajan Pro
82 | # fonts:
83 | # - asset: fonts/TrajanPro.ttf
84 | # - asset: fonts/TrajanPro_Bold.ttf
85 | # weight: 700
86 | #
87 | # For details regarding fonts from package dependencies,
88 | # see https://flutter.dev/custom-fonts/#from-packages
89 |
--------------------------------------------------------------------------------
/test/calculator_fail_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_test/flutter_test.dart';
2 | import '../lib/Chapter12/calculator_fail.dart';
3 |
4 | void main() {
5 | late Calculator _calculator;
6 | setUp(() {
7 | _calculator = Calculator();
8 | });
9 | test(
10 | 'calculator.sumTwoNumbers() sum both numbers',
11 | () => expect(_calculator.sumTwoNumbers(1, 2), 3),
12 | );
13 | }
14 |
--------------------------------------------------------------------------------
/test/calculator_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_test/flutter_test.dart';
2 | import '../lib/Chapter12/calculator.dart';
3 |
4 | void main() {
5 | late Calculator _calculator;
6 | setUp(() {
7 | _calculator = Calculator();
8 | });
9 | test(
10 | 'calculator.sumTwoNumbers() sum both numbers',
11 | () => expect(_calculator.sumTwoNumbers(1, 2), 3),
12 | );
13 |
14 | group("calculator tests", () {
15 | test(
16 | 'sumTwoNumbers() sum both numbers',
17 | () => expect(_calculator.sumTwoNumbers(1, 2), 3),
18 | );
19 | test(
20 | 'sumTwoNumbers() sum negative number',
21 | () => expect(_calculator.sumTwoNumbers(1, -1), 1),
22 | );
23 | });
24 | }
25 |
--------------------------------------------------------------------------------
/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility in the flutter_test package. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:flutter/material.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | import 'package:hello_world/Chapter01/main.dart';
12 |
13 | void main() {
14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 | // Build our app and trigger a frame.
16 | await tester.pumpWidget(const MyApp());
17 |
18 | // Verify that our counter starts at 0.
19 | expect(find.text('0'), findsOneWidget);
20 | expect(find.text('1'), findsNothing);
21 |
22 | // Tap the '+' icon and trigger a frame.
23 | await tester.tap(find.byIcon(Icons.add));
24 | await tester.pump();
25 |
26 | // Verify that our counter has incremented.
27 | expect(find.text('0'), findsNothing);
28 | expect(find.text('1'), findsOneWidget);
29 | });
30 | }
31 |
--------------------------------------------------------------------------------
/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/web/favicon.png
--------------------------------------------------------------------------------
/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/web/icons/Icon-maskable-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/web/icons/Icon-maskable-192.png
--------------------------------------------------------------------------------
/web/icons/Icon-maskable-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/web/icons/Icon-maskable-512.png
--------------------------------------------------------------------------------
/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | hello_world
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hello_world",
3 | "short_name": "hello_world",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "A new Flutter project.",
9 | "orientation": "portrait-primary",
10 | "prefer_related_applications": false,
11 | "icons": [
12 | {
13 | "src": "icons/Icon-192.png",
14 | "sizes": "192x192",
15 | "type": "image/png"
16 | },
17 | {
18 | "src": "icons/Icon-512.png",
19 | "sizes": "512x512",
20 | "type": "image/png"
21 | },
22 | {
23 | "src": "icons/Icon-maskable-192.png",
24 | "sizes": "192x192",
25 | "type": "image/png",
26 | "purpose": "maskable"
27 | },
28 | {
29 | "src": "icons/Icon-maskable-512.png",
30 | "sizes": "512x512",
31 | "type": "image/png",
32 | "purpose": "maskable"
33 | }
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.14)
3 | project(hello_world LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "hello_world")
8 |
9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10 | # versions of CMake.
11 | cmake_policy(SET CMP0063 NEW)
12 |
13 | # Define build configuration option.
14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
15 | if(IS_MULTICONFIG)
16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
17 | CACHE STRING "" FORCE)
18 | else()
19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
20 | set(CMAKE_BUILD_TYPE "Debug" CACHE
21 | STRING "Flutter build mode" FORCE)
22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
23 | "Debug" "Profile" "Release")
24 | endif()
25 | endif()
26 | # Define settings for the Profile build mode.
27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
31 |
32 | # Use Unicode for all projects.
33 | add_definitions(-DUNICODE -D_UNICODE)
34 |
35 | # Compilation settings that should be applied to most targets.
36 | #
37 | # Be cautious about adding new options here, as plugins use this function by
38 | # default. In most cases, you should add new options to specific targets instead
39 | # of modifying this function.
40 | function(APPLY_STANDARD_SETTINGS TARGET)
41 | target_compile_features(${TARGET} PUBLIC cxx_std_17)
42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
43 | target_compile_options(${TARGET} PRIVATE /EHsc)
44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>")
46 | endfunction()
47 |
48 | # Flutter library and tool build rules.
49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
50 | add_subdirectory(${FLUTTER_MANAGED_DIR})
51 |
52 | # Application build; see runner/CMakeLists.txt.
53 | add_subdirectory("runner")
54 |
55 | # Generated plugin build rules, which manage building the plugins and adding
56 | # them to the application.
57 | include(flutter/generated_plugins.cmake)
58 |
59 |
60 | # === Installation ===
61 | # Support files are copied into place next to the executable, so that it can
62 | # run in place. This is done instead of making a separate bundle (as on Linux)
63 | # so that building and running from within Visual Studio will work.
64 | set(BUILD_BUNDLE_DIR "$")
65 | # Make the "install" step default, as it's required to run.
66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
69 | endif()
70 |
71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
73 |
74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
75 | COMPONENT Runtime)
76 |
77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
78 | COMPONENT Runtime)
79 |
80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
81 | COMPONENT Runtime)
82 |
83 | if(PLUGIN_BUNDLED_LIBRARIES)
84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
86 | COMPONENT Runtime)
87 | endif()
88 |
89 | # Fully re-copy the assets directory on each build to avoid having stale files
90 | # from a previous install.
91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
92 | install(CODE "
93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
94 | " COMPONENT Runtime)
95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
97 |
98 | # Install the AOT library on non-Debug builds only.
99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
100 | CONFIGURATIONS Profile;Release
101 | COMPONENT Runtime)
102 |
--------------------------------------------------------------------------------
/windows/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.14)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
12 |
13 | # === Flutter Library ===
14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
15 |
16 | # Published to parent scope for install step.
17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
21 |
22 | list(APPEND FLUTTER_LIBRARY_HEADERS
23 | "flutter_export.h"
24 | "flutter_windows.h"
25 | "flutter_messenger.h"
26 | "flutter_plugin_registrar.h"
27 | "flutter_texture_registrar.h"
28 | )
29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
30 | add_library(flutter INTERFACE)
31 | target_include_directories(flutter INTERFACE
32 | "${EPHEMERAL_DIR}"
33 | )
34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
35 | add_dependencies(flutter flutter_assemble)
36 |
37 | # === Wrapper ===
38 | list(APPEND CPP_WRAPPER_SOURCES_CORE
39 | "core_implementations.cc"
40 | "standard_codec.cc"
41 | )
42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
44 | "plugin_registrar.cc"
45 | )
46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
47 | list(APPEND CPP_WRAPPER_SOURCES_APP
48 | "flutter_engine.cc"
49 | "flutter_view_controller.cc"
50 | )
51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
52 |
53 | # Wrapper sources needed for a plugin.
54 | add_library(flutter_wrapper_plugin STATIC
55 | ${CPP_WRAPPER_SOURCES_CORE}
56 | ${CPP_WRAPPER_SOURCES_PLUGIN}
57 | )
58 | apply_standard_settings(flutter_wrapper_plugin)
59 | set_target_properties(flutter_wrapper_plugin PROPERTIES
60 | POSITION_INDEPENDENT_CODE ON)
61 | set_target_properties(flutter_wrapper_plugin PROPERTIES
62 | CXX_VISIBILITY_PRESET hidden)
63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
64 | target_include_directories(flutter_wrapper_plugin PUBLIC
65 | "${WRAPPER_ROOT}/include"
66 | )
67 | add_dependencies(flutter_wrapper_plugin flutter_assemble)
68 |
69 | # Wrapper sources needed for the runner.
70 | add_library(flutter_wrapper_app STATIC
71 | ${CPP_WRAPPER_SOURCES_CORE}
72 | ${CPP_WRAPPER_SOURCES_APP}
73 | )
74 | apply_standard_settings(flutter_wrapper_app)
75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter)
76 | target_include_directories(flutter_wrapper_app PUBLIC
77 | "${WRAPPER_ROOT}/include"
78 | )
79 | add_dependencies(flutter_wrapper_app flutter_assemble)
80 |
81 | # === Flutter tool backend ===
82 | # _phony_ is a non-existent file to force this command to run every time,
83 | # since currently there's no way to get a full input/output list from the
84 | # flutter tool.
85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
87 | add_custom_command(
88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
90 | ${CPP_WRAPPER_SOURCES_APP}
91 | ${PHONY_OUTPUT}
92 | COMMAND ${CMAKE_COMMAND} -E env
93 | ${FLUTTER_TOOL_ENVIRONMENT}
94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
95 | windows-x64 $
96 | VERBATIM
97 | )
98 | add_custom_target(flutter_assemble DEPENDS
99 | "${FLUTTER_LIBRARY}"
100 | ${FLUTTER_LIBRARY_HEADERS}
101 | ${CPP_WRAPPER_SOURCES_CORE}
102 | ${CPP_WRAPPER_SOURCES_PLUGIN}
103 | ${CPP_WRAPPER_SOURCES_APP}
104 | )
105 |
--------------------------------------------------------------------------------
/windows/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 |
10 | void RegisterPlugins(flutter::PluginRegistry* registry) {
11 | }
12 |
--------------------------------------------------------------------------------
/windows/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void RegisterPlugins(flutter::PluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
9 | )
10 |
11 | set(PLUGIN_BUNDLED_LIBRARIES)
12 |
13 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
18 | endforeach(plugin)
19 |
20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23 | endforeach(ffi_plugin)
24 |
--------------------------------------------------------------------------------
/windows/runner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 | project(runner LANGUAGES CXX)
3 |
4 | # Define the application target. To change its name, change BINARY_NAME in the
5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6 | # work.
7 | #
8 | # Any new source files that you add to the application should be added here.
9 | add_executable(${BINARY_NAME} WIN32
10 | "flutter_window.cpp"
11 | "main.cpp"
12 | "utils.cpp"
13 | "win32_window.cpp"
14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
15 | "Runner.rc"
16 | "runner.exe.manifest"
17 | )
18 |
19 | # Apply the standard set of build settings. This can be removed for applications
20 | # that need different build settings.
21 | apply_standard_settings(${BINARY_NAME})
22 |
23 | # Add preprocessor definitions for the build version.
24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
29 |
30 | # Disable Windows macros that collide with C++ standard library functions.
31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
32 |
33 | # Add dependency libraries and include directories. Add any application-specific
34 | # dependencies here.
35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
36 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
37 |
38 | # Run the Flutter tool portions of the build. This must not be removed.
39 | add_dependencies(${BINARY_NAME} flutter_assemble)
40 |
--------------------------------------------------------------------------------
/windows/runner/Runner.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #pragma code_page(65001)
4 | #include "resource.h"
5 |
6 | #define APSTUDIO_READONLY_SYMBOLS
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // Generated from the TEXTINCLUDE 2 resource.
10 | //
11 | #include "winres.h"
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | #undef APSTUDIO_READONLY_SYMBOLS
15 |
16 | /////////////////////////////////////////////////////////////////////////////
17 | // English (United States) resources
18 |
19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Icon
51 | //
52 |
53 | // Icon with lowest ID value placed first to ensure application icon
54 | // remains consistent on all systems.
55 | IDI_APP_ICON ICON "resources\\app_icon.ico"
56 |
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | //
60 | // Version
61 | //
62 |
63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
65 | #else
66 | #define VERSION_AS_NUMBER 1,0,0,0
67 | #endif
68 |
69 | #if defined(FLUTTER_VERSION)
70 | #define VERSION_AS_STRING FLUTTER_VERSION
71 | #else
72 | #define VERSION_AS_STRING "1.0.0"
73 | #endif
74 |
75 | VS_VERSION_INFO VERSIONINFO
76 | FILEVERSION VERSION_AS_NUMBER
77 | PRODUCTVERSION VERSION_AS_NUMBER
78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79 | #ifdef _DEBUG
80 | FILEFLAGS VS_FF_DEBUG
81 | #else
82 | FILEFLAGS 0x0L
83 | #endif
84 | FILEOS VOS__WINDOWS32
85 | FILETYPE VFT_APP
86 | FILESUBTYPE 0x0L
87 | BEGIN
88 | BLOCK "StringFileInfo"
89 | BEGIN
90 | BLOCK "040904e4"
91 | BEGIN
92 | VALUE "CompanyName", "com.example" "\0"
93 | VALUE "FileDescription", "hello_world" "\0"
94 | VALUE "FileVersion", VERSION_AS_STRING "\0"
95 | VALUE "InternalName", "hello_world" "\0"
96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0"
97 | VALUE "OriginalFilename", "hello_world.exe" "\0"
98 | VALUE "ProductName", "hello_world" "\0"
99 | VALUE "ProductVersion", VERSION_AS_STRING "\0"
100 | END
101 | END
102 | BLOCK "VarFileInfo"
103 | BEGIN
104 | VALUE "Translation", 0x409, 1252
105 | END
106 | END
107 |
108 | #endif // English (United States) resources
109 | /////////////////////////////////////////////////////////////////////////////
110 |
111 |
112 |
113 | #ifndef APSTUDIO_INVOKED
114 | /////////////////////////////////////////////////////////////////////////////
115 | //
116 | // Generated from the TEXTINCLUDE 3 resource.
117 | //
118 |
119 |
120 | /////////////////////////////////////////////////////////////////////////////
121 | #endif // not APSTUDIO_INVOKED
122 |
--------------------------------------------------------------------------------
/windows/runner/flutter_window.cpp:
--------------------------------------------------------------------------------
1 | #include "flutter_window.h"
2 |
3 | #include
4 |
5 | #include "flutter/generated_plugin_registrant.h"
6 |
7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8 | : project_(project) {}
9 |
10 | FlutterWindow::~FlutterWindow() {}
11 |
12 | bool FlutterWindow::OnCreate() {
13 | if (!Win32Window::OnCreate()) {
14 | return false;
15 | }
16 |
17 | RECT frame = GetClientArea();
18 |
19 | // The size here must match the window dimensions to avoid unnecessary surface
20 | // creation / destruction in the startup path.
21 | flutter_controller_ = std::make_unique(
22 | frame.right - frame.left, frame.bottom - frame.top, project_);
23 | // Ensure that basic setup of the controller was successful.
24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25 | return false;
26 | }
27 | RegisterPlugins(flutter_controller_->engine());
28 | SetChildContent(flutter_controller_->view()->GetNativeWindow());
29 | return true;
30 | }
31 |
32 | void FlutterWindow::OnDestroy() {
33 | if (flutter_controller_) {
34 | flutter_controller_ = nullptr;
35 | }
36 |
37 | Win32Window::OnDestroy();
38 | }
39 |
40 | LRESULT
41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
42 | WPARAM const wparam,
43 | LPARAM const lparam) noexcept {
44 | // Give Flutter, including plugins, an opportunity to handle window messages.
45 | if (flutter_controller_) {
46 | std::optional result =
47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
48 | lparam);
49 | if (result) {
50 | return *result;
51 | }
52 | }
53 |
54 | switch (message) {
55 | case WM_FONTCHANGE:
56 | flutter_controller_->engine()->ReloadSystemFonts();
57 | break;
58 | }
59 |
60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
61 | }
62 |
--------------------------------------------------------------------------------
/windows/runner/flutter_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_FLUTTER_WINDOW_H_
2 | #define RUNNER_FLUTTER_WINDOW_H_
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "win32_window.h"
10 |
11 | // A window that does nothing but host a Flutter view.
12 | class FlutterWindow : public Win32Window {
13 | public:
14 | // Creates a new FlutterWindow hosting a Flutter view running |project|.
15 | explicit FlutterWindow(const flutter::DartProject& project);
16 | virtual ~FlutterWindow();
17 |
18 | protected:
19 | // Win32Window:
20 | bool OnCreate() override;
21 | void OnDestroy() override;
22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
23 | LPARAM const lparam) noexcept override;
24 |
25 | private:
26 | // The project to run.
27 | flutter::DartProject project_;
28 |
29 | // The Flutter instance hosted by this window.
30 | std::unique_ptr flutter_controller_;
31 | };
32 |
33 | #endif // RUNNER_FLUTTER_WINDOW_H_
34 |
--------------------------------------------------------------------------------
/windows/runner/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "flutter_window.h"
6 | #include "utils.h"
7 |
8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
9 | _In_ wchar_t *command_line, _In_ int show_command) {
10 | // Attach to console when present (e.g., 'flutter run') or create a
11 | // new console when running with a debugger.
12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
13 | CreateAndAttachConsole();
14 | }
15 |
16 | // Initialize COM, so that it is available for use in the library and/or
17 | // plugins.
18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
19 |
20 | flutter::DartProject project(L"data");
21 |
22 | std::vector command_line_arguments =
23 | GetCommandLineArguments();
24 |
25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
26 |
27 | FlutterWindow window(project);
28 | Win32Window::Point origin(10, 10);
29 | Win32Window::Size size(1280, 720);
30 | if (!window.CreateAndShow(L"hello_world", origin, size)) {
31 | return EXIT_FAILURE;
32 | }
33 | window.SetQuitOnClose(true);
34 |
35 | ::MSG msg;
36 | while (::GetMessage(&msg, nullptr, 0, 0)) {
37 | ::TranslateMessage(&msg);
38 | ::DispatchMessage(&msg);
39 | }
40 |
41 | ::CoUninitialize();
42 | return EXIT_SUCCESS;
43 | }
44 |
--------------------------------------------------------------------------------
/windows/runner/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by Runner.rc
4 | //
5 | #define IDI_APP_ICON 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1001
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PacktPublishing/Flutter-for-Beginners-Third-Edition/f1b71556f945a9d1f55274e3bd6d73fbff7231dc/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/windows/runner/runner.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PerMonitorV2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/windows/runner/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | void CreateAndAttachConsole() {
11 | if (::AllocConsole()) {
12 | FILE *unused;
13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
14 | _dup2(_fileno(stdout), 1);
15 | }
16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
17 | _dup2(_fileno(stdout), 2);
18 | }
19 | std::ios::sync_with_stdio();
20 | FlutterDesktopResyncOutputStreams();
21 | }
22 | }
23 |
24 | std::vector GetCommandLineArguments() {
25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
26 | int argc;
27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
28 | if (argv == nullptr) {
29 | return std::vector();
30 | }
31 |
32 | std::vector command_line_arguments;
33 |
34 | // Skip the first argument as it's the binary name.
35 | for (int i = 1; i < argc; i++) {
36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
37 | }
38 |
39 | ::LocalFree(argv);
40 |
41 | return command_line_arguments;
42 | }
43 |
44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) {
45 | if (utf16_string == nullptr) {
46 | return std::string();
47 | }
48 | int target_length = ::WideCharToMultiByte(
49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
50 | -1, nullptr, 0, nullptr, nullptr);
51 | std::string utf8_string;
52 | if (target_length == 0 || target_length > utf8_string.max_size()) {
53 | return utf8_string;
54 | }
55 | utf8_string.resize(target_length);
56 | int converted_length = ::WideCharToMultiByte(
57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
58 | -1, utf8_string.data(),
59 | target_length, nullptr, nullptr);
60 | if (converted_length == 0) {
61 | return std::string();
62 | }
63 | return utf8_string;
64 | }
65 |
--------------------------------------------------------------------------------
/windows/runner/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_UTILS_H_
2 | #define RUNNER_UTILS_H_
3 |
4 | #include
5 | #include
6 |
7 | // Creates a console for the process, and redirects stdout and stderr to
8 | // it for both the runner and the Flutter library.
9 | void CreateAndAttachConsole();
10 |
11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
12 | // encoded in UTF-8. Returns an empty std::string on failure.
13 | std::string Utf8FromUtf16(const wchar_t* utf16_string);
14 |
15 | // Gets the command line arguments passed in as a std::vector,
16 | // encoded in UTF-8. Returns an empty std::vector on failure.
17 | std::vector GetCommandLineArguments();
18 |
19 | #endif // RUNNER_UTILS_H_
20 |
--------------------------------------------------------------------------------
/windows/runner/win32_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_WIN32_WINDOW_H_
2 | #define RUNNER_WIN32_WINDOW_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be
11 | // inherited from by classes that wish to specialize with custom
12 | // rendering and input handling
13 | class Win32Window {
14 | public:
15 | struct Point {
16 | unsigned int x;
17 | unsigned int y;
18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {}
19 | };
20 |
21 | struct Size {
22 | unsigned int width;
23 | unsigned int height;
24 | Size(unsigned int width, unsigned int height)
25 | : width(width), height(height) {}
26 | };
27 |
28 | Win32Window();
29 | virtual ~Win32Window();
30 |
31 | // Creates and shows a win32 window with |title| and position and size using
32 | // |origin| and |size|. New windows are created on the default monitor. Window
33 | // sizes are specified to the OS in physical pixels, hence to ensure a
34 | // consistent size to will treat the width height passed in to this function
35 | // as logical pixels and scale to appropriate for the default monitor. Returns
36 | // true if the window was created successfully.
37 | bool CreateAndShow(const std::wstring& title,
38 | const Point& origin,
39 | const Size& size);
40 |
41 | // Release OS resources associated with window.
42 | void Destroy();
43 |
44 | // Inserts |content| into the window tree.
45 | void SetChildContent(HWND content);
46 |
47 | // Returns the backing Window handle to enable clients to set icon and other
48 | // window properties. Returns nullptr if the window has been destroyed.
49 | HWND GetHandle();
50 |
51 | // If true, closing this window will quit the application.
52 | void SetQuitOnClose(bool quit_on_close);
53 |
54 | // Return a RECT representing the bounds of the current client area.
55 | RECT GetClientArea();
56 |
57 | protected:
58 | // Processes and route salient window messages for mouse handling,
59 | // size change and DPI. Delegates handling of these to member overloads that
60 | // inheriting classes can handle.
61 | virtual LRESULT MessageHandler(HWND window,
62 | UINT const message,
63 | WPARAM const wparam,
64 | LPARAM const lparam) noexcept;
65 |
66 | // Called when CreateAndShow is called, allowing subclass window-related
67 | // setup. Subclasses should return false if setup fails.
68 | virtual bool OnCreate();
69 |
70 | // Called when Destroy is called.
71 | virtual void OnDestroy();
72 |
73 | private:
74 | friend class WindowClassRegistrar;
75 |
76 | // OS callback called by message pump. Handles the WM_NCCREATE message which
77 | // is passed when the non-client area is being created and enables automatic
78 | // non-client DPI scaling so that the non-client area automatically
79 | // responsponds to changes in DPI. All other messages are handled by
80 | // MessageHandler.
81 | static LRESULT CALLBACK WndProc(HWND const window,
82 | UINT const message,
83 | WPARAM const wparam,
84 | LPARAM const lparam) noexcept;
85 |
86 | // Retrieves a class instance pointer for |window|
87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept;
88 |
89 | bool quit_on_close_ = false;
90 |
91 | // window handle for top level window.
92 | HWND window_handle_ = nullptr;
93 |
94 | // window handle for hosted content.
95 | HWND child_content_ = nullptr;
96 | };
97 |
98 | #endif // RUNNER_WIN32_WINDOW_H_
99 |
--------------------------------------------------------------------------------